ucauth

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserActive   = "active"
	UserInActive = "inactive"
)
View Source
const BULK_INSERT_CHUNK_SIZE = 3000
View Source
const DIALECT = "mysql"
View Source
const OryCompatibleClientId = "kratos"

Variables

This section is empty.

Functions

func ChangeUserState added in v1.3.0

func ChangeUserState(kratosPrivateAddr string, userID string, state string) error

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 NewDB added in v1.3.0

func NewDB() (*gorm.DB, 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 OryKratosIdentityTraits struct {
	Email  string `json:"email"`
	Name   string `json:"username"`
	Nick   string `json:"nickname"`
	Phone  string `json:"phone"`
	Avatar string `json:"avatar"`
}

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 TokenClient struct {
	ID         int    `json:"id"`
	ClientID   string `json:"clientId"`
	ClientName string `json:"clientName"`
}

type UCClient

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

UCClient UC客户端\

func NewUCClient

func NewUCClient(baseURL, clientID, clientSecret string) *UCClient

NewUCClient 初始化UC客户端

func (*UCClient) ConvertUserIDs added in v1.3.0

func (c *UCClient) ConvertUserIDs(ids []string) ([]string, map[string]string, error)

func (*UCClient) FindUsers

func (c *UCClient) FindUsers(ids []string) ([]User, error)

FindUsers 根据用户ID查找用户信息

func (*UCClient) FindUsersByKey

func (c *UCClient) FindUsersByKey(key string) ([]User, error)

FindUsersByKey 根据key查找用户,key可匹配用户名/邮箱/手机号

func (*UCClient) FuzzSearchUserByName added in v1.1.0

func (c *UCClient) FuzzSearchUserByName(name string) ([]User, error)

func (*UCClient) GetUser

func (c *UCClient) GetUser(userID string) (*User, error)

GetUser 获取用户详情

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 (c *UCClient) MigrationReady() bool

func (*UCClient) SetDBClient added in v1.3.0

func (c *UCClient) SetDBClient(db *gorm.DB)

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) PwdAuth

func (a *UCUserAuth) PwdAuth(username, password string) (OAuthToken, error)

type USERID

type USERID string

func (*USERID) UnmarshalJSON

func (u *USERID) UnmarshalJSON(b []byte) error

maybe int or string, unmarshal them to string(USERID)

type UcUser

type UcUser struct {
	ID        int    `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"`
}

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 UserIDModel struct {
	ID     string
	UserID string
}

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"`
}

Jump to

Keyboard shortcuts

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