Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/phachon/qq-oauth

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/phachon/qq-oauth

  • v0.0.0-20180504022527-be5a8c5dd5e3
  • Source
  • Go
  • Socket score

Version published
Created
Source

qq-OAuth

QQ 第三方登录

功能

实现 QQ OAuth2.0 Open api 封装

示例

// 随机字符串,验证 state 防止 CSRF 攻击
var state = "adadasdad"

// 登录逻辑
func Login(res http.ResponseWriter, req *http.Request) {
	appId := ""
	appSecret := ""
	callback := ""
	scope := "" //多个以 ,号隔开
    // 初始化
	oAuth := NewOAuth(appId, appSecret, callback, scope)
	// 获取授权 URL
	loginUrl := oAuth.GetAuthorURL(state)

    // 跳转至 URL
	http.Redirect(res, req, loginUrl, 302)
}

// 回调逻辑
func Callback(res http.ResponseWriter, req *http.Request)  {
	reqState := req.Form.Get("state")
	if reqState != state {
	    // 防止 CSRF 攻击
		res.Write([]byte("CSRF!!"))
	}

	authCode := req.Form.Get("code")

	appId := ""
	appSecret := ""
	callback := ""
	scope := ""

	oAuth := NewOAuth(appId, appSecret, callback, scope)
	oAuth.Access(authCode)

	userInfo, httpCode, err := oAuth.GetUserInfo()

	// TODO
}

示例:example/http_example.go

License

MIT

Thanks

Create By phachon@163.com

FAQs

Package last updated on 04 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc