mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-20 18:47:55 +08:00
fix #I3RHPD 在api中对用户接口权限进行鉴权
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Security.AccessControl;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
|
using NUnit.Framework;
|
||||||
using OpenAuth.App.Interface;
|
using OpenAuth.App.Interface;
|
||||||
using OpenAuth.App.Request;
|
using OpenAuth.App.Request;
|
||||||
using OpenAuth.App.Response;
|
using OpenAuth.App.Response;
|
||||||
@@ -105,6 +107,18 @@ namespace OpenAuth.App
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源类型
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<List<SysResourceApp>> GetResourceApps()
|
||||||
|
{
|
||||||
|
var types = await SugarClient.Queryable<SysResource>()
|
||||||
|
.Distinct()
|
||||||
|
.Select(u => new {u.AppId,u.AppName})
|
||||||
|
.ToListAsync();
|
||||||
|
return types.Select(u => new SysResourceApp(u.AppId, u.AppName)).ToList();
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 同步站点API到资源列表
|
/// 同步站点API到资源列表
|
||||||
/// <para>读取站点API信息,如果资源列表中不存在,则添加</para>
|
/// <para>读取站点API信息,如果资源列表中不存在,则添加</para>
|
||||||
@@ -124,9 +138,12 @@ namespace OpenAuth.App
|
|||||||
|
|
||||||
resource = new SysResource
|
resource = new SysResource
|
||||||
{
|
{
|
||||||
|
Id = api.Path,
|
||||||
Name = api.Path,
|
Name = api.Path,
|
||||||
Disable = true,
|
Disable = true,
|
||||||
SortNo = 0,
|
SortNo = 0,
|
||||||
|
AppId = $"{Define.API}_{api.Tag}",
|
||||||
|
AppName = $"API接口-{api.Tag}",
|
||||||
TypeId = Define.API,
|
TypeId = Define.API,
|
||||||
TypeName = "API接口",
|
TypeName = "API接口",
|
||||||
Description = api.Summary??"",
|
Description = api.Summary??"",
|
||||||
@@ -140,4 +157,9 @@ namespace OpenAuth.App
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源类型
|
||||||
|
/// </summary>
|
||||||
|
public record SysResourceApp(string Id, string Name);
|
||||||
}
|
}
|
@@ -126,5 +126,23 @@ namespace OpenAuth.WebApi.Controllers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源所属应用
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<Response<List<SysResourceApp>>> GetResourceApps()
|
||||||
|
{
|
||||||
|
var result = new Response<List<SysResourceApp>>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result.Result = await _app.GetResourceApps();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
result.Code = 500;
|
||||||
|
result.Message = e.InnerException?.Message ?? e.Message;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,3 +1,10 @@
|
|||||||
|
<!--
|
||||||
|
* @Author: yubaolee <yubaolee@163.com> | ahfu~ <954478625@qq.com>
|
||||||
|
* @Date: 2023-12-25 14:43:53
|
||||||
|
* @Description:
|
||||||
|
* @LastEditTime: 2025-03-11 11:19:25
|
||||||
|
* Copyright (c) 2025 by yubaolee | ahfu~ , All Rights Reserved.
|
||||||
|
-->
|
||||||
# API权限控制
|
# API权限控制
|
||||||
|
|
||||||
在使用OpenAuth.WebApi过程中,系统会对所有的Api进行权限控制。如果没有登录就访问Api接口,会提示下面信息:
|
在使用OpenAuth.WebApi过程中,系统会对所有的Api进行权限控制。如果没有登录就访问Api接口,会提示下面信息:
|
||||||
@@ -30,6 +37,15 @@ Host: localhost:52789
|
|||||||
X-Token: e4a5aa00
|
X-Token: e4a5aa00
|
||||||
|
|
||||||
```
|
```
|
||||||
|
## 按角色授权API资源
|
||||||
|
|
||||||
|
目前主流的接口平台都提供按角色(或账号)授权访问API的功能,OpenAuth.Net也不例外。在OpenAuth.Net中,接口API被当作资源处理。如图:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
如果后端新增或删除API,点击【同步系统API资源】按钮,即可同步到资源列表中。在角色管理功能中,可以对登录的角色进行API资源授权。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## 不登录直接访问
|
## 不登录直接访问
|
||||||
|
|
||||||
|
@@ -1,23 +1,17 @@
|
|||||||
# 开发规范
|
# 后端开发规范
|
||||||
|
|
||||||
## 新增数据库名称规范
|
## 数据库表及字段命名
|
||||||
|
|
||||||
子系统名称+业务名称+表尾,其中表尾名称规则如下:
|
SqlServer采用PascalCase命名,Oracle采用全大写命名,其他数据库采用camelCase命名。
|
||||||
|
|
||||||
|
::: tip 提示
|
||||||
|
|
||||||
|
开源版代码生成时,通过表结尾Dtbl来判断是否是生成明细表代码。因此建议数据库表命名时按:子系统名称+业务名称+表尾,其中表尾名称规则:
|
||||||
- 基础主数据以Mst结尾;
|
- 基础主数据以Mst结尾;
|
||||||
|
|
||||||
- 普通业务表以Tbl结尾;
|
- 普通业务表以Tbl结尾;
|
||||||
|
|
||||||
- 业务明细表以Dtbl结尾;
|
- 业务明细表以Dtbl结尾;
|
||||||
|
如:WMS系统入库订单明细表:WmsInboundOrderDtbl
|
||||||
比如:
|
:::
|
||||||
|
|
||||||
- WMS系统客户主数据表:WmsCustomerMst
|
|
||||||
|
|
||||||
- WMS系统入库订单头表:WmsInboundOrderTbl
|
|
||||||
|
|
||||||
- WMS系统入库订单明细表:WmsInboundOrderDtbl
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 数据库字段类型
|
## 数据库字段类型
|
||||||
|
Reference in New Issue
Block a user