Documentation ¶
Index ¶
- Constants
- func HandlePagingUsers(req *apistructs.UserPagingRequest, token OAuthToken) (*common.UserPaging, error)
- type Config
- type CurrentUser
- type Interface
- type NewClientRequest
- type NewClientResponse
- type OAuthToken
- type TokenClient
- type UCTokenAuth
- type UCUserAuth
- func (a *UCUserAuth) GetCurrentUser(headers http.Header) (common.UserInfo, error)
- func (a *UCUserAuth) GetUserInfo(oauthToken OAuthToken) (common.UserInfo, error)
- func (a *UCUserAuth) Login(uccode string) (OAuthToken, error)
- func (a *UCUserAuth) LoginURL(https bool) string
- func (a *UCUserAuth) PwdAuth(username, password string) (OAuthToken, error)
- type UcUser
Constants ¶
const OryCompatibleClientId = "kratos"
Variables ¶
This section is empty.
Functions ¶
func HandlePagingUsers ¶
func HandlePagingUsers(req *apistructs.UserPagingRequest, token OAuthToken) (*common.UserPaging, error)
Types ¶
type CurrentUser ¶
type CurrentUser struct { Success bool `json:"success"` Result struct { ID common.USERID `json:"id"` Email string `json:"email"` Mobile string `json:"mobile"` Username string `json:"username"` Nickname string `json:"nickname"` LastLoginAt uint64 `json:"lastLoginAt"` } `json:"result"` Error interface{} `json:"error"` }
{ "success": true, "result": { "id": 1000530, "tenantId": 1, "username": "u191-1019703192", "nickname": "", "avatar": "", "prefix": "86", "mobile": "15950552810", "email": "", "pwdExpireAt": null, "passwordExist": true, "enabled": true, "locked": false, "channel": "", "channelType": "", "source": "", "sourceType": "", "tag": "", "extra": null, "userDetail": null, "createdAt": "2020-09-21T09:11:26.000+0000", "updatedAt": "2020-12-15T04:01:02.000+0000", "lastLoginAt": "2020-12-15T04:01:02.000+0000", "pk": 1307970680503390208 }, "code": null, "args": null, "error": null, "sourceIp": null, "sourceStack": null }
type NewClientRequest ¶
type NewClientRequest struct { AccessTokenValiditySeconds int64 `json:"accessTokenValiditySeconds"` AutoApprove bool `json:"autoApprove"` ClientID string `json:"clientId"` ClientLogoUrl string `json:"clientLogoUrl"` ClientName string `json:"clientName"` ClientSecret string `json:"clientSecret"` RefreshTokenValiditySeconds int64 `json:"refreshTokenValiditySeconds"` UserID json.RawMessage `json:"userId"` }
{ "accessTokenValiditySeconds": 433200, "autoApprove": false, "clientId": "testId", "clientLogoUrl": "http://123.com ", "clientName": "测试应用", "clientSecret": "secret", "refreshTokenValiditySeconds": 433200, "userId": 1 }
type NewClientResponse ¶
type NewClientResponse struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` RefreshToken string `json:"refresh_token"` ExpiresIn int64 `json:"expires_in"` Scope string `json:"scope"` Jti string `json:"jti"` }
{"access_token":"xxx","token_type":"bearer","refresh_token":"","expires_in":433199,"scope":"public_profile email","jti":"xxx"}
type OAuthToken ¶
type OAuthToken struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` RefreshToken string `json:"refresh_token"` ExpiresIn int `json:"expires_in"` Scope string `json:"scope"` Jti string `json:"jti"` }
func GenClientToken ¶
func GenClientToken(uchost, basic string) (OAuthToken, error)
type TokenClient ¶
type UCTokenAuth ¶
type UCTokenAuth struct { UCHost string ClientID string // server端的clientID ClientSecret string // server端的client secret // contains filtered or unexported fields }
func NewUCTokenAuth ¶
func NewUCTokenAuth(UCHost, ClientID, ClientSecret string) (*UCTokenAuth, error)
假设 openapi 要使用第三方client token验证 这里 openapi 是 server 第三方程序是 client
1. openapi先获取token (servertoken) 2. 创建client (NewClient) 3. 根据创建的client生成 clienttoken
func (*UCTokenAuth) Auth ¶
func (a *UCTokenAuth) Auth(token string) (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":{}}
func (*UCTokenAuth) ExpireServerToken ¶
func (a *UCTokenAuth) ExpireServerToken()
ExpireServerToken 使 serverToken 过期
func (*UCTokenAuth) GetServerToken ¶
func (a *UCTokenAuth) GetServerToken(refresh bool) (OAuthToken, error)
func (*UCTokenAuth) NewClient ¶
func (a *UCTokenAuth) NewClient(req *NewClientRequest) (*NewClientResponse, error)
type UCUserAuth ¶
type UCUserAuth struct { UCHostFront string UCHost string RedirectURI string ClientID string ClientSecret string // contains filtered or unexported fields }
func NewUCUserAuth ¶
func NewUCUserAuth(UCHostFront, UCHost, RedirectURI, ClientID, ClientSecret string) *UCUserAuth
func (*UCUserAuth) GetCurrentUser ¶
func (*UCUserAuth) GetUserInfo ¶
func (a *UCUserAuth) GetUserInfo(oauthToken OAuthToken) (common.UserInfo, error)
func (*UCUserAuth) Login ¶
func (a *UCUserAuth) Login(uccode string) (OAuthToken, error)
(登陆) 从uc回调回来,会有uccode,用于得到token
func (*UCUserAuth) LoginURL ¶
func (a *UCUserAuth) LoginURL(https bool) string
返回用户中心的登陆URL, 也就是浏览器请求的地址 http://uc.terminus.io/oauth/authorize?response_type=code&client_id=dice&redirect_uri=http%3A%2F%2Fopenapi.test.terminus.io%2Flogincb&scope=public_profile
func (*UCUserAuth) PwdAuth ¶
func (a *UCUserAuth) PwdAuth(username, password string) (OAuthToken, error)