XOAuth

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2021 License: MIT Imports: 6 Imported by: 0

README

XOAuth Starter

Documentation

Documentation

QQ OAuth2 接口文档 :https://wiki.connect.qq.com/准备工作_oauth2-0

微博 OAuth2 接口文档 :https://open.weibo.com/wiki/Connect/login

微信 OAuth2 接口文档 :https://developers.weixin.qq.com/doc/oplatform/Mobile_App/WeChat_Login/Development_Guide.html

XOAuth Starter Usage
goinfras.RegisterStarter(XOAuth.NewStarter())

XOAuth Config Setting
WechatSignSwitch      bool   // 微信三方登录开关
WechatOAuth2AppKey    string // 微信开发者appkey
WechatOAuth2AppSecret string // 微信开发者secret
WeiboSignSwitch       bool   // 微博三方登录开关
WeiboOAuth2AppKey     string // 微博开发者appkey
WeiboOAuth2AppSecret  string // 微博开发者secret
QQSignSwitch          bool   // qq三方登录开关
QQOAuth2AppKey        string // qq开发者appkey
QQOAuth2AppSecret     string // qq开发者secret
XOAuth Usage

1、qq 登录

// TODO 前端先获取预授权码 qqprecode ...

var qqprecode string
qqOAuthResult := XOAuth.XQQOAuthManager().Authorize(qqprecode)
Println("qqOAuthResult", qqOAuthResult)
// 获取信息后进入登录或注册流程...

2、 微博登录

// TODO 前端先获取预授权码 weiboprecode...
var weiboprecode string
weiboOAuthResult := XOAuth.XWeiboOAuthManager().Authorize(weiboprecode)
Println("weiboOAuthResult", weiboOAuthResult)
// 获取信息后进入登录或注册流程...

3、微信登录

// TODO 前端先获取预授权码 wechatprecode ...
var wechatprecode string
wechatOAuthResult := XOAuth.XWechatOAuthManager().Authorize(wechatprecode)
Println("wechatOAuthResult", wechatOAuthResult)
// 获取信息后进入登录或注册流程...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStarter

func NewStarter() *starter

Types

type Config

type Config struct {
	WechatSignSwitch      bool   // 微信三方登录开关
	WechatOAuth2AppKey    string // 微信开发者appkey
	WechatOAuth2AppSecret string // 微信开发者secret
	WeiboSignSwitch       bool   // 微博三方登录开关
	WeiboOAuth2AppKey     string // 微博开发者appkey
	WeiboOAuth2AppSecret  string // 微博开发者secret
	QQSignSwitch          bool   // qq三方登录开关
	QQOAuth2AppKey        string // qq开发者appkey
	QQOAuth2AppSecret     string // qq开发者secret
}

func DefaultConfig

func DefaultConfig() *Config

type OAuth

type OAuth interface {
	Authorize(code string) OAuthResult // 根据微信返回的accessTokenCode开始鉴权并获取用户信息
	// contains filtered or unexported methods
}

OAuth2服务的通用鉴权接口

type OAuthAccountInfo

type OAuthAccountInfo struct {
	AccessToken string
	OpenId      string
	UnionId     string
	NickName    string
	Gender      uint
	AvatarUrl   string
}

OAuth授权获取的第三方账号信息

type OAuthResult

type OAuthResult struct {
	Result   bool
	UserInfo *OAuthAccountInfo
	Error    error
}

OAuth鉴权结果

type QQOAuthManager

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

实现QQOAuth2鉴权

func NewQQOauthManager

func NewQQOauthManager(cfg *Config) *QQOAuthManager

func XQQOAuthManager

func XQQOAuthManager() *QQOAuthManager

func (*QQOAuthManager) Authorize

func (oauth *QQOAuthManager) Authorize(code string) OAuthResult

通过前端与用户交互获得的预授权码code后,后端再申请accessToken获得第三方用户信息,再进入本服务的登录或注册流程

type WechatOAuthManager

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

实现 微信 OAuth2鉴权

func NewWechatOAuthManager

func NewWechatOAuthManager(cfg *Config) *WechatOAuthManager

func XWechatOAuthManager

func XWechatOAuthManager() *WechatOAuthManager

func (*WechatOAuthManager) Authorize

func (oauth *WechatOAuthManager) Authorize(code string) OAuthResult

通过前端与用户交互获得的预授权码code后,后端再申请accessToken获得第三方用户信息,再进入本服务的登录或注册流程

type WeiboOAuthManager

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

实现微博 OAuth2鉴权

func NewWeiboOAuthManager

func NewWeiboOAuthManager(cfg *Config) *WeiboOAuthManager

func XWeiboOAuthManager

func XWeiboOAuthManager() *WeiboOAuthManager

func (*WeiboOAuthManager) Authorize

func (oauth *WeiboOAuthManager) Authorize(code string) OAuthResult

通过前端与用户交互获得的预授权码code后,后端再申请accessToken获得第三方用户信息,再进入本服务的登录或注册流程

Jump to

Keyboard shortcuts

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