tokenexchange

package
v1.130.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 11 Imported by: 0

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

func (r Result) MarshalJSON() ([]byte, error)

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.

func (Result) String

func (r Result) String() string

String redacts Token so logging or formatting a Result with %v or %+v never leaks the bearer token.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL