Documentation ¶
Index ¶
- Constants
- Variables
- func SplitAndValidateScope(str string) (scope.AccessScopes, error)
- func VerifyToken(token string, publicKey *rsa.PublicKey) (*jwt.Token, error)
- type AuthorizeData
- type AuthorizeStore
- type Client
- type ClientStore
- type Handler
- func (store *Handler) AuthorizationDecideHandler(c echo.Context) error
- func (store *Handler) AuthorizationEndpointHandler(c echo.Context) error
- func (store *Handler) DiscoveryHandler(c echo.Context) error
- func (store *Handler) IsOpenIDConnectAvailable() bool
- func (store *Handler) IssueAccessToken(client *Client, userID uuid.UUID, redirectURI string, scope scope.AccessScopes, ...) (*Token, error)
- func (store *Handler) LoadKeys(private, public []byte) (err error)
- func (store *Handler) NewIDToken(issueAt time.Time, expireIn int64) *IDToken
- func (store *Handler) PublicKeysHandler(c echo.Context) error
- func (store *Handler) TokenEndpointHandler(c echo.Context) error
- type IDToken
- type Store
- type Token
- type TokenStore
- type UserInfo
Constants ¶
const (
// AuthScheme Authorizationヘッダーのスキーム
AuthScheme = "Bearer"
)
Variables ¶
var ( // ErrInvalidScope OAuth2エラー 不正なスコープです ErrInvalidScope = &errorResponse{ErrorType: errInvalidScope} // ErrClientNotFound OAuth2エラー クライアントが存在しません ErrClientNotFound = &errorResponse{ErrorType: errInvalidClient} // ErrAuthorizeNotFound OAuth2エラー 認可コードが存在しません ErrAuthorizeNotFound = &errorResponse{ErrorType: errInvalidGrant} // ErrTokenNotFound OAuth2エラー トークンが存在しません ErrTokenNotFound = &errorResponse{ErrorType: errInvalidGrant} // ErrUserIDOrPasswordWrong OAuth2エラー ユーザー認証に失敗しました ErrUserIDOrPasswordWrong = &errorResponse{ErrorType: errInvalidGrant} )
var ( // ErrInvalidIDToken : OpenID Connectエラー 不正なIDトークンです ErrInvalidIDToken = errors.New("invalid token") )
Functions ¶
func SplitAndValidateScope ¶
func SplitAndValidateScope(str string) (scope.AccessScopes, error)
SplitAndValidateScope : スペース区切りのスコープ文字列を分解し、検証します
Types ¶
type AuthorizeData ¶
type AuthorizeData struct { Code string ClientID string UserID uuid.UUID CreatedAt time.Time ExpiresIn int RedirectURI string Scopes scope.AccessScopes OriginalScopes scope.AccessScopes CodeChallenge string CodeChallengeMethod string Nonce string }
AuthorizeData : Authorization Code Grant用の認可データ構造体
func (*AuthorizeData) IsExpired ¶
func (data *AuthorizeData) IsExpired() bool
IsExpired : 有効期限が切れているかどうか
func (*AuthorizeData) ValidatePKCE ¶
func (data *AuthorizeData) ValidatePKCE(verifier string) (bool, error)
ValidatePKCE : PKCEの検証を行う
type AuthorizeStore ¶
type AuthorizeStore interface { SaveAuthorize(data *AuthorizeData) error GetAuthorize(code string) (*AuthorizeData, error) DeleteAuthorize(code string) error }
AuthorizeStore OAuth2用の認可コードストアインターフェイス
type Client ¶
type Client struct { ID string Name string Description string Confidential bool CreatorID uuid.UUID Secret string RedirectURI string Scopes scope.AccessScopes }
Client : OAuth2.0クライアント構造体
func (*Client) GetAvailableScopes ¶
func (c *Client) GetAvailableScopes(request scope.AccessScopes) (result scope.AccessScopes)
GetAvailableScopes : requestで与えられたスコープのうち、利用可能なものを返します
type ClientStore ¶
type ClientStore interface { GetClient(id string) (*Client, error) GetClientsByUser(userID uuid.UUID) ([]*Client, error) SaveClient(client *Client) error UpdateClient(client *Client) error DeleteClient(id string) error }
ClientStore OAuth2用のクライアントストアインターフェイス
type Handler ¶
type Handler struct { Store //AccessTokenExp アクセストークンの有効時間(秒) AccessTokenExp int //AuthorizationCodeExp 認可コードの有効時間(秒) AuthorizationCodeExp int //IsRefreshEnabled リフレッシュトークンを発行するかどうか IsRefreshEnabled bool //UserAuthenticator ユーザー認証を行う関数 UserAuthenticator func(id, pw string) (uuid.UUID, error) //UserInfoGetter ユーザー情報を取得する関数 UserInfoGetter func(uid uuid.UUID) (UserInfo, error) Issuer string // contains filtered or unexported fields }
Handler OAuth2のハンドラ
func (*Handler) AuthorizationDecideHandler ¶
AuthorizationDecideHandler : 認可エンドポイントの確認フォームのハンドラ
func (*Handler) AuthorizationEndpointHandler ¶
AuthorizationEndpointHandler : 認可エンドポイントのハンドラ
func (*Handler) DiscoveryHandler ¶
DiscoveryHandler returns the OpenID Connect discovery object.
func (*Handler) IsOpenIDConnectAvailable ¶
IsOpenIDConnectAvailable OpenID Connectが有効かどうかを返します
func (*Handler) IssueAccessToken ¶
func (store *Handler) IssueAccessToken(client *Client, userID uuid.UUID, redirectURI string, scope scope.AccessScopes, expire int, refresh bool) (*Token, error)
IssueAccessToken : AccessTokenを発行します
func (*Handler) NewIDToken ¶
NewIDToken IDTokenを生成します
func (*Handler) PublicKeysHandler ¶
PublicKeysHandler publishes the public signing keys.
type IDToken ¶
type IDToken struct { jwt.StandardClaims Nonce string `json:"nonce,omitempty"` Name string `json:"name,omitempty"` }
IDToken : OpenID Connect IDToken
type Store ¶
type Store interface { ClientStore AuthorizeStore TokenStore }
Store : OAuth2用の各種データのストアインターフェイス
type Token ¶
type Token struct { ID uuid.UUID ClientID string UserID uuid.UUID RedirectURI string AccessToken string RefreshToken string CreatedAt time.Time ExpiresIn int Scopes scope.AccessScopes }
Token : OAuth2.0 Access Token構造体
func (*Token) GetAvailableScopes ¶
func (t *Token) GetAvailableScopes(request scope.AccessScopes) (result scope.AccessScopes)
GetAvailableScopes : requestで与えられたスコープのうち、利用可能なものを返します
type TokenStore ¶
type TokenStore interface { SaveToken(token *Token) error GetTokenByID(id uuid.UUID) (*Token, error) DeleteTokenByID(id uuid.UUID) error GetTokenByAccess(access string) (*Token, error) DeleteTokenByAccess(access string) error GetTokenByRefresh(refresh string) (*Token, error) DeleteTokenByRefresh(refresh string) error GetTokensByUser(userID uuid.UUID) ([]*Token, error) DeleteTokenByUser(userID uuid.UUID) error DeleteTokenByClient(clientID string) error }
TokenStore OAuth2用のトークンストアインターフェイス