core

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: MIT Imports: 17 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenIssuerNotMatch            = errors.New("token issuer not match")
	ErrTokenAudienceNotMatch          = errors.New("token audience not match")
	ErrTokenExpired                   = errors.New("token expired")
	ErrTokenIssuedInTheFuture         = errors.New("token issued in the future")
	ErrTokenIssuedInThePast           = errors.New("token issued in the past")
	ErrCallbackUriNotMatchRedirectUri = errors.New("callback uri not match redirect uri")
	ErrStateNotMatch                  = errors.New("state not match")
	ErrCodeNotFoundInCallbackUri      = errors.New("code not found in callback uri")
)
View Source
var ISSUED_AT_RESTRICTIONS int64 = 60 // in seconds

Functions

func GenerateCodeChallenge

func GenerateCodeChallenge(codeVerifier string) string

func GenerateCodeVerifier

func GenerateCodeVerifier() string

func GenerateSignInUri

func GenerateSignInUri(option *SignInUriGenerationOptions) (string, error)

func GenerateSignOutUri

func GenerateSignOutUri(option *SignOutUriGenerationOptions) (string, error)

func GenerateState

func GenerateState() string

func Revoke

func Revoke(client *http.Client, options *RevocationOptions) error

func VerifyAndParseCodeFromCallbackUri

func VerifyAndParseCodeFromCallbackUri(callbackUri, redirectUri, state string) (string, error)

func VerifyIdToken

func VerifyIdToken(idToken, clientId, issuer string, jwks *jose.JSONWebKeySet) error

Types

type CodeTokenResponse

type CodeTokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	IdToken      string `json:"id_token"`
	Scope        string `json:"scope"`
	ExpireIn     int    `json:"expires_in"`
}

func FetchTokenByAuthorizationCode

func FetchTokenByAuthorizationCode(client *http.Client, options *FetchTokenByAuthorizationCodeOptions) (CodeTokenResponse, error)

type FetchTokenByAuthorizationCodeOptions

type FetchTokenByAuthorizationCodeOptions struct {
	TokenEndpoint string
	Code          string
	CodeVerifier  string
	ClientId      string
	RedirectUri   string
	Resource      string
}

type FetchTokenByRefreshTokenOptions

type FetchTokenByRefreshTokenOptions struct {
	TokenEndpoint string
	ClientId      string
	RefreshToken  string
	Resource      string
	Scopes        []string
}

type IdTokenClaims

type IdTokenClaims struct {
	Sub       string   `json:"sub"`
	Aud       string   `json:"aud"`
	Exp       int64    `json:"exp"`
	Iat       int64    `json:"iat"`
	Iss       string   `json:"iss"`
	AtHash    string   `json:"at_hash"`
	Username  string   `json:"username"`
	Name      string   `json:"name"`
	Avatar    string   `json:"avatar"`
	RoleNames []string `json:"role_names"`
}

func DecodeIdToken

func DecodeIdToken(token string) (IdTokenClaims, error)

type JwksResponse

type JwksResponse struct {
	Keys []map[string]string `json:"keys"`
}

func FetchJwks

func FetchJwks(client *http.Client, jwksUri string) (JwksResponse, error)

type OidcConfigResponse

type OidcConfigResponse struct {
	AuthorizationEndpoint string `json:"authorization_endpoint"`
	TokenEndpoint         string `json:"token_endpoint"`
	EndSessionEndpoint    string `json:"end_session_endpoint"`
	RevocationEndpoint    string `json:"revocation_endpoint"`
	JwksUri               string `json:"jwks_uri"`
	Issuer                string `json:"issuer"`
}

func FetchOidcConfig

func FetchOidcConfig(client *http.Client, endpoint string) (OidcConfigResponse, error)

type RefreshTokenResponse

type RefreshTokenResponse = CodeTokenResponse

func FetchTokenByRefreshToken

func FetchTokenByRefreshToken(client *http.Client, options *FetchTokenByRefreshTokenOptions) (RefreshTokenResponse, error)

type RevocationOptions

type RevocationOptions struct {
	RevocationEndpoint string
	ClientId           string
	Token              string
}

type SignInUriGenerationOptions

type SignInUriGenerationOptions struct {
	AuthorizationEndpoint string
	ClientId              string
	RedirectUri           string
	CodeChallenge         string
	State                 string
	Scopes                []string
	Resources             []string
	Prompt                string
}

type SignOutUriGenerationOptions

type SignOutUriGenerationOptions struct {
	EndSessionEndpoint    string
	IdToken               string
	PostLogoutRedirectUri string
}

Jump to

Keyboard shortcuts

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