From 59e603062a414efcb04ec0090bcad5858ab6f01b Mon Sep 17 00:00:00 2001 From: huanghai <10402852@qq.com> Date: Mon, 24 Aug 2020 11:22:26 +0800 Subject: [PATCH] 'commit' --- dsBaseRpc/models/t_app_base.go | 1 + .../ControllerOauth2/ControllerOauth2.go | 75 +++++++++++++++- dsSso/docs/docs.go | 86 ++++++++++++++++++- dsSso/docs/swagger.json | 86 ++++++++++++++++++- dsSso/docs/swagger.yaml | 60 ++++++++++++- dsSso/main.go | 2 +- .../AccessSystemDao/AccessSystemDao.go | 13 ++- dsSupport/models/t_app_base.go | 1 + 8 files changed, 306 insertions(+), 18 deletions(-) diff --git a/dsBaseRpc/models/t_app_base.go b/dsBaseRpc/models/t_app_base.go index 46477eca..4a63ff48 100644 --- a/dsBaseRpc/models/t_app_base.go +++ b/dsBaseRpc/models/t_app_base.go @@ -11,4 +11,5 @@ type TAppBase struct { RedirectUri string `xorm:"default 'NULL' comment('统一认证回调地址') VARCHAR(1024)"` LogoutUri string `xorm:"default 'NULL' comment('统一认证登出地址') VARCHAR(1024)"` BUse int32 `xorm:"not null comment('是否可用 -2:不可用 1:可用') TINYINT(1)"` + SortId int32 `xorm:"not null default 1 comment('排序号') INT(11)"` } diff --git a/dsSso/Controller/ControllerOauth2/ControllerOauth2.go b/dsSso/Controller/ControllerOauth2/ControllerOauth2.go index c09c513b..b2ef3517 100644 --- a/dsSso/Controller/ControllerOauth2/ControllerOauth2.go +++ b/dsSso/Controller/ControllerOauth2/ControllerOauth2.go @@ -19,6 +19,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "github.com/RangelReale/osin" "github.com/dchest/captcha" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" @@ -54,6 +55,10 @@ func Routers(r *gin.RouterGroup) { r.POST("/bindWxUser", bindWxUser) //解除绑定 r.POST("/unBindWxUser", unBindWxUser) + //添加接入系统 + r.GET("/AddClient", AddClient) + //删除接入系统 + r.GET("/DelClient", DelClient) return } @@ -638,9 +643,9 @@ func checkOpenId(context *gin.Context) { // @Tags 登录验证类 // @Accept application/x-www-form-urlencoded // @Produce json -// @Param username formData string true "username" -// @Param password formData string true "password" -// @Param openId formData string true "openId" +// @Param username query string true "username" +// @Param password query string true "password" +// @Param openId query string true "openId" // @Success 200 {string} string // @Router /oauth2/bindWxUser [get] func bindWxUser(context *gin.Context) { @@ -732,3 +737,67 @@ func unBindWxUser(context *gin.Context) { Msg: "解除绑定成功!", }) } + +// @Summary 增加一个接入系统 +// @Description 增加一个接入系统 +// @Tags 统一认证管理 +// @Accept application/x-www-form-urlencoded +// @Produce json +// @Param access_key query string true "access_key" +// @Param secret_key query string true "secret_key" +// @Param redirect_uri query string true "redirect_uri" +// @Success 200 {string} string +// @Router /oauth2/AddClient [get] +func AddClient(context *gin.Context) { + ip := context.ClientIP() + if ip != "127.0.0.1" { + context.JSON(http.StatusOK, Model.Res{ + Code: http.StatusNotImplemented, + Msg: "内部接口,只限本机进行调用!", + }) + return + } + accessKey := context.Query("access_key") + secretKey := context.Query("secret_key") + redirectUri := context.Query("redirect_uri") + RedisStorage.OAuth2RedisStorage.CreateClient( + &osin.DefaultClient{ + Id: accessKey, + Secret: secretKey, + RedirectUri: redirectUri, + }, + ) + context.JSON(http.StatusOK, Model.Res{ + Code: http.StatusOK, + Msg: "增加成功!", + }) +} + +// @Summary 删除一个接入系统 +// @Description 删除一个接入系统 +// @Tags 统一认证管理 +// @Accept application/x-www-form-urlencoded +// @Produce json +// @Param access_key query string true "access_key" +// @Success 200 {string} string +// @Router /oauth2/DelClient [get] +func DelClient(context *gin.Context) { + ip := context.ClientIP() + if ip != "127.0.0.1" { + context.JSON(http.StatusOK, Model.Res{ + Code: http.StatusNotImplemented, + Msg: "内部接口,只限本机进行调用!", + }) + return + } + accessKey := context.Query("access_key") + RedisStorage.OAuth2RedisStorage.DeleteClient( + &osin.DefaultClient{ + Id: accessKey, + }, + ) + context.JSON(http.StatusOK, Model.Res{ + Code: http.StatusOK, + Msg: "删除成功!", + }) +} diff --git a/dsSso/docs/docs.go b/dsSso/docs/docs.go index 7acc8d0f..3d5a1f0d 100644 --- a/dsSso/docs/docs.go +++ b/dsSso/docs/docs.go @@ -25,6 +25,84 @@ var doc = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/oauth2/AddClient": { + "get": { + "description": "增加一个接入系统", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "统一认证管理" + ], + "summary": "增加一个接入系统", + "parameters": [ + { + "type": "string", + "description": "access_key", + "name": "access_key", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "secret_key", + "name": "secret_key", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "redirect_uri", + "name": "redirect_uri", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, + "/oauth2/DelClient": { + "get": { + "description": "删除一个接入系统", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "统一认证管理" + ], + "summary": "删除一个接入系统", + "parameters": [ + { + "type": "string", + "description": "access_key", + "name": "access_key", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, "/oauth2/access_token": { "post": { "description": "获取access_token", @@ -218,21 +296,21 @@ var doc = `{ "type": "string", "description": "username", "name": "username", - "in": "formData", + "in": "query", "required": true }, { "type": "string", "description": "password", "name": "password", - "in": "formData", + "in": "query", "required": true }, { "type": "string", "description": "openId", "name": "openId", - "in": "formData", + "in": "query", "required": true } ], @@ -586,7 +664,7 @@ type swaggerInfo struct { // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = swaggerInfo{ Version: "2.0", - Host: "127.0.0.1:8000", + Host: "10.10.14.187:8000", BasePath: "", Schemes: []string{}, Title: "东师理想统一认证中心(OAuth2+Sso)", diff --git a/dsSso/docs/swagger.json b/dsSso/docs/swagger.json index 01646dde..970f0eb0 100644 --- a/dsSso/docs/swagger.json +++ b/dsSso/docs/swagger.json @@ -7,8 +7,86 @@ "license": {}, "version": "2.0" }, - "host": "127.0.0.1:8000", + "host": "10.10.14.187:8000", "paths": { + "/oauth2/AddClient": { + "get": { + "description": "增加一个接入系统", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "统一认证管理" + ], + "summary": "增加一个接入系统", + "parameters": [ + { + "type": "string", + "description": "access_key", + "name": "access_key", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "secret_key", + "name": "secret_key", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "redirect_uri", + "name": "redirect_uri", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, + "/oauth2/DelClient": { + "get": { + "description": "删除一个接入系统", + "consumes": [ + "application/x-www-form-urlencoded" + ], + "produces": [ + "application/json" + ], + "tags": [ + "统一认证管理" + ], + "summary": "删除一个接入系统", + "parameters": [ + { + "type": "string", + "description": "access_key", + "name": "access_key", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + } + } + } + }, "/oauth2/access_token": { "post": { "description": "获取access_token", @@ -202,21 +280,21 @@ "type": "string", "description": "username", "name": "username", - "in": "formData", + "in": "query", "required": true }, { "type": "string", "description": "password", "name": "password", - "in": "formData", + "in": "query", "required": true }, { "type": "string", "description": "openId", "name": "openId", - "in": "formData", + "in": "query", "required": true } ], diff --git a/dsSso/docs/swagger.yaml b/dsSso/docs/swagger.yaml index 81ce130c..af922bfb 100644 --- a/dsSso/docs/swagger.yaml +++ b/dsSso/docs/swagger.yaml @@ -32,7 +32,7 @@ definitions: description: 个数 type: object type: object -host: 127.0.0.1:8000 +host: 10.10.14.187:8000 info: contact: {} description: 参考自xxl-sso @@ -40,6 +40,58 @@ info: title: 东师理想统一认证中心(OAuth2+Sso) version: "2.0" paths: + /oauth2/AddClient: + get: + consumes: + - application/x-www-form-urlencoded + description: 增加一个接入系统 + parameters: + - description: access_key + in: query + name: access_key + required: true + type: string + - description: secret_key + in: query + name: secret_key + required: true + type: string + - description: redirect_uri + in: query + name: redirect_uri + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: string + summary: 增加一个接入系统 + tags: + - 统一认证管理 + /oauth2/DelClient: + get: + consumes: + - application/x-www-form-urlencoded + description: 删除一个接入系统 + parameters: + - description: access_key + in: query + name: access_key + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + type: string + summary: 删除一个接入系统 + tags: + - 统一认证管理 /oauth2/access_token: post: consumes: @@ -167,17 +219,17 @@ paths: description: 绑定微信用户 parameters: - description: username - in: formData + in: query name: username required: true type: string - description: password - in: formData + in: query name: password required: true type: string - description: openId - in: formData + in: query name: openId required: true type: string diff --git a/dsSso/main.go b/dsSso/main.go index 92e8a73d..b514a25e 100644 --- a/dsSso/main.go +++ b/dsSso/main.go @@ -56,7 +56,7 @@ func startOAuth2Server() { // @title 东师理想统一认证中心(OAuth2+Sso) // @version 2.0 // @description 参考自xxl-sso -// @host 127.0.0.1:8000 +// @host 10.10.14.187:8000 func main() { // 发布模式 //gin.SetMode(gin.ReleaseMode) diff --git a/dsSupport/MyModel/AccessSystem/AccessSystemDao/AccessSystemDao.go b/dsSupport/MyModel/AccessSystem/AccessSystemDao/AccessSystemDao.go index 837cff64..a7c7c22a 100644 --- a/dsSupport/MyModel/AccessSystem/AccessSystemDao/AccessSystemDao.go +++ b/dsSupport/MyModel/AccessSystem/AccessSystemDao/AccessSystemDao.go @@ -19,7 +19,7 @@ var db = DbUtil.Engine /** 功能:增加一个接入系统 */ -func AddApp(appCode string, appName string, appUrl string, appIcon string, redirectUri string) error { +func AddApp(appCode string, appName string, appUrl string, appIcon string, redirectUri string, sortId int32) error { //生成AK+SK ak := xid.New() appKey := ak.String() //新增就生成一个secret @@ -43,9 +43,17 @@ func AddApp(appCode string, appName string, appUrl string, appIcon string, redir model.AppUrl = appUrl model.AppIcon = appIcon model.RedirectUri = redirectUri + model.SortId = sortId model.BUse = 1 _, err := db.Insert(&model) //插入REDIS缓存 + RedisStorage.OAuth2RedisStorage.CreateClient( + &osin.DefaultClient{ + Id: appKey, + Secret: secret, + RedirectUri: redirectUri, + }, + ) //TODO return err } @@ -64,13 +72,14 @@ func DelApp(appId string) error { /** 功能:修改一个接入系统 */ -func UpdateApp(appId string, appCode string, appName string, appUrl string, appIcon string, redirectUri string) error { +func UpdateApp(appId string, appCode string, appName string, appUrl string, appIcon string, redirectUri string, sortId int32) error { model := new(models.TAppBase) model.AppCode = appCode model.AppName = appName model.AppUrl = appUrl model.AppIcon = appIcon model.RedirectUri = redirectUri + model.SortId = sortId _, err := db.ID(appId).Update(model) //修改REDIS缓存 //TODO diff --git a/dsSupport/models/t_app_base.go b/dsSupport/models/t_app_base.go index 46477eca..4a63ff48 100644 --- a/dsSupport/models/t_app_base.go +++ b/dsSupport/models/t_app_base.go @@ -11,4 +11,5 @@ type TAppBase struct { RedirectUri string `xorm:"default 'NULL' comment('统一认证回调地址') VARCHAR(1024)"` LogoutUri string `xorm:"default 'NULL' comment('统一认证登出地址') VARCHAR(1024)"` BUse int32 `xorm:"not null comment('是否可用 -2:不可用 1:可用') TINYINT(1)"` + SortId int32 `xorm:"not null default 1 comment('排序号') INT(11)"` }