-
Notifications
You must be signed in to change notification settings - Fork 70
feat(oauth): Use keyring to store oauth token #1228
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
Draft
burmudar
wants to merge
7
commits into
wb/add-oauth-refresh-token
Choose a base branch
from
wb/oauth-keyring
base: wb/add-oauth-refresh-token
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
363e925
use keyring to store oauth token
burmudar 1437459
add internal/keyring package to use 99designs keyring
burmudar 4c65c11
return Token struct
burmudar 4c95c34
store token in keyring
burmudar 8d58ac1
create token struct from TokenResponse
burmudar 61e0172
add basic http transport for oauth
burmudar 278fc77
OAuth transport and use when available in api client
burmudar 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Package keyring provides secure credential storage using the system keychain. | ||
| package keyring | ||
|
|
||
| import ( | ||
| "github.com/99designs/keyring" | ||
| "github.com/sourcegraph/sourcegraph/lib/errors" | ||
| ) | ||
|
|
||
| const serviceName = "sourcegraph-cli" | ||
|
|
||
| // Store provides secure credential storage operations. | ||
| type Store struct { | ||
| ring keyring.Keyring | ||
| } | ||
|
|
||
| // Open opens the system keyring for the Sourcegraph CLI. | ||
| func Open() (*Store, error) { | ||
| ring, err := keyring.Open(keyring.Config{ | ||
| ServiceName: serviceName, | ||
| KeychainName: "login", // This is the default name for the keychain where MacOS puts all login passwords | ||
| KeychainTrustApplication: true, // the keychain can trust src-cli! | ||
| }) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "opening keyring") | ||
| } | ||
| return &Store{ring: ring}, nil | ||
| } | ||
|
|
||
| // Set stores a key-value pair in the keyring. | ||
| func (s *Store) Set(key string, data []byte) error { | ||
| err := s.ring.Set(keyring.Item{ | ||
| Key: key, | ||
| Data: data, | ||
| Label: key, | ||
| }) | ||
| if err != nil { | ||
| return errors.Wrap(err, "storing item in keyring") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // Get retrieves a value by key from the keyring. | ||
| // Returns nil, nil if the key is not found. | ||
| func (s *Store) Get(key string) ([]byte, error) { | ||
| item, err := s.ring.Get(key) | ||
| if err != nil { | ||
| if err == keyring.ErrKeyNotFound { | ||
| return nil, nil | ||
| } | ||
| return nil, errors.Wrap(err, "getting item from keyring") | ||
| } | ||
| return item.Data, nil | ||
| } | ||
|
|
||
| // Delete removes a key from the keyring. | ||
| func (s *Store) Delete(key string) error { | ||
| err := s.ring.Remove(key) | ||
| if err != nil && err != keyring.ErrKeyNotFound { | ||
| return errors.Wrap(err, "removing item from keyring") | ||
| } | ||
| return nil | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you only open this if doing deviceflow. If we are not doing deviceflow don't open secret storage. IE avoid interacting with secret storage unless we actually need to.
Maybe you can add a wrapper around secretstore which lazily opens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stop looking over my shoulder :P busy addressing this atm 😄