oauth2

package
v0.8.21 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultTokenLifetime   = time.Minute * 15
	DefaultRefreshLifetime = time.Hour * 24
)

Functions

func CompareBcrypt

func CompareBcrypt(hash, password string) error

Types

type AccessClient

type AccessClient struct {
	ClientSecret  string   `cfg:"client_secret"`
	Scope         []string `cfg:"scope"`
	WhitelistURLs []string `cfg:"whitelist_urls"`
}

type AccessTokenErrorResponse

type AccessTokenErrorResponse struct {
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
	// contains filtered or unexported fields
}

func (AccessTokenErrorResponse) GetCode

func (e AccessTokenErrorResponse) GetCode() int

type AccessTokenRequest

type AccessTokenRequest struct {
	GrantType string `form:"grant_type"`
	Scope     string `form:"scope,omitempty"`

	RefreshToken string `form:"refresh_token,omitempty"`

	Username string `form:"username,omitempty"`
	Password string `form:"password,omitempty"`

	RedirectURI string `form:"redirect_uri,omitempty"`
	Code        string `form:"code,omitempty"`
}

type AccessTokenResponse

type AccessTokenResponse struct {
	TokenType             string `json:"token_type"`
	AccessToken           string `json:"access_token"`
	ExpiresIn             int64  `json:"expires_in"`
	RefreshToken          string `json:"refresh_token"`
	RefreshTokenExpiresIn int64  `json:"refresh_token_expires_in"`
	Scope                 string `json:"scope,omitempty"`
	IDToken               string `json:"id_token,omitempty"`
}

type Cert

type Cert struct {
	RSA RSAKey `cfg:"rsa"`
}

type JWK

type JWK struct {
	KID string   `json:"kid"`
	KTY string   `json:"kty"`
	ALG string   `json:"alg"`
	Use string   `json:"use"`
	N   string   `json:"n"`
	E   string   `json:"e"`
	X5C []string `json:"x5c,omitempty"`
}

JWK represents a JSON Web Key.

type JWKSResponse

type JWKSResponse struct {
	Keys []JWK `json:"keys"`
}

JWKSResponse represents the JSON Web Key Set response structure.

type Oauth2

type Oauth2 struct {
	PrefixPath    string `cfg:"prefix_path"`
	Token         Token  `cfg:"token"`
	IamMiddleware string `cfg:"iam_middleware"`

	AccessClients map[string]AccessClient `cfg:"access_clients"`

	// Providers for get token from there but return token from here.
	Providers map[string]*session.Oauth2 `cfg:"providers"`
	// Code for code auth flow.
	Code auth.Code `cfg:"code"`
	// Store for cache temporary data.
	Store store.Store `cfg:"store"`
	// PassLower for pass lower case on password flow.
	PassLower bool `cfg:"pass_lower"`

	WellKnown  map[string]map[string]any    `cfg:"well_known"`
	CustomInfo map[string]map[string]string `cfg:"custom_info"`
	// contains filtered or unexported fields
}

func (*Oauth2) APIAuth

func (m *Oauth2) APIAuth(w http.ResponseWriter, r *http.Request)

APIAuth for auth endpoint implementation of oauth2.

  • Authorization Code Grant

func (*Oauth2) APICerts

func (m *Oauth2) APICerts(w http.ResponseWriter, r *http.Request)

func (*Oauth2) APICodeAuth

func (m *Oauth2) APICodeAuth(w http.ResponseWriter, r *http.Request)

APICodeAuth will receive callback and generate new token and respond to redirection.

func (*Oauth2) APILogout

func (m *Oauth2) APILogout(w http.ResponseWriter, _ *http.Request)

func (*Oauth2) APIToken

func (m *Oauth2) APIToken(w http.ResponseWriter, r *http.Request)

APIToken for token endpoint implementation of oauth2.

func (*Oauth2) APIUserInfo

func (m *Oauth2) APIUserInfo(w http.ResponseWriter, r *http.Request)

func (*Oauth2) APIWellKnown

func (m *Oauth2) APIWellKnown(w http.ResponseWriter, r *http.Request)

func (*Oauth2) GenerateToken

func (m *Oauth2) GenerateToken(w http.ResponseWriter, userID string, user *data.UserExtended, clientID string, scope []string, defScope []string, _ map[string]interface{})

func (*Oauth2) GetAccessClient

func (m *Oauth2) GetAccessClient(clientID, clientSecret string) (*AccessClient, *AccessTokenErrorResponse)

func (*Oauth2) Init

func (m *Oauth2) Init() error

func (*Oauth2) Middleware

func (m *Oauth2) Middleware(ctx context.Context) (func(http.Handler) http.Handler, error)

func (*Oauth2) MuxSet

func (m *Oauth2) MuxSet(prefix string) *chi.Mux

type RSAKey

type RSAKey struct {
	PrivateKey       string `cfg:"private_key"`
	PrivateKeyBase64 string `cfg:"private_key_base64"`
	PublicKey        string `cfg:"public_key"`
	PublicKeyBase64  string `cfg:"public_key_base64"`
	// contains filtered or unexported fields
}

func (*RSAKey) GetPrivateKey

func (k *RSAKey) GetPrivateKey() (string, error)

func (*RSAKey) GetPublicKey

func (k *RSAKey) GetPublicKey() (string, error)

type Token

type Token struct {
	KID  string `cfg:"kid"`
	Cert Cert   `cfg:"cert"`

	TokenLifetime   time.Duration `cfg:"token_lifetime"`
	RefreshLifetime time.Duration `cfg:"refresh_lifetime"`
}

func (*Token) GetRefreshExpDate

func (t *Token) GetRefreshExpDate() int64

func (*Token) GetTokenExpDate

func (t *Token) GetTokenExpDate() int64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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