Documentation
¶
Overview ¶
Package tokenexchange exchanges a GitLab session token for a short-lived token scoped to one GitLab service through the POST /api/v4/token_exchange endpoint.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Result ¶
type Result struct {
// Token is the raw, encoded access token returned by the server. Nothing
// here verifies its signature; it is trustworthy because of the TLS
// connection to the issuing host. Treat it as a bearer credential for the
// requested audience and hand it to nothing else.
Token string `json:"token"`
// ExpiresAt is the token's expiry, taken from its exp claim.
ExpiresAt time.Time `json:"expires_at"`
// Issuer is the token's iss claim.
Issuer string `json:"issuer"`
// Subject is the token's sub claim.
Subject string `json:"subject"`
// Audience is the token's aud claim: what it is scoped to. Printing this
// is what distinguishes a service-scoped token from just "a token GitLab
// issued".
Audience string `json:"audience"`
}
Result is the decoded result of a successful token exchange. The claim-derived fields are populated here so callers never have to decode the token a second time.
func Exchange ¶
func Exchange(ctx context.Context, gl *gitlab.Client, audience string, expiresIn time.Duration) (*Result, error)
Exchange exchanges the caller's GitLab credential for a short-lived token for audience, valid for expiresIn. A zero expiresIn omits expires_in from the request so the server applies its own default lifetime. Bounds on expiresIn are the caller's to enforce; the server's 400 is the authoritative answer.
func (Result) MarshalJSON ¶
MarshalJSON redacts Token so json.Marshal(Result) never leaks the bearer token, protecting callers that marshal the whole struct instead of a printer-local subset of its fields.