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

chunshand / d3auth
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
outh_gitee.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
chunshand 提交于 2018-12-18 08:46 . 增加码云登录
package d3auth
import (
// "encoding/json"
"encoding/json"
"errors"
// "net/url"
"regexp"
// "strconv"
)
//获取登录地址
func (e *Auth_gitee) Get_Rurl(state string) string {
return "https://gitee.com/oauth/authorize?client_id=" + e.Conf.Appid + "&redirect_uri=" + e.Conf.Rurl + "&response_type=code"
}
//获取token
func (e *Auth_gitee) Get_Token(code string) (*Auth_gitee_succ_res, error) {
str, err := HttpPost("https://gitee.com/oauth/token?grant_type=authorization_code&code=" + code + "&client_id=" + e.Conf.Appid + "&redirect_uri=" + e.Conf.Rurl + "&client_secret=" + e.Conf.Appkey)
if err != nil {
return nil, err
}
ismatch, _ := regexp.MatchString("error", str)
if ismatch {
return nil, errors.New(str)
} else {
p := &Auth_gitee_succ_res{}
err := json.Unmarshal([]byte(str), p)
if err != nil {
return nil, err
}
return p, nil
}
}
//获取第三方用户信息
func (e *Auth_gitee) Get_User_Info(access_token string) (string, error) {
str, err := HttpGet("https://gitee.com/api/v5/user?access_token=" + access_token)
if err != nil {
return "", err
}
return string(str), nil
}
//构造方法
func NewAuth_gitee(config *Auth_conf) *Auth_gitee {
return &Auth_gitee{
Conf: config,
}
}
Go
1
https://gitee.com/chunshand/d3auth.git
git@gitee.com:chunshand/d3auth.git
chunshand
d3auth
d3auth
master

搜索帮助