authentication

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ALG_HS256 = "HS256"
View Source
const JWK_PATH = "/oidc/.well-known/jwks.json"
View Source
const RandStringLen = 16

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessTokenClaims

type AccessTokenClaims struct {
	jwt.StandardClaims
	AccessTokenExtended
}

type AccessTokenExtended

type AccessTokenExtended struct {
	Scope string `json:"scope,omitempty"`
}

type AuthURLParams

type AuthURLParams struct {
	RedirectUri string
	State       string
	Nonce       string
	Scope       string
	Forced      bool
}

type AuthUrlResult

type AuthUrlResult struct {
	Url   string
	State string
	Nonce string
}

type AuthenticationClientOptions

type AuthenticationClientOptions struct {
	/** 应用 ID */
	AppId string

	/** 应用 Secret */
	AppSecret string

	/** 应用对应的用户池域名,例如 pool.authing.cn */
	Domain string

	/** 认证完成后的重定向目标 URL */
	RedirectUri string

	/** 登出完成后的重定向目标 URL, 可选 */
	LogoutRedirectUri string

	/**
	 * @optional
	 * 应用侧向 Authing 请求的权限,以空格分隔,默认为 'openid profile'
	 *
	 * 成功获取的权限会出现在 Access Token 的 scope 字段中
	 *
	 * 一些示例:
	 * - openid OIDC 标准规定的权限,必须包含
	 * - profile 获取用户的基本身份信息
	 * - offline_access 获取用户的 Refresh Token,可用于调用 refreshLoginState 刷新用户的登录态
	 */
	Scope string
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(options *AuthenticationClientOptions) (*Client, error)

func (*Client) BuildAuthUrl

func (client *Client) BuildAuthUrl(params *AuthURLParams) (AuthUrlResult, error)

func (*Client) BuildLogoutUrl

func (client *Client) BuildLogoutUrl(params *LogoutURLParams) (string, error)

func (*Client) GetLoginStateByAuthCode

func (client *Client) GetLoginStateByAuthCode(params *CodeToTokenParams) (*LoginState, error)

func (*Client) GetUserInfo

func (client *Client) GetUserInfo(accessToken string) (*UserInfo, error)

func (*Client) ParsedAccessToken

func (client *Client) ParsedAccessToken(tokenStr string) (*AccessTokenClaims, error)

func (*Client) ParsedIDToken

func (client *Client) ParsedIDToken(tokenStr string) (*IDTokenClaims, error)

func (*Client) RefreshLoginState

func (client *Client) RefreshLoginState(refreshToken string) (*LoginState, error)

type CodeToTokenParams

type CodeToTokenParams struct {
	Code        string
	RedirectUri string
	Nonce       string
}

type IDTokenClaims

type IDTokenClaims struct {
	UserInfoCommon
	IDTokenExtended
	jwt.StandardClaims
}

type IDTokenExtended

type IDTokenExtended struct {
	Nonce  string `json:"nonce,omitempty"`
	AtHash string `json:"at_hash,omitempty"`
	SHash  string `json:"s_hash,omitempty"`
}

type LoginState

type LoginState struct {
	AccessToken       string `json:"access_token"`
	IDToken           string `json:"id_token"`
	RefreshToken      string `json:"refresh_token"` //可选
	ExpiresIn         uint64 `json:"expires_in"`
	ExpireAt          time.Time
	ParsedIDToken     *IDTokenClaims
	ParsedAccessToken *AccessTokenClaims
}

type LogoutURLParams

type LogoutURLParams struct {
	PostLogoutRedirectUri string // 可选
	IDTokenHint           string // 可选
	State                 string // 可选
}

type UserInfo

type UserInfo struct {
	Subject string `json:"sub,omitempty"` // 用户 ID
	UserInfoCommon
}

type UserInfoCommon

type UserInfoCommon struct {
	Name              string `json:"name,omitempty"`
	Nickname          string `json:"nickname,omitempty"`
	GivenName         string `json:"given_name,omitempty"`
	FamilyName        string `json:"family_name,omitempty"`
	Birthdate         string `json:"birthdate,omitempty"`
	Gender            string `json:"gender,omitempty"` //'M' | 'F' | 'U'
	Picture           string `json:"picture,omitempty"`
	UpdatedAt         string `json:"updated_at,omitempty"`
	Zoneinfo          string `json:"zoneinfo,omitempty"`
	PreferredUsername string `json:"preferred_username,omitempty"`
	Locale            string `json:"locale,omitempty"`
}

Jump to

Keyboard shortcuts

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