oauth2

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: GPL-3.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OAuth2Error

func OAuth2Error(c *gin.Context, err error, msg string)

Types

type Authenticator

type Authenticator struct {
	OAuth2Authenticator
	// contains filtered or unexported fields
}

The underlying implementation uses the golang.org/x/oauth2 package

func (Authenticator) Authenticate

func (a Authenticator) Authenticate(c *gin.Context)

middleware (authentication): authenticates a request coming from the oauth2 server two possible behaviors (based on the query string): - sign up user - log in user

func (Authenticator) CleanUpStatesEach

func (a Authenticator) CleanUpStatesEach(d time.Duration)

clean up utilty: removes all expired states from the memory storage run it as go routine when init the authenticator

func (*Authenticator) Ft

func (a *Authenticator) Ft()

func (Authenticator) GetToken

func (a Authenticator) GetToken(c *gin.Context)

func (Authenticator) Redirect

func (a Authenticator) Redirect(scope string) gin.HandlerFunc

type OAuth2Authenticator

type OAuth2Authenticator interface {
	auth.Authenticator

	// middlware:
	// 1. gets the user's token object from the oauth2 server
	// 2. stores the token in the context (at "oauth2.token")
	GetToken(c *gin.Context)

	// middleware (handler):
	// redirects the user to the oauth2 server endpoint for the given
	// scope
	Redirect(scope string)
}

Middlewares exposed by the `Authenticator` struct below are described by this interface:

type OAuth2StateProvider

type OAuth2StateProvider interface {
	GenerateState(scope string, exp time.Duration) (string, error)
	Validate(token string) error
	Delete(token string) error
	GetScope(token string) (string, error)
}

type States

type States map[string]stateValue

We implement this interface as a mere map.

func (States) Delete

func (s States) Delete(state string) error

func (States) GenerateState

func (s States) GenerateState(scope string, exp time.Duration) (string, error)

func (States) GetScope

func (s States) GetScope(token string) (string, error)

func (States) Validate

func (s States) Validate(state string) error

Jump to

Keyboard shortcuts

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