Ai
13 Star 25 Fork 28

openEuler/ci-bot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
oauth.go 1006 Bytes
一键复制 编辑 原始数据 按行查看 历史
xwzQmxx 提交于 2020-11-09 09:49 +08:00 . fix issue I224AJJ
package cibot
import (
"context"
"fmt"
"github.com/golang/glog"
"os"
"strings"
"golang.org/x/oauth2"
)
func GetToken(code string) (*oauth2.Token, error) {
url := os.Getenv("WEBSITE_URL")
if url == "" {
url = "https://openeuler.org"
}
secret := os.Getenv("GITEE_OAUTH2_SECRET")
client := os.Getenv("GITEE_OAUTH2_CLIENT_CODE")
if !strings.HasSuffix(url, "/") {
url = fmt.Sprintf("%s/", url)
}
redirect := fmt.Sprintf("%scla", strings.TrimSpace(url))
ctx := context.Background()
config := Setup(client, redirect, secret)
glog.Infof("Token request config, code: %s", code)
return config.Exchange(ctx, code)
}
var Endpoint = oauth2.Endpoint{
AuthURL: "https://gitee.com/oauth/authorize",
TokenURL: "https://gitee.com/oauth/token",
}
func Setup(client, redirect, secret string) *oauth2.Config {
return &oauth2.Config{
ClientID: client,
ClientSecret: secret,
Scopes: []string{"emails", "user_info"},
Endpoint: Endpoint,
RedirectURL: redirect,
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/openeuler/ci-bot.git
git@gitee.com:openeuler/ci-bot.git
openeuler
ci-bot
ci-bot
e91f82195b70

搜索帮助