获取accessToken
(code string)
| 33 | |
| 34 | //获取accessToken |
| 35 | func GetGithubAccessToken(code string) (token GithubAccessToken, err error) { |
| 36 | var resp string |
| 37 | Api := beego.AppConfig.String("oauth::githubAccesstoken") |
| 38 | ClientId := beego.AppConfig.String("oauth::githubClientId") |
| 39 | ClientSecret := beego.AppConfig.String("oauth::githubClientSecret") |
| 40 | Callback := beego.AppConfig.String("oauth::githubCallback") |
| 41 | req := httplib.Post(Api) |
| 42 | req.Header("Accept", "application/json") |
| 43 | if strings.HasPrefix(Api, "https") { |
| 44 | req.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true}) |
| 45 | } |
| 46 | req.Param("code", code) |
| 47 | req.Param("client_id", ClientId) |
| 48 | req.Param("redirect_uri", Callback) |
| 49 | req.Param("client_secret", ClientSecret) |
| 50 | if resp, err = req.String(); err == nil { |
| 51 | err = json.Unmarshal([]byte(resp), &token) |
| 52 | } |
| 53 | return |
| 54 | } |
| 55 | |
| 56 | //获取用户信息 |
| 57 | func GetGithubUserInfo(accessToken string) (info GithubUser, err error) { |