auth

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Unauthed        = http.StatusUnauthorized
	AuthFail        = http.StatusForbidden
	InternalAuthErr = http.StatusInternalServerError
	AuthSucc        = http.StatusOK
)
View Source
const (
	HeaderAuthorization             = "Authorization"
	HeaderAuthorizationBearerPrefix = "Bearer "
)
View Source
const (
	LOGIN checkType = iota
	TRY_LOGIN
	BASICAUTH
	TOKEN
	NONE
)
View Source
const (
	CtxKeyOauth2JwtKeyPayload = "oauth2-jwt-token-payload"
)
View Source
const (
	SessionExpireDays = 5
)

Variables

View Source
var (
	ErrNotExist = errors.New("session not exist")
)

Functions

func GetDiceClientToken

func GetDiceClientToken() (ucauth.OAuthToken, error)

获取 dice 自己的token

func MkSessionKey

func MkSessionKey(sessionID string) string

func VerifyUCClientToken

func VerifyUCClientToken(token string) (ucauth.TokenClient, error)

@return example: {"id":7,"userId":null,"clientId":"dice-test","clientName":"dice测试应用","clientLogoUrl":null,"clientSecret":null,"autoApprove":false,"scope":["public_profile","email"],"resourceIds":["shinda-maru"],"authorizedGrantTypes":["client_credentials"],"registeredRedirectUris":[],"autoApproveScopes":[],"authorities":["ROLE_CLIENT"],"accessTokenValiditySeconds":433200,"refreshTokenValiditySeconds":433200,"additionalInformation":{}}

Types

type Auth

type Auth struct {
	RedisCli     *redis.Client
	OAuth2Server *oauth2.OAuth2Server
}

func NewAuth

func NewAuth(oauth2server *oauth2.OAuth2Server) (*Auth, error)

func (*Auth) Auth

func (a *Auth) Auth(spec *spec.Spec, req *http.Request) AuthResult

type AuthResult

type AuthResult struct {
	Code   int
	Detail string
}

type GetUserState

type GetUserState int
const (
	GetInit GetUserState = iota
	GotSessionID
	GotToken
	GotInfo
	GotScopeInfo
)

type OAuth2APISpec added in v1.5.0

type OAuth2APISpec interface {
	MatchPath(path string) bool
	PathVars(temp, path string) map[string]string
	Method() string
	Scheme() string
}

OAuth2APISpec .

type OpenapiSpec added in v1.5.0

type OpenapiSpec struct {
	*spec.Spec
}

OpenapiSpec .

func (*OpenapiSpec) MatchPath added in v1.5.0

func (s *OpenapiSpec) MatchPath(path string) bool

func (*OpenapiSpec) Method added in v1.5.0

func (s *OpenapiSpec) Method() string

func (*OpenapiSpec) PathVars added in v1.5.0

func (s *OpenapiSpec) PathVars(template, path string) map[string]string

func (*OpenapiSpec) Scheme added in v1.5.0

func (s *OpenapiSpec) Scheme() string

type ScopeInfo

type ScopeInfo struct {
	OrgID uint64 `json:"orgId"`
}

type SetUserState

type SetUserState int
const (
	SetInit SetUserState = iota
	SetSessionID
)

type TokenClient

type TokenClient struct {
	ClientID   string
	ClientName string
}

func VerifyOpenapiOAuth2Token

func VerifyOpenapiOAuth2Token(o *oauth2.OAuth2Server, spec OAuth2APISpec, r *http.Request) (TokenClient, error)

type User

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

func NewUser

func NewUser(redisCli *redis.Client) *User

func (*User) GetInfo

func (u *User) GetInfo(req *http.Request) (ucauth.UserInfo, AuthResult)

获取用户信息

func (*User) GetScopeInfo

func (u *User) GetScopeInfo(req *http.Request) (ScopeInfo, AuthResult)

获取用户orgID

func (*User) IsLogin

func (u *User) IsLogin(req *http.Request) AuthResult

func (*User) Login

func (u *User) Login(uccode string, redirectURI string) (string, int, error)

return (token, expiredays, err)

func (*User) Logout

func (u *User) Logout(req *http.Request) error

func (*User) PwdLogin

func (u *User) PwdLogin(username, password string) (string, error)

Jump to

Keyboard shortcuts

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