ucauth

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const OryCompatibleClientId = "kratos"

Variables

This section is empty.

Functions

func ConvertToUserInfoExt

func ConvertToUserInfoExt(user *userPaging) *apistructs.UserPagingData

func HandlePagingUsers

func HandlePagingUsers(req *apistructs.UserPagingRequest, token OAuthToken) (*userPaging, 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 OryKratosIdentity

type OryKratosIdentity struct {
	ID       USERID                  `json:"id"`
	SchemaID string                  `json:"schema_id"`
	Traits   OryKratosIdentityTraits `json:"traits"`
}

type OryKratosIdentityTraits

type OryKratosIdentityTraits struct {
	Email string                      `json:"email"`
	Name  OryKratosIdentityTraitsName `json:"name"`
}

type OryKratosIdentityTraitsName

type OryKratosIdentityTraitsName struct {
	First string `json:"first"`
	Last  string `json:"last"`
}

type OryKratosSession

type OryKratosSession struct {
	ID       string            `json:"id"`
	Active   bool              `json:"active"`
	Identity OryKratosIdentity `json:"identity"`
}

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

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

GetUser 获取用户详情

func (*UCClient) InvalidateServerToken

func (c *UCClient) InvalidateServerToken()

InvalidateServerToken 使 server token 失效

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
}

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

User 用户中心用户数据结构

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