auth

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: AGPL-3.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 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 *spec.Spec, 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, spec *apispec.Spec) 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