-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathouth_gitee.go
59 lines (45 loc) · 1.22 KB
/
outh_gitee.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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,
}
}