oauth2

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareBcrypt

func CompareBcrypt(hash, password string) error

func EncodeState

func EncodeState(state State) (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             int    `json:"expires_in"`
	RefreshToken          string `json:"refresh_token"`
	RefreshTokenExpiresIn int    `json:"refresh_token_expires_in"`
	Scope                 string `json:"scope,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"`
	// 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) 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) CodeAuth

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

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

func (*Oauth2) GenerateToken

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

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 State

type State struct {
	RedirectURI string `json:"redirect_uri"`
	State       string `json:"state"`
	OrgState    string `json:"org_state"`
}

func DecodeState

func DecodeState(encoded string) (State, error)

type Token

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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