@@ -34,9 +34,7 @@ const (
3434 ScopeOfflineAccess string = "offline_access"
3535 ScopeUserAll string = "user:all"
3636
37- // storeKeyFmt is the format of the key name that will be used to store a value
38- // typically the last element is the endpoint the value is for ie. src:oauth:https://sourcegraph.sourcegraph.com
39- storeKeyFmt string = "src:oauth:%s"
37+ oauthKey string = "src:oauth"
4038)
4139
4240var defaultScopes = []string {ScopeEmail , ScopeOfflineAccess , ScopeOpenID , ScopeProfile , ScopeUserAll }
@@ -394,12 +392,12 @@ func (t *Token) ExpiringIn(d time.Duration) bool {
394392 return future .After (t .ExpiresAt )
395393}
396394
397- func oauthKey (endpoint string ) string {
398- return fmt .Sprintf (storeKeyFmt , endpoint )
399- }
400-
401395func StoreToken (ctx context.Context , token * Token ) error {
402- store , err := secrets .Open (ctx )
396+ if token .Endpoint == "" {
397+ return errors .New ("token endpoint cannot be empty when storing the token" )
398+ }
399+
400+ store , err := secrets .Open (ctx , token .Endpoint )
403401 if err != nil {
404402 return err
405403 }
@@ -408,21 +406,16 @@ func StoreToken(ctx context.Context, token *Token) error {
408406 return errors .Wrap (err , "failed to marshal token" )
409407 }
410408
411- if token .Endpoint == "" {
412- return errors .New ("token endpoint cannot be empty when storing the token" )
413- }
414-
415- return store .Put (oauthKey (token .Endpoint ), data )
409+ return store .Put (oauthKey , data )
416410}
417411
418412func LoadToken (ctx context.Context , endpoint string ) (* Token , error ) {
419- store , err := secrets .Open (ctx )
413+ store , err := secrets .Open (ctx , endpoint )
420414 if err != nil {
421415 return nil , err
422416 }
423417
424- key := oauthKey (endpoint )
425- data , err := store .Get (key )
418+ data , err := store .Get (oauthKey )
426419 if err != nil {
427420 return nil , err
428421 }
0 commit comments