auth

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 7 Imported by: 0

README

百度账号授权

  1. 获取OAuth授权url
  2. 获取AccessToken
  3. 刷新AccessToken
  4. 获取授权用户的百度账号信息

Documentation

Overview

百度授权相关,wiki地址 https://openauth.baidu.com/doc/doc.html

Index

Constants

View Source
const OAuthTokenUri = "/oauth/2.0/token"
View Source
const OAuthUri = "/oauth/2.0/authorize"
View Source
const UserInfoUri = "/rest/2.0/passport/users/getInfo"

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessTokenResponse

type AccessTokenResponse struct {
	AccessToken      string `json:"access_token"`
	ExpiresIn        int    `json:"expires_in"`
	RefreshToken     string `json:"refresh_token"`
	Scope            string `json:"scope"`
	SessionKey       string `json:"session_key"`
	SessionSecret    string `json:"session_secret"`
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

type Auth

type Auth struct {
	ClientID     string
	ClientSecret string
}

func NewAuthClient

func NewAuthClient(clientID string, clientSecret string) *Auth

func (*Auth) AccessToken

func (a *Auth) AccessToken(code, redirectUri string) (AccessTokenResponse, error)

获取AccessToken

func (*Auth) OAuthUrl

func (a *Auth) OAuthUrl(redirectUri string) string

获取授权页网址

func (*Auth) RefreshToken

func (a *Auth) RefreshToken(refreshToken string) (RefreshTokenResponse, error)

刷新AccessToken

func (*Auth) UserInfo

func (a *Auth) UserInfo(accessToken string) (UserInfoResponse, error)

获取授权用户的百度账号信息,可以通过unionid字段来识别多个百度产品授权的是否是同一用户 注:获取网盘账号信息请使用account.UserInfo方法

type RefreshTokenResponse

type RefreshTokenResponse struct {
	AccessToken      string `json:"access_token"`
	ExpiresIn        int    `json:"expires_in"`
	RefreshToken     string `json:"refresh_token"`
	Scope            string `json:"scope"`
	SessionKey       string `json:"session_key"`
	SessionSecret    string `json:"session_secret"`
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

type UserInfoResponse

type UserInfoResponse struct {
	OpenID       string `json:"openid"`
	UnionID      string `json:"unionid"` // 百度用户统一标识,对当前开发者帐号唯一
	UserID       string `json:"userid"`  // 老版百度用户的唯一标识,后续不在返回该字段,user_id字段对应account.UserInfo方法返回的uk
	UserName     string `json:"username"`
	SecureMobile int    `json:"securemobile"` // 当前用户绑定手机号,需要向百度开放平台单独申请权限
	Portrait     string `json:"portrait"`
	UserDetail   string `json:"userdetail"`
	Birthday     string `json:"birthday"`
	Marriage     string `json:"marriage"`
	Sex          string `json:"sex"`
	Blood        string `json:"blood"`
	IsBindMobile string `json:"is_bind_mobile"`
	IsRealName   string `json:"is_realname"`
	ErrorCode    int    `json:"errno"`
	ErrorMsg     string `json:"errmsg"`
}

Jump to

Keyboard shortcuts

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