master
huanghai 5 years ago
parent fd287d68ae
commit 59e603062a

@ -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)"`
}

@ -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: "删除成功!",
})
}

@ -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)",

@ -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
}
],

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

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

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

@ -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)"`
}

Loading…
Cancel
Save