auth

package
v0.0.0-...-2635c8b Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OAuthClientID

func OAuthClientID() string

OAuthClientID returns the OAuth client ID used for the device flow, overridable via MEMORY_OAUTH_CLIENT_ID (e.g. to point the CLI at a dev Zitadel instance whose memory-cli app has a different client ID).

func OpenBrowser

func OpenBrowser(urlStr string) error

func RevokeCredentials

func RevokeCredentials(creds *Credentials, clientID string) []string

RevokeCredentials attempts to revoke all tokens in the given credentials using the OIDC revocation endpoint discovered from the stored issuer URL. It revokes the refresh token first (higher-value target), then the access token. Returns a list of warnings for any failures — callers should log these but not block.

func RevokeToken

func RevokeToken(revocationEndpoint, clientID, token, tokenTypeHint string) error

RevokeToken revokes a single OAuth token via the OIDC revocation endpoint (RFC 7009). tokenTypeHint should be "access_token" or "refresh_token". Returns nil if revocation succeeds or the endpoint is not available (best-effort).

func Save

func Save(creds *Credentials, path string) error

Types

type Credentials

type Credentials struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	ExpiresAt    time.Time `json:"expires_at"`
	UserEmail    string    `json:"user_email,omitempty"`
	IssuerURL    string    `json:"issuer_url,omitempty"`
}

func Load

func Load(path string) (*Credentials, error)

func (*Credentials) IsExpired

func (c *Credentials) IsExpired() bool

type DeviceCodeResponse

type DeviceCodeResponse struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri"`
	VerificationURIComplete string `json:"verification_uri_complete"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval"`
}

func RequestDeviceCode

func RequestDeviceCode(config *OIDCConfig, clientID string, scopes []string) (*DeviceCodeResponse, error)

type OIDCConfig

type OIDCConfig struct {
	Issuer                      string `json:"issuer"`
	DeviceAuthorizationEndpoint string `json:"device_authorization_endpoint"`
	TokenEndpoint               string `json:"token_endpoint"`
	UserinfoEndpoint            string `json:"userinfo_endpoint"`
	AuthorizationEndpoint       string `json:"authorization_endpoint,omitempty"`
	RevocationEndpoint          string `json:"revocation_endpoint,omitempty"`
	JwksURI                     string `json:"jwks_uri,omitempty"`
}

func DiscoverOIDC

func DiscoverOIDC(issuerURL string) (*OIDCConfig, error)

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
	TokenType    string `json:"token_type"`
	IDToken      string `json:"id_token,omitempty"`
}

func PollForToken

func PollForToken(config *OIDCConfig, deviceCode, clientID string, interval, expiresIn int) (*TokenResponse, error)

func RefreshToken

func RefreshToken(config *OIDCConfig, refreshToken, clientID string) (*TokenResponse, error)

type UserInfo

type UserInfo struct {
	Sub   string `json:"sub"`
	Email string `json:"email"`
	Name  string `json:"name"`
}

func GetUserInfo

func GetUserInfo(config *OIDCConfig, accessToken string) (*UserInfo, error)

Jump to

Keyboard shortcuts

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