Documentation
¶
Index ¶
- Variables
- func Register(source string, factory AuthRequestFactory)
- type AuthCallback
- type AuthRequest
- type AuthRequestBuilder
- func (b *AuthRequestBuilder) Build() (AuthRequest, error)
- func (b *AuthRequestBuilder) ClientId(clientId string) *AuthRequestBuilder
- func (b *AuthRequestBuilder) ClientSecret(clientSecret string) *AuthRequestBuilder
- func (b *AuthRequestBuilder) RedirectUrl(redirectUrl string) *AuthRequestBuilder
- func (b *AuthRequestBuilder) Source(source string) *AuthRequestBuilder
- type AuthRequestFactory
- type AuthResponse
- type AuthToken
- type AuthUser
- type AuthUserGender
- type DefaultAuthRequest
- func (r *DefaultAuthRequest) AccessTokenUrl(code string) string
- func (r *DefaultAuthRequest) Authorize(state string) (string, error)
- func (r *DefaultAuthRequest) DoPostAuthorizationCode(code string) (string, error)
- func (r *DefaultAuthRequest) GetScopes(separator string, encode bool, defaultScopes []string) string
- func (r *DefaultAuthRequest) Login(callback AuthCallback) (AuthResponse, error)
- func (r *DefaultAuthRequest) Revoke(token AuthToken) error
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrAuthFailed = errors.New("auth failed") ErrGetAccessToken = errors.New("get access token error") ErrGetUserInfo = errors.New("get user info error") ErrIllegalStatus = errors.New("illegal status error") ErrNotImplemented = errors.New("not implemented") ErrClientIdNotFound = errors.New("client id is required") ErrClientSecretNotFound = errors.New("client secret is required") ErrSourceNotFound = errors.New("auth source is required") )
Functions ¶
func Register ¶
func Register(source string, factory AuthRequestFactory)
Types ¶
type AuthCallback ¶
type AuthCallback struct {
Code string `json:"code" schema:"code"`
AuthCode string `json:"auth_code" schema:"auth_code"`
State string `json:"state" schema:"state"`
AuthorizationCode string `json:"authorization_code" schema:"authorization_code"`
OauthToken string `json:"oauth_token" schema:"oauth_token"`
OauthVerifier string `json:"oauth_verifier" schema:"oauth_verifier"`
}
type AuthRequest ¶
type AuthRequest interface {
Authorize(state string) (string, error)
Login(callback AuthCallback) (AuthResponse, error)
GetAccessToken(callback AuthCallback) (AuthToken, error)
GetUserInfo(token AuthToken) (AuthUser, error)
Revoke(token AuthToken) error
}
type AuthRequestBuilder ¶
type AuthRequestBuilder struct {
// contains filtered or unexported fields
}
func New ¶
func New() *AuthRequestBuilder
func (*AuthRequestBuilder) Build ¶
func (b *AuthRequestBuilder) Build() (AuthRequest, error)
func (*AuthRequestBuilder) ClientId ¶
func (b *AuthRequestBuilder) ClientId(clientId string) *AuthRequestBuilder
func (*AuthRequestBuilder) ClientSecret ¶
func (b *AuthRequestBuilder) ClientSecret(clientSecret string) *AuthRequestBuilder
func (*AuthRequestBuilder) RedirectUrl ¶
func (b *AuthRequestBuilder) RedirectUrl(redirectUrl string) *AuthRequestBuilder
func (*AuthRequestBuilder) Source ¶
func (b *AuthRequestBuilder) Source(source string) *AuthRequestBuilder
type AuthRequestFactory ¶
type AuthRequestFactory interface {
NewAuthRequest(*config.AuthConfig) (AuthRequest, error)
}
type AuthResponse ¶
type AuthResponse struct {
Data interface{} `json:"data"`
}
type AuthToken ¶
type AuthToken struct {
AccessToken string `json:"access_token"`
ExpireIn int `json:"expire_in"`
RefreshToken string `json:"refresh_token"`
RefreshTokenExpireIn int `json:"refresh_token_expire_in"`
Uid string `json:"uid"`
OpenId string `json:"open_id"`
AccessCode string `json:"access_code"`
UnionId string `json:"union_id"`
Scope string `json:"scope"` // Google
TokenType string `json:"token_type"` // Google
IdToken string `json:"id_token"` // Google
MacAlgorithm string `json:"mac_algorithm"` // Xiao Mi
MacKey string `json:"mac_key"` // Xiao Mi
Code string `json:"code"` // Work WeChat
SnapshotUser bool `json:"snapshot_user"` // WeChat Official Account - Available for web authorization login
OauthToken string `json:"oauth_token"` // Twitter
OauthTokenSecret string `json:"oauth_token_secret"` // Twitter
UserId string `json:"user_id"` // Twitter
ScreenName string `json:"screen_name"` // Twitter
OauthCallbackConfirmed *bool `json:"oauth_callback_confirmed"` // Twitter
}
type AuthUser ¶
type AuthUser struct {
UID string `json:"uid"`
Username string `json:"username"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
Blog string `json:"blog"`
Company string `json:"company"`
Location string `json:"location"`
Email string `json:"email"`
Remark string `json:"remark"`
Gender AuthUserGender `json:"gender"`
Source string `json:"source"`
Token AuthToken `json:"token"`
RawUserInfo string `json:"raw_user_info"`
SnapshotUser bool `json:"snapshot_user"`
}
type AuthUserGender ¶
type AuthUserGender int8
const ( GenderMale AuthUserGender = 1 GenderFemale AuthUserGender = 0 GenderUnknown AuthUserGender = -1 )
func GetRealGender ¶ added in v0.0.2
func GetRealGender(originalGender string) AuthUserGender
type DefaultAuthRequest ¶
type DefaultAuthRequest struct {
AuthRequest
Source config.AuthSource
// contains filtered or unexported fields
}
func NewDefaultAuthRequest ¶
func NewDefaultAuthRequest(config *config.AuthConfig, source config.AuthSource, authRequest AuthRequest) *DefaultAuthRequest
func (*DefaultAuthRequest) AccessTokenUrl ¶ added in v0.0.3
func (r *DefaultAuthRequest) AccessTokenUrl(code string) string
func (*DefaultAuthRequest) Authorize ¶
func (r *DefaultAuthRequest) Authorize(state string) (string, error)
func (*DefaultAuthRequest) DoPostAuthorizationCode ¶
func (r *DefaultAuthRequest) DoPostAuthorizationCode(code string) (string, error)
func (*DefaultAuthRequest) GetScopes ¶
func (r *DefaultAuthRequest) GetScopes(separator string, encode bool, defaultScopes []string) string
func (*DefaultAuthRequest) Login ¶
func (r *DefaultAuthRequest) Login(callback AuthCallback) (AuthResponse, error)
func (*DefaultAuthRequest) Revoke ¶
func (r *DefaultAuthRequest) Revoke(token AuthToken) error
Source Files
¶
Click to show internal directories.
Click to hide internal directories.