Documentation
¶
Overview ¶
Package dpop implements the DPoP protocol primitives used by OAuth token requests and Lark OpenAPI requests.
Index ¶
- Constants
- Variables
- func IsClockRecoverySignal(code int, oauthError string) bool
- func IsEnterpriseProvider(name string) bool
- func PrepareTokenRequest(req *http.Request, key *Key, operation TokenOperation, body AssertionBody) (*http.Request, error)
- func SynchronizeClock(ctx context.Context, httpClient *http.Client, brand core.LarkBrand, key *Key) error
- func WithBinding(ctx context.Context, binding *Binding) context.Context
- func WithTokenEndpointKey(ctx context.Context, key *Key) context.Context
- type AdjustableClock
- type AssertionBody
- type Binding
- type Clock
- type ClockState
- type DPoPProofProvider
- type Key
- func (k *Key) AuthHelperEndpoint() string
- func (k *Key) Clock() *AdjustableClock
- func (k *Key) Delete(ctx context.Context) error
- func (k *Key) ID() string
- func (k *Key) MatchesKeyID(id string) bool
- func (k *Key) ProbeWritable(ctx context.Context) error
- func (k *Key) ProofProviderName() string
- func (k *Key) Provider() string
- func (k *Key) PublicJWK() (keysigner.PublicJWK, error)
- func (k *Key) Save(ctx context.Context) error
- func (k *Key) SecurityLevel() keysigner.SecurityLevel
- func (k *Key) Thumbprint() (string, error)
- func (k *Key) UsesAuthHelper(endpoint string, identity authhelper.Identity) bool
- type KeyStore
- func (s *KeyStore) Delete(ctx context.Context, id string) error
- func (s *KeyStore) Ensure(ctx context.Context, id string) (*Key, error)
- func (s *KeyStore) Load(ctx context.Context, id string) (*Key, error)
- func (s *KeyStore) ProbeAndRecoverForReauthorization(ctx context.Context) (bool, error)
- func (s *KeyStore) ProbeWritable(ctx context.Context) error
- type TokenOperation
- type Transport
Constants ¶
const ( ProofHeader = "DPoP" Scheme = "DPoP" TokenType = "DPoP" ClockSkewErrorCode = 20153 InvalidProofOAuthError = "invalid_dpop_proof" )
const ( LocalKeyProviderName = "local-key" DeviceCertProviderName = "device-cert" AuthHelperProviderName = "auth-helper" )
const ( // exchange because it makes no claim about whether a request was sent. KeyStoreUnavailableHint = "" /* 253-byte string literal not displayed */ // only when key storage fails before the Token Endpoint request. KeyStorePreExchangeUnavailableHint = "no OAuth token request was sent; " + KeyStoreUnavailableHint // loaded or used to sign the protected resource request. KeyAccessUnavailableHint = "" /* 284-byte string literal not displayed */ )
const HeartbeatPath = "/accounts/status/heartbeat"
Variables ¶
var ErrBindingMismatch = errors.New("DPoP key binding does not match stored token metadata")
var ErrInvalidProofResponse = errors.New("token endpoint returned " + InvalidProofOAuthError)
ErrInvalidProofResponse is a safe cause for typed errors derived from an InvalidProofOAuthError Token Endpoint response. It intentionally excludes the response description, token, proof, and key material.
var ErrKeyNotFound = errors.New("DPoP key not found")
ErrProofUnavailable marks a failure before the token request was sent.
var ErrRepeatedInvalidProof = errors.New("token endpoint rejected three consecutive DPoP proofs")
ErrRepeatedInvalidProof marks three consecutive explicit proof rejections during new token issuance. Callers own the preferred-mode fallback and key rollback.
var ErrUnknownProofProvider = errors.New("unknown DPoP proof provider")
Functions ¶
func IsClockRecoverySignal ¶
IsClockRecoverySignal reports whether a Token Endpoint response carries the complete server signal that permits a one-time DPoP clock correction. The OAuth error comparison is deliberately exact.
func IsEnterpriseProvider ¶
func PrepareTokenRequest ¶
func PrepareTokenRequest(req *http.Request, key *Key, operation TokenOperation, body AssertionBody) (*http.Request, error)
PrepareTokenRequest signs even when the HTTP client has no DPoP transport. A DPoP transport re-signs each network attempt using the same provider.
func SynchronizeClock ¶
func SynchronizeClock(ctx context.Context, httpClient *http.Client, brand core.LarkBrand, key *Key) error
SynchronizeClock obtains the Accounts server time before a DPoP token request. The calibrated clock is kept on the key; callers decide when the corresponding key metadata becomes part of their token transaction.
Types ¶
type AdjustableClock ¶
type AdjustableClock struct {
// contains filtered or unexported fields
}
AdjustableClock is safe for concurrent proof generation and clock recovery.
func NewClock ¶
func NewClock(base Clock) *AdjustableClock
func NewClockWithState ¶
func NewClockWithState(base Clock, state ClockState) *AdjustableClock
func (*AdjustableClock) Now ¶
func (c *AdjustableClock) Now() time.Time
func (*AdjustableClock) RestoreState ¶
func (c *AdjustableClock) RestoreState(state ClockState)
RestoreState replaces the persisted calibration without reading the system clock. Token records can use this to remain the atomic source of truth for a UAT and its proof clock.
func (*AdjustableClock) SetServerTime ¶
func (c *AdjustableClock) SetServerTime(serverTime, localReceiveTime time.Time)
SetServerTime records serverTime-localReceiveTime as the shared DPoP clock offset used by proofs and DPoP-bound token lifetime calculations.
func (*AdjustableClock) State ¶
func (c *AdjustableClock) State() ClockState
type AssertionBody ¶
AssertionBody encodes a grant with the ASI returned alongside its DPoP proof.
type Binding ¶
type Binding struct {
Token string
KeyID string
JKT string
KeyStoreSecureLevel keysigner.SecurityLevel
// RecoverToken replaces an unavailable Helper grant and returns the context for its request.
RecoverToken func(ctx context.Context, cause error) (token string, binding *Binding, requestCtx context.Context, err error) `json:"-"`
// contains filtered or unexported fields
}
Binding associates a token with its proof provider.
func BindingFromContext ¶
func RestoreBinding ¶
type ClockState ¶
ClockState is the non-secret persistent state needed to restore a calibrated clock with its platform key.
type DPoPProofProvider ¶
type DPoPProofProvider interface {
GenerateDPoPKey(ctx context.Context, reusableID string) (*Key, bool, error)
RestoreDPoPKey(ctx context.Context, id string) (*Key, error)
DeleteDPoPKey(ctx context.Context, id string) error
Name() string
}
DPoPProofProvider manages signing keys for one proof scheme. GenerateDPoPKey reports whether the caller must delete a new key if issuance fails.
func NewAuthHelperProvider ¶
func NewAuthHelperProvider(client authhelper.IPCClient, identity authhelper.Identity) DPoPProofProvider
func NewDeviceCertProvider ¶
func NewDeviceCertProvider(selector keysigner.DeviceCertSelector) DPoPProofProvider
NewDeviceCertProvider selects system identities using the Terminal policy.
func NewLocalKeyProvider ¶
func NewLocalKeyProvider(store *KeyStore) DPoPProofProvider
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key carries the signing capability and clock for DPoP requests.
func (*Key) AuthHelperEndpoint ¶
AuthHelperEndpoint returns the endpoint selected for this key.
func (*Key) Clock ¶
func (k *Key) Clock() *AdjustableClock
func (*Key) MatchesKeyID ¶
Device certificate signing uses Terminal policy instead of a stored key handle.
func (*Key) ProbeWritable ¶
ProbeWritable checks the signing identity used by this key before token refresh.
func (*Key) ProofProviderName ¶
ProofProviderName identifies the binding scheme independently of its native backend.
func (*Key) SecurityLevel ¶
func (k *Key) SecurityLevel() keysigner.SecurityLevel
func (*Key) Thumbprint ¶
Thumbprint computes the RFC 7638 SHA-256 JWK thumbprint.
func (*Key) UsesAuthHelper ¶
func (k *Key) UsesAuthHelper(endpoint string, identity authhelper.Identity) bool
UsesAuthHelper reports whether the key and assertion can share one IPC request.
type KeyStore ¶
type KeyStore struct {
// contains filtered or unexported fields
}
KeyStore coordinates ordered signing backends with the CLI secret store. Metadata records contain no private keys. L3 keeps its file unlock secret in a separate keychain entry; the signer owns its encrypted private-key files.
func NewKeyStore ¶
func NewKeyStore(kc keychain.KeychainAccess, signers ...keysigner.Signer) *KeyStore
NewKeyStore uses the supplied signers in order. With no arguments after kc, it tries platform signers first, followed by the software signer.
func (*KeyStore) ProbeAndRecoverForReauthorization ¶
ProbeAndRecoverForReauthorization probes the store before explicit reauthorization and reports whether it deleted keys whose unlock secret was lost.
type TokenOperation ¶
type TokenOperation string
const ( TokenAcquire TokenOperation = "acquire" TokenRefresh TokenOperation = "refresh" )
type Transport ¶
type Transport struct {
Base http.RoundTripper
}
Transport signs access-token requests at the final request boundary. Place it inside retry transports so each attempt receives a fresh proof. Callers own destination policy and must clear DPoP headers and context whenever they remove Authorization; this transport does not restrict request origins.
func (*Transport) BaseRoundTripper ¶
func (t *Transport) BaseRoundTripper() http.RoundTripper
func (*Transport) WithBaseRoundTripper ¶
func (t *Transport) WithBaseRoundTripper(base http.RoundTripper) http.RoundTripper