Avnology ID
SDKsGo SDKOAuth 2.1

Token Exchange

Delegation and impersonation with RFC 8693 token exchange in the Go SDK.

Token Exchange

Exchange tokens for delegation (acting on behalf of a user) with full audit trail.

ExchangeToken()

func (o *OAuthService) ExchangeToken(ctx context.Context, params *TokenExchangeParams) (*TokenSet, error)

Parameters

FieldTypeRequiredDescription
SubjectTokenstringyesToken of the user to act as
SubjectTokenTypestringyes"access_token" or "id_token"
ActorTokenstringnoToken of the actor
ActorTokenTypestringno"access_token"
Scopes[]stringnoRequested scopes

Basic usage

delegatedTokens, err := client.OAuth.ExchangeToken(ctx, &avnologyid.TokenExchangeParams{
    SubjectToken:     userAccessToken,
    SubjectTokenType: "access_token",
    ActorToken:       adminAccessToken,
    ActorTokenType:   "access_token",
    Scopes:           []string{"openid", "profile"},
})
if err != nil {
    var insufficientScope *errors.InsufficientScopeError
    if errors.As(err, &insufficientScope) {
        log.Println("Client missing token_exchange scope")
        return
    }
    log.Fatal(err)
}

// The token's `act` claim records who is acting
fmt.Println("Acting as user:", delegatedTokens.AccessToken)

See also

On this page