diff --git a/api/oauth_api/gitee_api.go b/api/oauth_api/gitee_api.go index 73aec97..bb0ac0b 100644 --- a/api/oauth_api/gitee_api.go +++ b/api/oauth_api/gitee_api.go @@ -50,6 +50,12 @@ type GiteeUser struct { } // GetGiteeRedirectUrl 获取Gitee登录地址 +// @Summary 获取Gitee登录地址 +// @Description 获取Gitee登录地址 +// @Tags OAuth +// @Produce json +// @Success 200 {string} string "登录地址" +// @Router /api/oauth/gitee/get_url [get] func (OAuthAPI) GetGiteeRedirectUrl(c *gin.Context) { clientID := global.CONFIG.OAuth.Gitee.ClientID redirectURI := global.CONFIG.OAuth.Gitee.RedirectURI @@ -123,6 +129,11 @@ func GetGiteeUserInfo(token *Token) (map[string]interface{}, error) { } // GiteeCallback 处理Gitee回调 +// @Summary 处理Gitee回调 +// @Description 处理Gitee回调 +// @Tags OAuth +// @Produce json +// @Router /api/oauth/gitee/callback [get] func (OAuthAPI) GiteeCallback(c *gin.Context) { var err error // 获取 code diff --git a/api/oauth_api/github_api.go b/api/oauth_api/github_api.go index e0658a6..b222f33 100644 --- a/api/oauth_api/github_api.go +++ b/api/oauth_api/github_api.go @@ -16,9 +16,6 @@ import ( "strconv" ) -type Token struct { - AccessToken string `json:"access_token"` -} type GitHubUser struct { AvatarURL string `json:"avatar_url"` Bio interface{} `json:"bio"` @@ -56,10 +53,17 @@ type GitHubUser struct { } // GetRedirectUrl 获取github登录url +// @Summary 获取github登录url +// @Description 获取github登录url +// @Tags OAuth +// @Produce json +// @Success 200 {string} string "登录url" +// @Router /api/oauth/github/get_url [get] func (OAuthAPI) GetRedirectUrl(c *gin.Context) { + state := c.Query("state") clientId := global.CONFIG.OAuth.Github.ClientID redirectUrl := global.CONFIG.OAuth.Github.RedirectURI - url := "https://github.com/login/oauth/authorize?client_id=" + clientId + "&redirect_uri=" + redirectUrl + url := "https://github.com/login/oauth/authorize?client_id=" + clientId + "&redirect_uri=" + redirectUrl + "&state=" + state result.OkWithData(url, c) return } @@ -129,6 +133,13 @@ func GetUserInfo(token *Token) (map[string]interface{}, error) { } // Callback 登录回调函数 +// @Summary 登录回调函数 +// @Description 登录回调函数 +// @Tags OAuth +// @Produce json +// @Param code query string true "code" +// @Success 200 {string} string "登录成功" +// @Router /api/oauth/github/callback [get] func (OAuthAPI) Callback(c *gin.Context) { var err error // 获取 code diff --git a/api/oauth_api/oauth.go b/api/oauth_api/oauth.go index 9b5a494..5b21d14 100644 --- a/api/oauth_api/oauth.go +++ b/api/oauth_api/oauth.go @@ -20,6 +20,10 @@ var rolePermissionService = service.Service.RolePermissionService var permissionServiceService = service.Service.PermissionService var roleService = service.Service.RoleService +type Token struct { + AccessToken string `json:"access_token"` +} + var script = `