oauthgo

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeJSON  = "application/json; charset=utf-8"
	EnvSIDCookie     = "SID_COOKIE"
	DefaultSIDCookie = "oauthgo_sid"
	ErrNotSignedIn   = "not signed in"
	PathRoot         = "/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthURLOptions

type AuthURLOptions = oauthgoauth2.AuthURLOptions

type CallbackOptions

type CallbackOptions struct {
	SetLoginCookie bool // set the login cookie
	SetSIDCookie   bool // to set the SID in the cookie, StoreSession needed to be set to true if this is set to true
	StoreSession   bool // store the session data in the session store if this is set to true, SessionStore must be provided
	OnSuccess      func(http.ResponseWriter, *http.Request, *CallbackResult)
	OnError        func(http.ResponseWriter, *http.Request, error)
}

CallbackOptions provides options to customize the callback behavior.

type CallbackResult

type CallbackResult struct {
	ProviderName string
	User         *User
	Session      *SessionData
	SID          string
	ReturnTo     string
}

CallbackResult contains the final results of a callback.

type HandlerFacade

type HandlerFacade struct{}

HandlerFacade is a facade for the handlers.

func (*HandlerFacade) AutoCallbackOAuth2

func (h *HandlerFacade) AutoCallbackOAuth2(provider string) http.HandlerFunc

AutoCallbackOAuth2 returns a handler that handles the callback for OAuth2. If ?redirect_uri=/ (or ?rd=/) is present, redirect there; else return JSON.

func (*HandlerFacade) AutoCallbackOIDC

func (h *HandlerFacade) AutoCallbackOIDC(provider string) http.HandlerFunc

AutoCallbackOIDC returns a handler that handles the callback for OIDC. If ?redirect_uri=/ (or ?rd=/) is present, redirect there; else return JSON.

func (*HandlerFacade) AutoLogin

func (h *HandlerFacade) AutoLogin(baseUrl string, provider string) http.HandlerFunc

AutoLogin returns a handler that redirects to the provider by default (like Login). If the client prefers JSON, pass ?json=1 or set Accept: application/json.

func (*HandlerFacade) Callback

func (h *HandlerFacade) Callback(provider string, opts CallbackOptions) http.HandlerFunc

Callback returns a handler that handles the callback after the user logs in. Default behavior: if opts.OnSuccess is nil, redirect to ?redirect_uri (or ?rd) when provided; otherwise return JSON payload.

func (*HandlerFacade) LoggedInUser

func (h *HandlerFacade) LoggedInUser() http.HandlerFunc

LoggedInUser returns a handler that returns the logged-in user (JSON).

func (*HandlerFacade) Login

func (h *HandlerFacade) Login(provider string, authURLOptions AuthURLOptions) http.HandlerFunc

Login returns a handler that redirects to the provider auth page by default. If the client prefers JSON, pass ?json=1 or ?format=json or set Accept: application/json.

func (*HandlerFacade) Logout

func (h *HandlerFacade) Logout() http.HandlerFunc

Logout returns a handler that logs out the user. If ?redirect_uri=/ (or ?rd=/) is provided, it will redirect after clearing sessions.

func (*HandlerFacade) Refresh

func (h *HandlerFacade) Refresh(provider string, refreshToken string) http.HandlerFunc

Refresh returns a handler that refreshes an access token (JSON).

func (*HandlerFacade) Register

func (h *HandlerFacade) Register(name string, provider oauth2oidc.OAuthO2IDCProvider)

Register registers a provider.

func (*HandlerFacade) Revoke

func (h *HandlerFacade) Revoke(provider string, token string) http.HandlerFunc

Revoke returns a handler that revokes a token (JSON).

func (*HandlerFacade) UserInfo

func (h *HandlerFacade) UserInfo(userInfoEndpoint string, method string) http.HandlerFunc

UserInfo returns a handler that fetches user info from the userinfo endpoint using the access token from the Authorization header.

type ProviderManager

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

ProviderManager is the main entry point for the OIDC/OAuth2 provider.

func NewProviderManager

func NewProviderManager() *ProviderManager

NewProviderManager creates a new ProviderManager.

func (*ProviderManager) AuthURL

func (m *ProviderManager) AuthURL(
	providerName string,
	r *http.Request,
	opts AuthURLOptions,
) (string, string, error)

AuthURL returns the URL to redirect the user to for authentication.

func (*ProviderManager) Callback

func (m *ProviderManager) Callback(
	providerName string,
	w http.ResponseWriter,
	r *http.Request,
	opts CallbackOptions,
) (*CallbackResult, error)

Callback handles the callback after the user logs in.

func (*ProviderManager) LoggedInUser

func (m *ProviderManager) LoggedInUser(
	w http.ResponseWriter,
	r *http.Request,
)

LoggedInUser writes JSON information about the logged-in user (cookie + optional server session).

func (*ProviderManager) Logout

func (m *ProviderManager) Logout(
	w http.ResponseWriter,
	r *http.Request,
)

Logout logs out the user (revoke if possible, clear server and browser sessions). Returns JSON by default; if a redirect target is provided via query (?redirect_uri=/ or ?rd=/), performs a 302 redirect instead.

func (*ProviderManager) Refresh

func (m *ProviderManager) Refresh(
	providerName string,
	refreshToken string,
	r *http.Request,
) (*oauthgoauth2.OAuth2Session, error)

Refresh refreshes the access token based on a refresh token.

func (*ProviderManager) Register

func (m *ProviderManager) Register(name string, provider oauth2oidc.OAuthO2IDCProvider)

Register registers a provider.

func (*ProviderManager) Revoke

func (m *ProviderManager) Revoke(
	providerName string,
	token string,
	r *http.Request,
) error

Revoke revokes the token.

type SessionData

type SessionData = oauthgoauth2.OAuth2Session

type User

type User = oidccore.User

Jump to

Keyboard shortcuts

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