Skip to content

Commit

Permalink
Pass config token as param
Browse files Browse the repository at this point in the history
  • Loading branch information
stijndcl committed Aug 4, 2023
1 parent a33e5ae commit b9a30c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import (
)

// RotateTokens exchanges a refresh token for a new app configuration token
func (api *Client) RotateTokens(refreshToken string) (*TokenResponse, error) {
return api.RotateTokensContext(context.Background(), refreshToken)
func (api *Client) RotateTokens(configToken string, refreshToken string) (*TokenResponse, error) {
return api.RotateTokensContext(context.Background(), configToken, refreshToken)
}

// RotateTokensContext exchanges a refresh token for a new app configuration token with a custom context
func (api *Client) RotateTokensContext(ctx context.Context, refreshToken string) (*TokenResponse, error) {
func (api *Client) RotateTokensContext(ctx context.Context, configToken string, refreshToken string) (*TokenResponse, error) {
if configToken == "" {
configToken = api.configToken
}

if refreshToken == "" {
refreshToken = api.configRefreshToken
}
Expand All @@ -21,7 +25,7 @@ func (api *Client) RotateTokensContext(ctx context.Context, refreshToken string)
}

response := &TokenResponse{}
err := api.getMethod(ctx, "tooling.tokens.rotate", api.configToken, values, response)
err := api.getMethod(ctx, "tooling.tokens.rotate", configToken, values, response)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestRotateTokens(t *testing.T) {
once.Do(startServer)
api := New("testing-token", OptionAPIURL("http://"+serverAddr+"/"))

tok, err := api.RotateTokens("old-refresh")
tok, err := api.RotateTokens("expired-config", "old-refresh")
if err != nil {
t.Errorf("Unexpected error: %v", err)
return
Expand Down

0 comments on commit b9a30c0

Please sign in to comment.