uc

package
v1.3.0-rc.0...-d217119 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const OryCompatibleClientId = "kratos"

Variables

This section is empty.

Functions

func HandlePagingUsers

func HandlePagingUsers(req *apistructs.UserPagingRequest, token OAuthToken) (*common.UserPaging, error)

Types

type Config

type Config struct {
	UCClientID     string `default:"dice" file:"UC_CLIENT_ID"`
	UCClientSecret string `default:"secret" file:"UC_CLIENT_SECRET"`
}

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 Interface

type Interface common.Interface

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

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) (common.UserInfo, error)

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

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

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

User 用户中心用户数据结构

Directories

Path Synopsis
conf
Package conf 配置文件信息
Package conf 配置文件信息
dao
Package dbclient 定义数据库操作的方法, orm 等。
Package dbclient 定义数据库操作的方法, orm 等。
endpoints
Package endpoints API相关的数据信息
Package endpoints API相关的数据信息

Jump to

Keyboard shortcuts

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