Documentation
¶
Index ¶
Constants ¶
const (
JTILength = 14
)
Variables ¶
This section is empty.
Functions ¶
func NewDPoPHTTPClient ¶ added in v0.30.0
func NewDPoPHTTPClient(baseClient *http.Client, dpopKey jwk.Key, tokenSource AccessTokenSource, tokenEndpoint string) (*http.Client, error)
NewDPoPHTTPClient creates a new HTTP client with DPoP transport wrapping. The client will automatically add DPoP proofs to all requests.
It returns an error when tokenEndpoint is non-empty but cannot be parsed: an unparseable endpoint would otherwise make token-endpoint requests silently misclassified as resource requests (adding an ath claim and Authorization header to the token exchange itself).
Types ¶
type AccessToken ¶
type AccessToken string
type AccessTokenCredential ¶ added in v0.28.0
type AccessTokenCredential struct {
Token AccessToken
Type TokenType
}
AccessTokenCredential binds an access token to its authentication scheme.
type AccessTokenCredentialSource ¶ added in v0.28.0
type AccessTokenCredentialSource interface {
AccessTokenCredential(ctx context.Context, client *http.Client) (AccessTokenCredential, error)
}
AccessTokenCredentialSource is implemented by token sources that can return an access token and its authentication scheme atomically.
Token sources without this optional interface retain the SDK's existing DPoP behavior for backwards compatibility.
type AccessTokenSource ¶
type AccessTokenSource interface {
AccessToken(ctx context.Context, client *http.Client) (AccessToken, error)
// MakeToken probably better to use `crypto.AsymDecryption` here than roll our own since this should be
// more closely linked to what happens in KAS in terms of crypto params
MakeToken(func(jwk.Key) ([]byte, error)) ([]byte, error)
}
type DPoPTransport ¶ added in v0.30.0
type DPoPTransport struct {
// Base is the underlying transport. If nil, http.DefaultTransport is used.
Base http.RoundTripper
// DPoPKey is the private key used to sign DPoP proofs.
DPoPKey jwk.Key
// TokenSource provides access tokens for resource requests.
// For resource requests (any URL other than TokenEndpoint), the transport
// sets Authorization: DPoP <token> and includes the ath claim binding the
// proof to the access token. Requests to TokenEndpoint get neither.
//
// When TokenSource also implements AccessTokenCredentialSource and reports a
// non-DPoP scheme for a resource request, the transport instead sets
// Authorization: Bearer <token> and sends no DPoP proof, matching the
// credential interceptor so a bearer token source is not forced onto DPoP.
TokenSource AccessTokenSource
// TokenEndpoint is the OAuth token endpoint URL.
// Requests to this endpoint are treated as token requests
// and do not include the ath claim.
//
// TokenEndpoint must not be mutated after the transport is first used:
// isTokenEndpointRequest caches the parsed URL (and NewDPoPHTTPClient
// pre-parses it at construction), so a later change would not take effect
// and would race with the cached read.
TokenEndpoint string
// contains filtered or unexported fields
}
DPoPTransport wraps each go standard net/http RoundTripper request with DPoP (RFC 9449) proof tokens. These proofs are for both token endpoint (IdP, etc) calls and resource (i.e. KAS or policy service, for the SDK) endpoint calls, handling server-issued nonces with automatic retry.
type TokenAddingInterceptor ¶
type TokenAddingInterceptor struct {
// contains filtered or unexported fields
}
func NewTokenAddingInterceptor
deprecated
func NewTokenAddingInterceptor(t AccessTokenSource, c *tls.Config) TokenAddingInterceptor
Deprecated: NewTokenAddingInterceptor is deprecated, use NewTokenAddingInterceptorWithClient instead. A http client can be constructed using httputil.SafeHTTPClientWithTLSConfig, but should be reused as much as possible.
func NewTokenAddingInterceptorWithClient ¶ added in v0.3.27
func NewTokenAddingInterceptorWithClient(t AccessTokenSource, c *http.Client) TokenAddingInterceptor
func (TokenAddingInterceptor) AddCredentialsConnect ¶ added in v0.4.5
func (i TokenAddingInterceptor) AddCredentialsConnect() connect.UnaryInterceptorFunc
func (TokenAddingInterceptor) GetDPoPToken ¶
func (i TokenAddingInterceptor) GetDPoPToken(path, method, accessToken string) (string, error)
type TokenType ¶ added in v0.28.0
type TokenType string
func TokenTypeFromOAuthTokenType ¶ added in v0.28.0
TokenTypeFromOAuthTokenType returns the authentication scheme required for an OAuth access token. A DPoP token type requires a DPoP proof; all other values use the Bearer scheme.