Skip to content

Commit

Permalink
Remove refresh token as well on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
cyx committed Mar 6, 2021
1 parent 2ad756e commit d46f61d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type SecretStore interface {
Set(namespace, key, value string) error
// Get gets the secret
Get(namespace, key string) (string, error)
// Delete removes the secret
Delete(namespace, key string) error
}

type Authenticator struct {
Expand Down
5 changes: 5 additions & 0 deletions internal/auth/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ func (k *Keyring) Set(namespace, key, value string) error {
func (k *Keyring) Get(namespace, key string) (string, error) {
return keyring.Get(namespace, key)
}

// Delete deletes a value for the given namespace and key.
func (k *Keyring) Delete(namespace, key string) error {
return keyring.Delete(namespace, key)
}
5 changes: 5 additions & 0 deletions internal/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ type TokenRetriever struct {
Client *http.Client
}

// Delete deletes the given tenant from the secrets storage.
func (t *TokenRetriever) Delete(tenant string) error {
return t.Secrets.Delete(secretsNamespace, tenant)
}

// Refresh gets a new access token from the provided refresh token,
// The request is used the default client_id and endpoint for device authentication.
func (t *TokenRetriever) Refresh(ctx context.Context, tenant string) (TokenResponse, error) {
Expand Down
7 changes: 6 additions & 1 deletion internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,12 @@ func (c *cli) removeTenant(ten string) error {
}

if err := c.persistConfig(); err != nil {
return fmt.Errorf("persisting config: %w", err)
return fmt.Errorf("Unexpected error persisting config: %w", err)
}

tr := &auth.TokenRetriever{Secrets: &auth.Keyring{}}
if err := tr.Delete(ten); err != nil {
return fmt.Errorf("Unexpected error clearing tenant information: %w", err)
}

return nil
Expand Down

0 comments on commit d46f61d

Please sign in to comment.