oauthgoauth2

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthURLOptions

type AuthURLOptions struct {
	RedirectURL string            // Redirect URL after authentication
	ReturnTo    string            // ReturnTo URL after authentication
	Scopes      []string          // Scopes to request
	Prompt      string            // Prompt to use
	LoginHint   string            // Login hint to use
	Extras      map[string]string // Additional parameters to include in the URL
}

AuthURLOptions are the options for generating an authentication URL.

type OAuth2Config

type OAuth2Config struct {
	ClientID      string            // required
	ClientSecret  string            // optional for public clients, required for confidential clients
	Scopes        []string          // scopes to request, defaults to "openid profile email"
	AuthURL       string            // optional, for discovery-based providers
	TokenURL      string            // optional, for discovery-based providers
	UserInfoURL   string            // optional, provide if OIDC is not supported
	RevocationURL string            // optional RFC7009
	ExtraAuth     map[string]string // provider-specific params if needed
	ExtraToken    map[string]string // provider-specific params if needed
	UsePKCE       bool              // controls whether to use PKCE (Proof Key for Code Exchange) in the OAuth2 flow
}

OAuth2Config represents the configuration for the OAuth2 provider.

type OAuth2Provider

type OAuth2Provider interface {
	UserInfoURL() string
	// Name returns the name of the provider.
	Name() string
	// AuthURL returns the URL to redirect the user to for authentication.
	AuthURL(ctx context.Context, r *http.Request, opts AuthURLOptions) (url string, opaqueState string, err error)
	// Exchange exchanges an authorization code for an access token.
	Exchange(ctx context.Context, r *http.Request, code string, opaqueState string) (*OAuth2Session, error)
	// Refresh refreshes an access token based on a refresh token.
	Refresh(ctx context.Context, refreshToken string) (*OAuth2Session, error)
	// Revoke revokes a token.
	Revoke(ctx context.Context, token string) error
	// GetState Get state from opaque state
	GetState(ctx context.Context, opaqueState string) (*oauthgostate.StatePayload, error)
}

OAuth2Provider is an OAuth2 provider that needs to be implemented by a provider.

type OAuth2Session

type OAuth2Session struct {
	Provider        string         `json:"provider"`      // Required
	AccessToken     string         `json:"access_token"`  // Required
	RefreshToken    string         `json:"refresh_token"` // Present if the provider supports refresh tokens
	IDToken         string         `json:"id_token"`      // optional; empty in pure OAuth2
	TokenType       string         `json:"token_type"`    // Access token type
	Expiry          time.Time      `json:"expiry"`        // Expiry time of the access token
	Raw             map[string]any `json:"raw"`           // Raw token data
	RequestedScopes []string       `json:"requested_scopes"`
	GrantedScopes   []string       `json:"granted_scopes"`
}

OAuth2Session represents an OAuth2 session containing an access token, refresh token, and ID token.

type StandardOAuth2Provider

type StandardOAuth2Provider struct {
	// contains filtered or unexported fields
}

StandardOAuth2Provider is an OAuth2 provider that implements the OAuth2Provider interface.

func NewStandardOAuth2Provider

func NewStandardOAuth2Provider(
	name string,
	cfg OAuth2Config,
) *StandardOAuth2Provider

NewStandardOAuth2Provider creates a new StandardOAuth2Provider.

func (*StandardOAuth2Provider) AuthURL

AuthURL implements the OAuth2Provider interface method and returns the URL to redirect the user to for authentication.

func (*StandardOAuth2Provider) Exchange

func (p *StandardOAuth2Provider) Exchange(ctx context.Context, r *http.Request, code, opaque string) (*OAuth2Session, error)

Exchange implements the OAuth2Provider interface method and exchanges the code for a token.

func (*StandardOAuth2Provider) GetState added in v0.1.2

func (p *StandardOAuth2Provider) GetState(ctx context.Context, opaqueState string) (*oauthgostate.StatePayload, error)

GetState implements the OAuth2Provider interface method and gets the state.

func (*StandardOAuth2Provider) Name

func (p *StandardOAuth2Provider) Name() string

Name implements the OAuth2Provider interface method and returns the provider name.

func (*StandardOAuth2Provider) Refresh

func (p *StandardOAuth2Provider) Refresh(ctx context.Context, refreshToken string) (*OAuth2Session, error)

Refresh implements the OAuth2Provider interface method and refreshes the token.

func (*StandardOAuth2Provider) Revoke

func (p *StandardOAuth2Provider) Revoke(ctx context.Context, token string) error

Revoke implements the OAuth2Provider interface method and revokes the token.

func (*StandardOAuth2Provider) UserInfoURL added in v0.1.4

func (p *StandardOAuth2Provider) UserInfoURL() string

type TokenExchangeResult added in v0.1.3

type TokenExchangeResult struct {
	Token      *oauth2.Token
	RawBody    map[string]any
	RawHeaders map[string]string
}

TokenExchangeResult contains the parsed token plus raw token response metadata.

Jump to

Keyboard shortcuts

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