当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 15

lorock / d3auth
暂停

forked from chunshand / d3auth
暂停
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
outh_github.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
chunshand 提交于 2018-12-12 15:22 . 更新变量名问题错误
package d3auth
import (
// "encoding/json"
"errors" // "fmt"
// "net/url"
"regexp"
// "strconv"
)
//获取登录地址
func (e *Auth_github) Get_Rurl(state string) string {
return "https://github.com/login/oauth/authorize?client_id=" + e.Conf.Appid + "&redirect_uri=" + e.Conf.Rurl + "&state=" + state
}
//获取token
func (e *Auth_github) Get_Token(code string) (string, error) {
str, err := HttpGet("https://github.com/login/oauth/access_token?client_id=" + e.Conf.Appid + "&client_secret=" + e.Conf.Appkey + "&code=" + code + "&redirect_uri=" + e.Conf.Rurl)
if err != nil {
return "", err
}
ismatch, _ := regexp.MatchString("error", str)
if ismatch {
return "", errors.New(str)
} else {
re, _ := regexp.Compile("access_token=(.*)&scope")
newres := re.FindStringSubmatch(str)
if len(newres) >= 2 {
return newres[1], nil
}
return "", nil
}
}
//获取第三方用户信息
func (e *Auth_github) Get_User_Info(access_token string) (string, error) {
str, err := HttpGet("https://api.github.com/user?access_token=" + access_token)
if err != nil {
return "", err
}
return string(str), nil
}
//构造方法
func NewAuth_github(config *Auth_conf) *Auth_github {
return &Auth_github{
Conf: config,
}
}
Go
1
https://gitee.com/lorock/d3auth.git
git@gitee.com:lorock/d3auth.git
lorock
d3auth
d3auth
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891