oauth

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateState

func GenerateState() string

GenerateState returns a cryptographically random 64-character hex string for use as the OAuth2 state parameter.

Types

type Provider

type Provider struct {
	Name         string
	ClientID     string
	ClientSecret string
	RedirectURL  string
	Scopes       []string
	AuthURL      string
	TokenURL     string
	UserInfoURL  string
	// contains filtered or unexported fields
}

Provider configures an OAuth2 provider (e.g., Google, GitHub).

func GitHub

func GitHub(clientID, clientSecret, redirectURL string) *Provider

GitHub creates a pre-configured GitHub OAuth2 provider.

func Google

func Google(clientID, clientSecret, redirectURL string) *Provider

Google creates a pre-configured Google OAuth2 provider.

func NewProvider

func NewProvider(name, clientID, clientSecret, redirectURL string, scopes []string, authURL, tokenURL, userInfoURL string, parser func(map[string]any) UserInfo) *Provider

NewProvider creates a custom OAuth2 provider with the given configuration.

func (*Provider) AuthCodeURL

func (p *Provider) AuthCodeURL(state string) string

AuthCodeURL builds the authorization redirect URL with the provided state.

func (*Provider) Exchange

func (p *Provider) Exchange(ctx context.Context, code string) (*oauth2.Token, error)

Exchange exchanges the authorization code for an access token.

func (*Provider) FetchUser

func (p *Provider) FetchUser(ctx context.Context, token *oauth2.Token) (UserInfo, error)

FetchUser fetches and normalizes the user's profile from the provider API.

type UserInfo

type UserInfo struct {
	ID        string
	Email     string
	Name      string
	AvatarURL string
	Raw       map[string]any
}

UserInfo holds normalized user profile data from an OAuth2 provider.

Jump to

Keyboard shortcuts

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