-
-
Notifications
You must be signed in to change notification settings - Fork 0
[hotfix] Auth + Deployment Action #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9706d6a
re-tag
gocanto 1ffd35f
Empty - Commit
gocanto adb8677
debug code
gocanto 8caac81
tweak caddy
gocanto 2c6e681
fix token logic
gocanto 9f3cd8f
caddy
gocanto 9f626a6
start workin on Bearer-Token
gocanto 779bf7f
update model
gocanto a87019d
token structure
gocanto 9036e89
comment old token
gocanto 1444a27
wire cli menu
gocanto 7a23ae3
add prefix
gocanto 4e2c81e
remove old token refs
gocanto 9253828
format
gocanto 3c58468
start working on token middleware logic
gocanto dab85ae
format
gocanto 76dffe6
makefile
gocanto 86516d6
remove this
gocanto f289f36
check private token hash too
gocanto 73ab9e9
format
gocanto f5e2636
remove old guard
gocanto aaa526d
fix validation
gocanto 861f178
pass signature header too
gocanto 7f3975d
apply tweaks
gocanto 01b4b66
encrypt tokens before saving them in db
gocanto 90dfc24
re-work create api account, show api account, and app key generation
gocanto 7119e08
fix
gocanto 8d0120c
http signature
gocanto 4bcb323
wire middleware
gocanto fcff219
add middleware logic
gocanto 67822cd
format
gocanto a8d7fa4
this is ok
gocanto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package accounts | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/oullin/database" | ||
| "github.com/oullin/database/repository" | ||
| "github.com/oullin/env" | ||
| "github.com/oullin/pkg/auth" | ||
| ) | ||
|
|
||
| type Handler struct { | ||
| IsDebugging bool | ||
| Env *env.Environment | ||
| Tokens *repository.ApiKeys | ||
| TokenHandler *auth.TokenHandler | ||
| } | ||
|
|
||
| func MakeHandler(db *database.Connection, env *env.Environment) (*Handler, error) { | ||
| tokenHandler, err := auth.MakeTokensHandler( | ||
| []byte(env.App.MasterKey), | ||
| ) | ||
|
|
||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to make token handler: %v", err) | ||
| } | ||
|
|
||
| return &Handler{ | ||
| Env: env, | ||
| IsDebugging: false, | ||
| Tokens: &repository.ApiKeys{DB: db}, | ||
| TokenHandler: tokenHandler, | ||
| }, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| package accounts | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/oullin/database" | ||
| "github.com/oullin/pkg/auth" | ||
| "github.com/oullin/pkg/cli" | ||
| ) | ||
|
|
||
| func (h Handler) CreateAccount(accountName string) error { | ||
| token, err := h.TokenHandler.SetupNewAccount(accountName) | ||
|
|
||
| if err != nil { | ||
| return fmt.Errorf("failed to create the given account [%s] tokens pair: %v", accountName, err) | ||
| } | ||
|
|
||
| _, err = h.Tokens.Create(database.APIKeyAttr{ | ||
| AccountName: token.AccountName, | ||
| SecretKey: token.EncryptedSecretKey, | ||
| PublicKey: token.EncryptedPublicKey, | ||
| }) | ||
|
|
||
| if err != nil { | ||
| return fmt.Errorf("failed to create account [%s]: %v", accountName, err) | ||
| } | ||
|
|
||
| cli.Successln("Account created successfully.\n") | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (h Handler) ReadAccount(accountName string) error { | ||
| item := h.Tokens.FindBy(accountName) | ||
|
|
||
| if item == nil { | ||
| return fmt.Errorf("the given account [%s] was not found", accountName) | ||
| } | ||
|
|
||
| token, err := h.TokenHandler.DecodeTokensFor( | ||
| item.AccountName, | ||
| item.SecretKey, | ||
| item.PublicKey, | ||
| ) | ||
|
|
||
| if err != nil { | ||
| return fmt.Errorf("could not decode the given account [%s] keys: %v", item.AccountName, err) | ||
| } | ||
|
|
||
| cli.Successln("\nThe given account has been found successfully!\n") | ||
| cli.Blueln(" > " + fmt.Sprintf("Account name: %s", token.AccountName)) | ||
| cli.Blueln(" > " + fmt.Sprintf("Public Key: %s", token.PublicKey)) | ||
| cli.Blueln(" > " + fmt.Sprintf("Secret Key: %s", token.SecretKey)) | ||
| cli.Blueln(" > " + fmt.Sprintf("API Signature: %s", auth.CreateSignatureFrom(token.AccountName, token.SecretKey))) | ||
| cli.Warningln("----- Encrypted Values -----") | ||
| cli.Magentaln(" > " + fmt.Sprintf("Public Key: %x", token.EncryptedPublicKey)) | ||
| cli.Magentaln(" > " + fmt.Sprintf("Secret Key: %x", token.EncryptedSecretKey)) | ||
| fmt.Println(" ") | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (h Handler) CreateSignature(accountName string) error { | ||
| item := h.Tokens.FindBy(accountName) | ||
|
|
||
| if item == nil { | ||
| return fmt.Errorf("the given account [%s] was not found", accountName) | ||
| } | ||
|
|
||
| token, err := h.TokenHandler.DecodeTokensFor( | ||
| item.AccountName, | ||
| item.SecretKey, | ||
| item.PublicKey, | ||
| ) | ||
|
|
||
| if err != nil { | ||
| return fmt.Errorf("could not decode the given account [%s] keys: %v", item.AccountName, err) | ||
| } | ||
|
|
||
| signature := auth.CreateSignatureFrom(token.AccountName, token.SecretKey) | ||
|
|
||
| cli.Successln("\nThe given account has been found successfully!\n") | ||
| cli.Blueln(" > " + fmt.Sprintf("Account name: %s", token.AccountName)) | ||
| cli.Blueln(" > " + fmt.Sprintf("Public Key: %s", auth.SafeDisplay(token.PublicKey))) | ||
| cli.Blueln(" > " + fmt.Sprintf("Secret Key: %s", auth.SafeDisplay(token.SecretKey))) | ||
| cli.Warningln("----- Encrypted Values -----") | ||
| cli.Magentaln(" > " + fmt.Sprintf("Signature: %s", signature)) | ||
| fmt.Println(" ") | ||
|
|
||
| return nil | ||
| } | ||
gocanto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.