补充checker和enpoint注册逻辑

This commit is contained in:
yumaojun03 2025-03-16 15:26:12 +08:00
parent 997d7b1cc0
commit 903a3d8520
6 changed files with 72 additions and 10 deletions

View File

@ -1,17 +1,37 @@
<mxfile host="65bd71144e">
<diagram id="IhDVpRNFMw0Yaq81ft-V" name="第 1 页">
<mxGraphModel dx="873" dy="647" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<mxGraphModel dx="873" dy="324" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="2" value="cmdb" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="140" y="220" width="340" height="160" as="geometry"/>
<mxGeometry x="30" y="260" width="340" height="160" as="geometry"/>
</mxCell>
<mxCell id="5" value="user center" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="520" y="265" width="230" height="160" as="geometry"/>
</mxCell>
<mxCell id="3" value="user" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="290" y="320" width="80" height="50" as="geometry"/>
<mxGeometry x="545" y="370" width="80" height="50" as="geometry"/>
</mxCell>
<mxCell id="4" value="token" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="390" y="320" width="80" height="50" as="geometry"/>
<mxGeometry x="645" y="370" width="80" height="50" as="geometry"/>
</mxCell>
<mxCell id="7" style="edgeStyle=orthogonalEdgeStyle;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.25;entryDx=0;entryDy=0;" edge="1" parent="1" source="6" target="5">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="8" value="rpc" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="7">
<mxGeometry x="0.4744" y="3" relative="1" as="geometry">
<mxPoint as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="6" value="auth middleware" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="140" y="290" width="120" height="30" as="geometry"/>
</mxCell>
<mxCell id="9" value="..." style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="30" y="460" width="340" height="160" as="geometry"/>
</mxCell>
<mxCell id="10" value="scm: auth middleware" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="520" y="200" width="120" height="30" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>

View File

@ -1,11 +1,17 @@
# 中心化用户鉴权服务
## 认证(用户的身份问题 ID 你是谁)
```sh
curl --location 'http://127.0.0.1:8020/api/mcenter/v1/token/validate' \
--header 'Content-Type: application/json' \
--header 'Authorization: ••••••' \
--data '{
"access_token": "ANfXCQ3tjDNv5y1mq4F1mSBw"
}'
```
## 鉴权(用户能访问哪些接口, 你能干什么Role)
## 鉴权(用户能访问哪些接口, 你能干什么Role)
1. api 注册给 mcenter

View File

@ -58,7 +58,7 @@ func (c *Checker) Init() error {
}
func (c *Checker) Check(r *restful.Request, w *restful.Response, next *restful.FilterChain) {
route := endpoint.NewEntryFromRestRoute(r.SelectedRoute())
route := endpoint.NewEntryFromRestRouteReader(r.SelectedRoute())
if route.RequiredAuth {
// 校验身份
tk, err := c.CheckToken(r)

View File

@ -0,0 +1,34 @@
package permission
import (
"context"
"github.com/infraboard/mcube/v2/ioc"
"github.com/infraboard/mcube/v2/ioc/config/gorestful"
"github.com/infraboard/modules/iam/apps/endpoint"
)
func init() {
ioc.Api().Registry(&ApiRegister{})
}
type ApiRegister struct {
ioc.ObjectImpl
endpoint endpoint.Service
}
func (a *ApiRegister) Init() error {
// 注册认证中间件
entries := endpoint.NewEntryFromRestfulContainer(gorestful.RootRouter())
req := endpoint.NewRegistryEndpointRequest()
req.AddItem(entries...)
_, err := a.endpoint.RegistryEndpoint(context.Background(), req)
if err != nil {
return err
}
return nil
}
func (c *ApiRegister) Name() string {
return "api_register"
}

2
go.mod
View File

@ -10,7 +10,7 @@ require (
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.3
github.com/infraboard/mcube/v2 v2.0.51
github.com/infraboard/modules v0.0.2
github.com/infraboard/modules v0.0.3
github.com/rs/zerolog v1.32.0
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1116
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.1115

2
go.sum
View File

@ -133,6 +133,8 @@ github.com/infraboard/modules v0.0.0-20250316032722-447e1c651a75 h1:yuK6RWI23duw
github.com/infraboard/modules v0.0.0-20250316032722-447e1c651a75/go.mod h1:v5qcwHvGOg6UsmKPVgAN3sn+XLgD9uYu/PqEWU129ck=
github.com/infraboard/modules v0.0.2 h1:LyIKcSp4J/p96JHm59ZtDr3CF1yWN09RttiPmRgoYHM=
github.com/infraboard/modules v0.0.2/go.mod h1:v5qcwHvGOg6UsmKPVgAN3sn+XLgD9uYu/PqEWU129ck=
github.com/infraboard/modules v0.0.3 h1:OTsW1K7htTnNZUMNHJOcHIL4Tp218LaGPk4HX3Cuas0=
github.com/infraboard/modules v0.0.3/go.mod h1:v5qcwHvGOg6UsmKPVgAN3sn+XLgD9uYu/PqEWU129ck=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=