d3auth

package module
v0.0.0-...-e9c0fdc Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

d3auth

第三方登录golang版本的简单实现

安装

go get gitee.com/liqp1992/d3auth

GoDoc

emmm

		type Auth_conf struct {
			Appid  string
			Appkey string
			Rurl   string
		}

使用

gitee


	giteeconf := &d3auth.Auth_conf{Appid: "xxx", Appkey: "xxx", Rurl: "http://www.oschina.net/login"}

	giteeAuth := d3auth.NewAuth_gitee(giteeconf)

	fmt.Print(giteeAuth.Get_Rurl("state")) //获取第三方登录地址

	token, err := giteeAuth.Get_Token("3ce778954a27dd95e46e999667353ac4b780d50fa987d8646a534ac820b02c13") //回调页收的code 获取token
	fmt.Print(token, err)                                                                                 
	userinfo, _ := giteeAuth.Get_User_Info(token.Access_Token)                                            //获取用户信息 userinfo 是一个json字符串返回
	fmt.Print(userinfo)


qq

		qqconf := &d3auth.Auth_conf{Appid: "xxx", Appkey: "xxx", Rurl: "http://www.change.tm"}

		qqAuth := d3auth.NewAuth_qq(qqconf)

		fmt.Print(qqAuth.Get_Rurl("state")) //获取第三方登录地址

		token, err := qqAuth.Get_Token("code")  //回调页收的code 获取token


		me, err := qqAuth.Get_Me(token)  //获取第三方id

		Client_ID string `json:"client_id"`
		OpenID    string `json:"openid"`

		userinfo, _ := wbAuth.Get_User_Info(token, me.OpenID)  //获取用户信息 userinfo 是一个json字符串返回

weibo

		wbconf := &d3auth.Auth_conf{Appid: "xxx", Appkey: "xxx", Rurl: "http://www.change.tm"}

		wbAuth := d3auth.NewAuth_wb(wbconf)

		fmt.Print(wbAuth.Get_Rurl("state")) //获取第三方登录地址


		tokenobj, err := wbAuth.Get_Token("code")

		Access_Token string `json:"access_token"`
		Openid       string `json:"uid"`

		userinfo, _ := wbAuth.Get_User_Info(tokenobj.Access_Token, tokenobj.Openid)//获取用户信息 userinfo 是一个json字符串返回

wechat

		wxconf := &d3auth.Auth_conf{Appid: "xxx", Appkey: "xxx", Rurl: "http://www.change.tm"}

		wxAuth := d3auth.NewAuth_wx(wxconf)

		fmt.Print(wxAuth.Get_Rurl("sate")) //获取第三方登录地址

		wxres, err := wxAuth.Get_Token("code")

		userinfo, _ := wxAuth.Get_User_Info(wxres.Access_Token, wxres.Openid) //获取用户信息 userinfo 是一个json字符串返回

github

		githubconf := &d3auth.Auth_conf{Appid: "xxx", Appkey: "xxx", Rurl: "http://www.change.tm/D3/d3_code/type/github"}

		githubAuth := d3auth.NewAuth_github(githubconf)

		fmt.Print(githubAuth.Get_Rurl("state"), "\r\n") //获取第三方登录地址

		token, err := githubAuth.Get_Token("6d92d879d8b1a86922a9") //回调页收的code 获取token
		if err != nil {
			fmt.Print(err, "\r\n")
			return
		}

		userinfo, err := githubAuth.Get_User_Info(token) //获取用户信息 userinfo 是一个json字符串返回
		if err != nil {
			fmt.Print(err)
		}

		fmt.Print(userinfo)	

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HttpGet

func HttpGet(geturl string) (string, error)

func HttpPost

func HttpPost(geturl string, reqData map[string]interface{}) (string, error)

Types

type Auth_conf

type Auth_conf struct {
	Appid  string
	Appkey string
	Rurl   string
}

基本配置

type Auth_gitee

type Auth_gitee struct {
	Conf *Auth_conf
}

type Auth_gitee_err_res

type Auth_gitee_err_res struct {
	Error             int    `json:"errcode"`
	Error_description string `json:"errmsg"`
}

type Auth_gitee_succ_res

type Auth_gitee_succ_res struct {
	Access_Token string `json:"access_token"`
}

type Auth_github

type Auth_github struct {
	Conf *Auth_conf
}

func NewAuth_github

func NewAuth_github(config *Auth_conf) *Auth_github

构造方法

func (*Auth_github) Get_Rurl

func (e *Auth_github) Get_Rurl(state string) string

获取登录地址

func (*Auth_github) Get_User_Info

func (e *Auth_github) Get_User_Info(access_token string) (string, error)

获取第三方用户信息

func (*Auth_github) Post_Token

func (e *Auth_github) Post_Token(code string) (string, error)

获取token

type Auth_github_err_res

type Auth_github_err_res struct {
	Error             int    `json:"errcode"`
	Error_description string `json:"errmsg"`
}

type Auth_github_succ_res

type Auth_github_succ_res struct {
	Access_Token string `json:"access_token"`
	Openid       string `json:"openid"`
}

type Auth_qq

type Auth_qq struct {
	Conf *Auth_conf
}

type Auth_qq_err_res

type Auth_qq_err_res struct {
	Error             int    `json:"error"`
	Error_description string `json:"error_description"`
}

type Auth_qq_me

type Auth_qq_me struct {
	Client_ID string `json:"client_id"`
	OpenID    string `json:"openid"`
}

type Auth_wb

type Auth_wb struct {
	Conf *Auth_conf
}

type Auth_wb_err_res

type Auth_wb_err_res struct {
	Error             int    `json:"error_code"`
	Error_description string `json:"error"`
}

type Auth_wb_succ_res

type Auth_wb_succ_res struct {
	Access_Token string `json:"access_token"`
	Openid       string `json:"uid"`
}

type Auth_wx

type Auth_wx struct {
	Conf *Auth_conf
}

func NewAuth_wx

func NewAuth_wx(config *Auth_conf) *Auth_wx

构造方法

func (*Auth_wx) Get_Rurl

func (e *Auth_wx) Get_Rurl(state string) string

获取登录地址

func (*Auth_wx) Get_Token

func (e *Auth_wx) Get_Token(code string) (*Auth_wx_succ_res, error)

获取token

func (*Auth_wx) Get_User_Info

func (e *Auth_wx) Get_User_Info(access_token string, openid string) (*Auth_wx_user_info_res, error)

获取第三方用户信息

type Auth_wx_err_res

type Auth_wx_err_res struct {
	Error             int    `json:"errcode"`
	Error_description string `json:"errmsg"`
}

type Auth_wx_succ_res

type Auth_wx_succ_res struct {
	Access_Token string `json:"access_token"`
	Openid       string `json:"openid"`
}

type Auth_wx_user_info_res

type Auth_wx_user_info_res struct {
	Openid     string   `json:"openid"`
	Nickname   string   `json:"nickname"`
	Sex        int      `json:"sex"`
	Province   string   `json:"province"`
	City       string   `json:"city"`
	Country    string   `json:"country"`
	Headimgurl string   `json:"headimgurl"`
	Privilege  []string `json:"privilege"`
	Unionid    string   `json:"unionid"`
}

Jump to

Keyboard shortcuts

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