Documentation
¶
Index ¶
- Constants
- func ChangeUserState(kratosPrivateAddr string, userID string, state string) error
- func ConvertToUserInfoExt(user *userPaging) *apistructs.UserPagingData
- func CreateUser(req OryKratosRegistrationRequest) error
- func HandlePagingUsers(req *apistructs.UserPagingRequest, token OAuthToken) (*userPaging, error)
- func NewDB() (*gorm.DB, error)
- func UpdateIdentity(kratosPrivateAddr string, userID string, req OryKratosUpdateIdentitiyRequest) error
- type CurrentUser
- type NewClientRequest
- type NewClientResponse
- type OAuthToken
- type OryKratosCreateIdentitiyRequest
- type OryKratosFlowResponse
- type OryKratosFlowResponseUI
- type OryKratosIdentity
- type OryKratosIdentityTraits
- type OryKratosReadyResponse
- type OryKratosRegistrationRequest
- type OryKratosRegistrationResponse
- type OryKratosSession
- type OryKratosUpdateIdentitiyRequest
- type TokenClient
- type UCClient
- func (c *UCClient) ConvertUserIDs(ids []string) ([]string, map[string]string, error)
- func (c *UCClient) FindUsers(ids []string) ([]User, error)
- func (c *UCClient) FindUsersByKey(key string) ([]User, error)
- func (c *UCClient) FuzzSearchUserByName(name string) ([]User, error)
- func (c *UCClient) GetUser(userID string) (*User, error)
- func (c *UCClient) GetUserIDMapping(ids []string) ([]UserIDModel, error)
- func (c *UCClient) InvalidateServerToken()
- func (c *UCClient) MigrationReady() bool
- func (c *UCClient) SetDBClient(db *gorm.DB)
- func (c *UCClient) UserMigration(req OryKratosCreateIdentitiyRequest) (string, error)
- type UCTokenAuth
- type UCUserAuth
- func (a *UCUserAuth) GetCurrentUser(headers http.Header) (UserInfo, error)
- func (a *UCUserAuth) GetUserInfo(oauthToken OAuthToken) (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 USERID
- type UcUser
- type User
- type UserIDModel
- type UserInfo
Constants ¶
const ( UserActive = "active" UserInActive = "inactive" )
const BULK_INSERT_CHUNK_SIZE = 3000
const DIALECT = "mysql"
const OryCompatibleClientId = "kratos"
Variables ¶
This section is empty.
Functions ¶
func ChangeUserState ¶ added in v1.3.0
func ConvertToUserInfoExt ¶
func ConvertToUserInfoExt(user *userPaging) *apistructs.UserPagingData
func CreateUser ¶ added in v1.3.0
func CreateUser(req OryKratosRegistrationRequest) error
func HandlePagingUsers ¶
func HandlePagingUsers(req *apistructs.UserPagingRequest, token OAuthToken) (*userPaging, error)
func UpdateIdentity ¶ added in v1.3.0
func UpdateIdentity(kratosPrivateAddr string, userID string, req OryKratosUpdateIdentitiyRequest) error
Types ¶
type CurrentUser ¶
type CurrentUser struct {
Success bool `json:"success"`
Result struct {
ID USERID `json:"id"`
Email string `json:"email"`
Mobile string `json:"mobile"`
Username string `json:"username"`
Nickname string `json:"nickname"`
} `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 OryKratosCreateIdentitiyRequest ¶ added in v1.3.0
type OryKratosCreateIdentitiyRequest struct {
SchemaID string `json:"schema_id"`
Traits OryKratosIdentityTraits `json:"traits"`
}
type OryKratosFlowResponse ¶ added in v1.3.0
type OryKratosFlowResponse struct {
ID string `json:"id"`
UI OryKratosFlowResponseUI `json:"ui"`
}
type OryKratosFlowResponseUI ¶ added in v1.3.0
type OryKratosFlowResponseUI struct {
Action string `json:"action"`
}
type OryKratosIdentity ¶
type OryKratosIdentity struct {
ID USERID `json:"id"`
SchemaID string `json:"schema_id"`
State string `json:"state"`
Traits OryKratosIdentityTraits `json:"traits"`
}
type OryKratosIdentityTraits ¶
type OryKratosReadyResponse ¶ added in v1.3.0
type OryKratosReadyResponse struct {
Status string `json:"status"`
}
type OryKratosRegistrationRequest ¶ added in v1.3.0
type OryKratosRegistrationRequest struct {
Traits OryKratosIdentityTraits `json:"traits"`
Password string `json:"password"`
Method string `json:"method"`
}
type OryKratosRegistrationResponse ¶ added in v1.3.0
type OryKratosRegistrationResponse struct {
Identity OryKratosIdentity `json:"identity"`
}
type OryKratosSession ¶
type OryKratosSession struct {
ID string `json:"id"`
Active bool `json:"active"`
Identity OryKratosIdentity `json:"identity"`
}
type OryKratosUpdateIdentitiyRequest ¶ added in v1.3.0
type OryKratosUpdateIdentitiyRequest struct {
State string `json:"state"`
Traits OryKratosIdentityTraits `json:"traits"`
}
type TokenClient ¶
type UCClient ¶
type UCClient struct {
// contains filtered or unexported fields
}
UCClient UC客户端\
func NewUCClient ¶
NewUCClient 初始化UC客户端
func (*UCClient) ConvertUserIDs ¶ added in v1.3.0
func (*UCClient) FindUsersByKey ¶
FindUsersByKey 根据key查找用户,key可匹配用户名/邮箱/手机号
func (*UCClient) FuzzSearchUserByName ¶ added in v1.1.0
func (*UCClient) GetUserIDMapping ¶ added in v1.3.0
func (c *UCClient) GetUserIDMapping(ids []string) ([]UserIDModel, error)
func (*UCClient) InvalidateServerToken ¶
func (c *UCClient) InvalidateServerToken()
InvalidateServerToken 使 server token 失效
func (*UCClient) MigrationReady ¶ added in v1.3.0
func (*UCClient) SetDBClient ¶ added in v1.3.0
func (*UCClient) UserMigration ¶ added in v1.3.0
func (c *UCClient) UserMigration(req OryKratosCreateIdentitiyRequest) (string, error)
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 (a *UCUserAuth) GetCurrentUser(headers http.Header) (UserInfo, error)
func (*UCUserAuth) GetUserInfo ¶
func (a *UCUserAuth) GetUserInfo(oauthToken OAuthToken) (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)
type USERID ¶
type USERID string
func (*USERID) UnmarshalJSON ¶
maybe int or string, unmarshal them to string(USERID)
type User ¶
type User struct {
ID string `json:"user_id"`
Name string `json:"username"`
Nick string `json:"nickname"`
AvatarURL string `json:"avatar_url"`
Phone string `json:"phone_number"`
Email string `json:"email"`
State string `json:"state"`
}
User 用户中心用户数据结构
type UserIDModel ¶ added in v1.3.0
type UserInfo ¶
type UserInfo struct {
ID USERID `json:"id"`
Token string `json:"token"`
Email string `json:"email"`
EmailExist bool `json:"emailExist"`
PasswordExist bool `json:"passwordExist"`
PhoneExist bool `json:"phoneExist"`
Birthday string `json:"birthday"`
PasswordStrength int `json:"passwordStrength"`
Phone string `json:"phone"`
AvatarUrl string `json:"avatarUrl"`
UserName string `json:"username"`
NickName string `json:"nickName"`
Enabled bool `json:"enabled"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
LastLoginAt string `json:"lastLoginAt"`
}