oauth2

package
v1.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// AuthScheme Authorizationヘッダーのスキーム
	AuthScheme = "Bearer"
)

Variables

View Source
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}
)
View Source
var (
	// ErrInvalidIDToken : OpenID Connectエラー 不正なIDトークンです
	ErrInvalidIDToken = errors.New("invalid token")
)

Functions

func SplitAndValidateScope

func SplitAndValidateScope(str string) (scope.AccessScopes, error)

SplitAndValidateScope : スペース区切りのスコープ文字列を分解し、検証します

func VerifyToken

func VerifyToken(token string, publicKey *rsa.PublicKey) (*jwt.Token, error)

VerifyToken : 与えられたJWTが有効かどうかを確認します

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

func (store *Handler) AuthorizationDecideHandler(c echo.Context) error

AuthorizationDecideHandler : 認可エンドポイントの確認フォームのハンドラ

func (*Handler) AuthorizationEndpointHandler

func (store *Handler) AuthorizationEndpointHandler(c echo.Context) error

AuthorizationEndpointHandler : 認可エンドポイントのハンドラ

func (*Handler) DiscoveryHandler

func (store *Handler) DiscoveryHandler(c echo.Context) error

DiscoveryHandler returns the OpenID Connect discovery object.

func (*Handler) IsOpenIDConnectAvailable

func (store *Handler) IsOpenIDConnectAvailable() bool

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) LoadKeys

func (store *Handler) LoadKeys(private, public []byte) (err error)

LoadKeys OpenID Connectのjwt用のRSA秘密鍵・公開鍵を読み込みます

func (*Handler) NewIDToken

func (store *Handler) NewIDToken(issueAt time.Time, expireIn int64) *IDToken

NewIDToken IDTokenを生成します

func (*Handler) PublicKeysHandler

func (store *Handler) PublicKeysHandler(c echo.Context) error

PublicKeysHandler publishes the public signing keys.

func (*Handler) TokenEndpointHandler

func (store *Handler) TokenEndpointHandler(c echo.Context) error

TokenEndpointHandler : トークンエンドポイントのハンドラ

type IDToken

type IDToken struct {
	jwt.StandardClaims

	Nonce string `json:"nonce,omitempty"`

	Name string `json:"name,omitempty"`
}

IDToken : OpenID Connect IDToken

func (*IDToken) Generate

func (t *IDToken) Generate(key *rsa.PrivateKey) (string, error)

Generate : IDTokenからJWTを生成します

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で与えられたスコープのうち、利用可能なものを返します

func (*Token) IsExpired

func (t *Token) IsExpired() bool

IsExpired : 有効期限が切れているかどうか

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用のトークンストアインターフェイス

type UserInfo

type UserInfo interface {
	GetUID() uuid.UUID
	GetName() string
}

UserInfo ユーザー情報インターフェイス

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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