diff --git a/dsSso/Const/Const.go b/dsSso/Const/Const.go new file mode 100644 index 00000000..ec5c539f --- /dev/null +++ b/dsSso/Const/Const.go @@ -0,0 +1,4 @@ +package Const + +//整数最大值 +const Int32Max = 2147483647 diff --git a/dsSso/Controller/ControllerOauth2/ControllerOauth2.go b/dsSso/Controller/ControllerOauth2/ControllerOauth2.go index 756e55a0..1f36874d 100644 --- a/dsSso/Controller/ControllerOauth2/ControllerOauth2.go +++ b/dsSso/Controller/ControllerOauth2/ControllerOauth2.go @@ -1,9 +1,11 @@ package ControllerOauth2 import ( + "dsSso/Const" "dsSso/Const/DefaultConst" "dsSso/Controller/ControllerRecaptcha" "dsSso/Model" + "dsSso/Service/ServiceJoinApp" "dsSso/Service/ServiceLoginPerson" "dsSso/Utils/AesUtil" "dsSso/Utils/CommonUtil" @@ -15,8 +17,10 @@ import ( "dsSso/Utils/SsoUtil" "encoding/base64" "encoding/json" + "fmt" "github.com/dchest/captcha" "github.com/gin-gonic/gin" + "io/ioutil" "net/http" "strconv" "strings" @@ -404,6 +408,29 @@ func authorizeGet(context *gin.Context) { // @Success 200 {string} string // @Router /oauth2/logout [get] func logout(context *gin.Context) { + //取出现在的cookie中的accessToken + accessToken := SsoUtil.ReadSsoCookie(context) + //获取所有接入系统的 + list, _ := ServiceJoinApp.GetJoinAppList(1, Const.Int32Max, "") + for i := range list { + //每个系统的退出地址 + logoutUri := list[i]["logout_uri"].(string) + //如果注册了退出地址的话 + if len(logoutUri) > 0 { + //开启协程进行调用 + go func() { + resp, err := http.Get(logoutUri + "?access_token=" + accessToken) + if err != nil { + fmt.Println(err) + return + } + defer resp.Body.Close() + body, _ := ioutil.ReadAll(resp.Body) + fmt.Println(string(body)) + }() + } + } + //清除cookie SsoUtil.DeleteSsoCookie(context) msg := "统一认证退出成功!" context.JSON(http.StatusOK, map[string]interface{}{"success": false, "msg": msg}) diff --git a/dsSso/docs/docs.go b/dsSso/docs/docs.go index 42e7c632..220884c4 100644 --- a/dsSso/docs/docs.go +++ b/dsSso/docs/docs.go @@ -260,6 +260,29 @@ var doc = `{ ] } }, + "/oauth2/logout": { + "get": { + "description": "退出统一认证", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "登录验证类" + ], + "summary": "退出统一认证", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, "/sso/addJoinApp": { "post": { "description": "增加一条接入系统的记录", diff --git a/dsSso/docs/swagger.json b/dsSso/docs/swagger.json index 65c7e177..c65b14e6 100644 --- a/dsSso/docs/swagger.json +++ b/dsSso/docs/swagger.json @@ -244,6 +244,29 @@ ] } }, + "/oauth2/logout": { + "get": { + "description": "退出统一认证", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "登录验证类" + ], + "summary": "退出统一认证", + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, "/sso/addJoinApp": { "post": { "description": "增加一条接入系统的记录", diff --git a/dsSso/docs/swagger.yaml b/dsSso/docs/swagger.yaml index d2c425aa..778bfc05 100644 --- a/dsSso/docs/swagger.yaml +++ b/dsSso/docs/swagger.yaml @@ -198,6 +198,21 @@ paths: - 登录验证类 x-lengthlimit: - captchaId: 20,20 + /oauth2/logout: + get: + consumes: + - application/x-www-form-urlencoded + description: 退出统一认证 + produces: + - application/json + responses: + "200": + description: OK + schema: + type: string + summary: 退出统一认证 + tags: + - 登录验证类 /sso/addJoinApp: post: consumes: