Skip to content

Commit

Permalink
client: Add a GetOIDCTokens() method
Browse files Browse the repository at this point in the history
This adds a helper method to fetch the OIDC tokens (if any) from the
OIDC client used to authenticate to an Incus server. In the vast
majority of cases, the tokens are automatically saved/restored from
the remote's configuration. However, when operating without a configuration
file, such as a standalone tool, there's no way to save the tokens for later
use. This results in an authentication prompt every time a new connection is
established rather than being able to re-use a previously acquired token.

Signed-off-by: Mathias Gibbens <mathias.gibbens@futurfusion.io>
  • Loading branch information
gibmat committed Nov 6, 2024
1 parent 8082084 commit c636e56
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions client/incus_oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ func (r *ProtocolIncus) setupOIDCClient(token *oidc.Tokens[*oidc.IDTokenClaims])
r.oidcClient.httpClient = r.http
}

// GetOIDCTokens returns the current OIDC tokens (if any) from the OIDC client.
//
// This should only be used by internal Incus tools when it's not possible to get the tokens from a Config struct.
func (r *ProtocolIncus) GetOIDCTokens() *oidc.Tokens[*oidc.IDTokenClaims] {
if r.oidcClient == nil {
return nil
}

return r.oidcClient.tokens
}

// Custom transport that modifies requests to inject the audience field.
type oidcTransport struct {
deviceAuthorizationEndpoint string
Expand Down

0 comments on commit c636e56

Please sign in to comment.