master
huanghai 5 years ago
parent 90605a74b5
commit df18be6559

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

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

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

@ -6,10 +6,14 @@ import (
"dsSupport/Utils/SqlKit"
"dsSupport/models"
"errors"
"fmt"
"github.com/oklog/ulid"
"github.com/rs/xid"
"github.com/xormplus/builder"
"io/ioutil"
"math/rand"
"net/http"
"net/url"
"strings"
"time"
)
@ -46,26 +50,62 @@ func AddApp(appCode string, appName string, appUrl string, appIcon string, redir
model.SortId = sortId
model.BUse = 1
_, err := db.Insert(&model)
if err != nil {
return err
}
//插入REDIS缓存
RedisStorage.OAuth2RedisStorage.CreateClient(
&osin.DefaultClient{
Id: appKey,
Secret: secret,
RedirectUri: redirectUri,
},
)
//TODO
err = insertRedisCache(model.AccessKey, model.SecretKey, model.RedirectUri)
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 {
model := new(models.TAppBase)
_, err := db.ID(appId).Delete(model)
_, err := db.Where("app_id = ?", appId).Get(&model)
//删除REDIS缓存
//RedisUtil.DEL("TJoinApp:" + appId)
deleteRedisCache(model.AccessKey)
//删除物理记录
_, err = db.ID(appId).Delete(model)
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 {
model := new(models.TAppBase)
//修改REDIS缓存
_, err := db.Where("app_id = ?", appId).Get(&model)
//删除REDIS缓存
deleteRedisCache(model.AccessKey)
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
_, err = db.ID(appId).Update(model)
//插入REDIS缓存
err = insertRedisCache(model.AccessKey, model.SecretKey, model.RedirectUri)
return err
}

Loading…
Cancel
Save