master
huanghai 5 years ago
parent 90605a74b5
commit df18be6559

@ -26,7 +26,7 @@ var doc = `{
"basePath": "{{.BasePath}}", "basePath": "{{.BasePath}}",
"paths": { "paths": {
"/oauth2/AddClient": { "/oauth2/AddClient": {
"get": { "post": {
"description": "增加一个接入系统", "description": "增加一个接入系统",
"consumes": [ "consumes": [
"application/x-www-form-urlencoded" "application/x-www-form-urlencoded"
@ -43,21 +43,21 @@ var doc = `{
"type": "string", "type": "string",
"description": "access_key", "description": "access_key",
"name": "access_key", "name": "access_key",
"in": "query", "in": "formData",
"required": true "required": true
}, },
{ {
"type": "string", "type": "string",
"description": "secret_key", "description": "secret_key",
"name": "secret_key", "name": "secret_key",
"in": "query", "in": "formData",
"required": true "required": true
}, },
{ {
"type": "string", "type": "string",
"description": "redirect_uri", "description": "redirect_uri",
"name": "redirect_uri", "name": "redirect_uri",
"in": "query", "in": "formData",
"required": true "required": true
} }
], ],
@ -72,7 +72,7 @@ var doc = `{
} }
}, },
"/oauth2/DelClient": { "/oauth2/DelClient": {
"get": { "post": {
"description": "删除一个接入系统", "description": "删除一个接入系统",
"consumes": [ "consumes": [
"application/x-www-form-urlencoded" "application/x-www-form-urlencoded"
@ -89,7 +89,7 @@ var doc = `{
"type": "string", "type": "string",
"description": "access_key", "description": "access_key",
"name": "access_key", "name": "access_key",
"in": "query", "in": "formData",
"required": true "required": true
} }
], ],

