Merge branch 'master' of 10.10.14.250:huanghai/dsMin

master
wubin 5 years ago
commit b9ccdddda0

@ -0,0 +1,4 @@
package Const
//整数最大值
const Int32Max = 2147483647

@ -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"
@ -36,6 +40,9 @@ func Routers(r *gin.RouterGroup) {
r.GET("/getCaptcha", getCaptcha)
//获取验证码图片
r.GET("/getCaptchaPng", getCaptchaPng)
//退出接口
r.GET("/logout", logout)
r.POST("/logout", logout)
return
}
@ -392,3 +399,39 @@ func authorizeGet(context *gin.Context) {
url := "/sso/static/index.html?redirect_uri=" + redirectUri + "&response_type=code&client_id=" + paraClientId + "&oauth_callback=" + oauthCallback
context.Redirect(302, url)
}
// @Summary 退出统一认证
// @Description 退出统一认证
// @Tags 登录验证类
// @Accept application/x-www-form-urlencoded
// @Produce json
// @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})
}

@ -10,6 +10,7 @@ import (
"dsSso/Utils/LogUtil"
"dsSso/models"
"fmt"
"time"
)
var loginModel Model.Selector
@ -97,6 +98,7 @@ func WriteLoginLog(identityId string, personId string, ip string, loginState int
tLog.IpAddress = ip
tLog.LoginName = loginName
tLog.LoginState = int32(loginState)
tLog.LoginTime = time.Now()
_, err := db.Insert(tLog)
if err != nil {
fmt.Println(err.Error())

@ -61,6 +61,6 @@ func ReadSsoCookie(c *gin.Context) string {
2020-02-22
*/
func deleteSsoCookie(c *gin.Context) {
func DeleteSsoCookie(c *gin.Context) {
c.SetCookie(ConfigUtil.AccessToken, "", -1, "/", "", false, true)
}

@ -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": "增加一条接入系统的记录",

@ -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": "增加一条接入系统的记录",

@ -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:

Loading…
Cancel
Save