core

package
v0.0.0-...-04d8ac2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ReservedScopeOpenId        = "openid"
	ReservedScopeOfflineAccess = "offline_access"
)
View Source
var (
	UserScopeProfile    = "profile"
	UserScopeEmail      = "email"
	UserScopePhone      = "phone"
	UserScopeCustomData = "custom_data"
	UserScopeIdentities = "identities"
)
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"`
}

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"`
	UserinfoEndpoint      string `json:"userinfo_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
	ClientId              string
	PostLogoutRedirectUri string
}

type UserInfoResponse

type UserInfoResponse struct {
	Sub                 string                 `json:"sub"`
	Name                string                 `json:"name"`
	Username            string                 `json:"username"`
	Picture             string                 `json:"picture"`
	Email               string                 `json:"email"`
	EmailVerified       bool                   `json:"email_verified"`
	PhoneNumber         string                 `json:"phone_number"`
	PhoneNumberVerified bool                   `json:"phone_number_verified"`
	CustomData          map[string]interface{} `json:"custom_data"`
	Identities          map[string]interface{} `json:"identities"`
}

func FetchUserInfo

func FetchUserInfo(client *http.Client, userInfoEndpoint, accessToken string) (UserInfoResponse, error)

Jump to

Keyboard shortcuts

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