@ -10,7 +10,7 @@
"host": "127.0.0.1:8000", "host": "127.0.0.1:8000",
"paths": { "paths": {
"/oauth2/AddClient": { "/oauth2/AddClient": {
"get": { "post": {
"description": "增加一个接入系统", "description": "增加一个接入系统",
"consumes": [ "consumes": [
"application/x-www-form-urlencoded" "application/x-www-form-urlencoded"
@ -27,21 +27,21 @@
"type": "string", "type": "string",
"description": "access_key", "description": "access_key",
"name": "access_key", "name": "access_key",
"in": "query", "in": "formData",
"required": true "required": true
}, },
{ {
"type": "string", "type": "string",
"description": "secret_key", "description": "secret_key",
"name": "secret_key", "name": "secret_key",
"in": "query", "in": "formData",
"required": true "required": true
}, },
{ {
"type": "string", "type": "string",
"description": "redirect_uri", "description": "redirect_uri",
"name": "redirect_uri", "name": "redirect_uri",
"in": "query", "in": "formData",
"required": true "required": true
} }
], ],
@ -56,7 +56,7 @@
} }
}, },
"/oauth2/DelClient": { "/oauth2/DelClient": {
"get": { "post": {
"description": "删除一个接入系统", "description": "删除一个接入系统",
"consumes": [ "consumes": [
"application/x-www-form-urlencoded" "application/x-www-form-urlencoded"
@ -73,7 +73,7 @@
"type": "string", "type": "string",
"description": "access_key", "description": "access_key",
"name": "access_key", "name": "access_key",
"in": "query", "in": "formData",
"required": true "required": true
} }
], ],

@ -41,23 +41,23 @@ info:
version: "2.0" version: "2.0"
paths: paths:
/oauth2/AddClient: /oauth2/AddClient:
get: post:
consumes: consumes:
- application/x-www-form-urlencoded - application/x-www-form-urlencoded
description: 增加一个接入系统 description: 增加一个接入系统
parameters: parameters:
- description: access_key - description: access_key
in: query in: formData
name: access_key name: access_key
required: true required: true
type: string type: string
- description: secret_key - description: secret_key
in: query in: formData
name: secret_key name: secret_key
required: true required: true
type: string type: string
- description: redirect_uri - description: redirect_uri
in: query in: formData
name: redirect_uri name: redirect_uri
required: true required: true
type: string type: string
@ -72,13 +72,13 @@ paths:
tags: tags:
- 统一认证管理 - 统一认证管理
/oauth2/DelClient: /oauth2/DelClient:
get: post:
consumes: consumes:
- application/x-www-form-urlencoded - application/x-www-form-urlencoded
description: 删除一个接入系统 description: 删除一个接入系统
parameters: parameters:
- description: access_key - description: access_key
in: query in: formData
name: access_key name: access_key
required: true required: true
type: string type: string

@ -6,10 +6,14 @@ import (
"dsSupport/Utils/SqlKit" "dsSupport/Utils/SqlKit"
"dsSupport/models" "dsSupport/models"
"errors" "errors"
"fmt"
"github.com/oklog/ulid" "github.com/oklog/ulid"
"github.com/rs/xid" "github.com/rs/xid"
"github.com/xormplus/builder" "github.com/xormplus/builder"
"io/ioutil"
"math/rand" "math/rand"
"net/http"
"net/url"
"strings" "strings"
"time" "time"
) )
@ -46,26 +50,62 @@ func AddApp(appCode string, appName string, appUrl string, appIcon string, redir
model.SortId = sortId model.SortId = sortId
model.BUse = 1 model.BUse = 1
_, err := db.Insert(&model) _, err := db.Insert(&model)
if err != nil {
return err
}
//插入REDIS缓存 //插入REDIS缓存
RedisStorage.OAuth2RedisStorage.CreateClient( err = insertRedisCache(model.AccessKey, model.SecretKey, model.RedirectUri)
&osin.DefaultClient{
Id: appKey,
Secret: secret,
RedirectUri: redirectUri,
},
)
//TODO
return err return err
} }
/**
REDIS
*/
func insertRedisCache(accessKey string, secreKey string, redirectUri string) error {
resp, err := http.PostForm("http://127.0.0.1/oauth2/AddClient",
url.Values{"access_key": {accessKey}, "secret_key": {secreKey}, "redirect_uri": {redirectUri}})
if err != nil {
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
fmt.Println(string(body))
return nil
}
/**
REDIS
*/
func deleteRedisCache(accessKey string) error {
//插入REDIS缓存
resp, err := http.PostForm("http://127.0.0.1/oauth2/DelClient",
url.Values{"access_key": {accessKey}})
if err != nil {
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil
}
fmt.Println(string(body))
return nil
}
/** /**
*/ */
func DelApp(appId string) error { func DelApp(appId string) error {
model := new(models.TAppBase) model := new(models.TAppBase)
_, err := db.ID(appId).Delete(model) _, err := db.Where("app_id = ?", appId).Get(&model)
//删除REDIS缓存 //删除REDIS缓存
//RedisUtil.DEL("TJoinApp:" + appId) deleteRedisCache(model.AccessKey)
//删除物理记录
_, err = db.ID(appId).Delete(model)
return err return err
} }
@ -74,15 +114,21 @@ func DelApp(appId string) error {
*/ */
func UpdateApp(appId string, appCode string, appName string, appUrl string, appIcon string, redirectUri string, sortId int32) error { func UpdateApp(appId string, appCode string, appName string, appUrl string, appIcon string, redirectUri string, sortId int32) error {
model := new(models.TAppBase) model := new(models.TAppBase)
//修改REDIS缓存
_, err := db.Where("app_id = ?", appId).Get(&model)
//删除REDIS缓存
deleteRedisCache(model.AccessKey)
model.AppCode = appCode model.AppCode = appCode
model.AppName = appName model.AppName = appName
model.AppUrl = appUrl model.AppUrl = appUrl
model.AppIcon = appIcon model.AppIcon = appIcon
model.RedirectUri = redirectUri model.RedirectUri = redirectUri
model.SortId = sortId model.SortId = sortId
_, err := db.ID(appId).Update(model) _, err = db.ID(appId).Update(model)
//修改REDIS缓存
//TODO //插入REDIS缓存
err = insertRedisCache(model.AccessKey, model.SecretKey, model.RedirectUri)
return err return err
} }

Loading…
Cancel
Save