CSFramework.WebapiV3(.NET7/NetCore) 系统安全及Token令牌介绍
CSFramework.WebapiV3(.NET7/NetCore) 系统安全及Token令牌介绍
目录
1、GateController - 门禁控制器
GateController也可称为系统安全控制器,提供系统登录、登出、刷新令牌接口服务。
GateController提供6个接口:
序 | 名称 | 返回类型 | 接口说明 |
1 | Login | Task<ModelUser> | C/S框架登录接口,CSFrameworkV6_System.tb_MyUser表用户认证 |
2 | Logout | Task<Boolean> | C/S框架登出接口 |
3 | RefreshToken | Task<res_Token> | C/S框架刷新令牌 |
4 | LoginAPP | Task<Api_User> | WebApi框架登录接口,CSFramework_WebAPI_V3.Api_User表用户认证 |
5 | LogoutAPP | Task<Boolean> | WebApi框架登出接口 |
6 | RefreshTokenAPP | Task<res_Token> | WebApi框架刷新令牌 |
2、保存Token及刷新Token
用户登录或调用刷新令牌接口,系统自动生成一个全局令牌(JWT Token)序列,并存储到数据表。
CS框架系统数据库:tb_MyUser表Token字段设置为 varchar(1000) 长度
WebApi框架数据库:Api_User表Token字段设置为 varchar(1000) 长度
3、设置Jwt Token过期
JwtToken不能直接设置过期。
如果你想要强制所有用户的Token过期时,你可以在数据库中设置一个标志,当用户登录时检查这个标志,如果标志被设置,则不允许操作接口。
4、C/S客户端调用WebApi接口
首先要登录WebApi获取Token,调用Login或LoginAPP接口,存储到Loginer.CurrentUser.Token属性。
C# 全选
//调用Login或LoginAPP接口登录。
var webApiUser=LoginWebApi();
Loginer.CurrentUser.Token = webApiUser.Token;
5、Api接口测试报告
Login - 模拟C/S框架用户登录
请求:
C# 全选
{
"validationTicket": "#ZuBaSz+G$*FGs2+a/z3aDd3aGqo0F34f160$^",
"LoginUser": {
"Account": "admin",
"Password": "Snj6+Q3dGGb1ukbEi0igFw==",
"DBID": "Normal",
"IP": "127.0.0.1",
"MAC": "10-FF-84-46-04-62",
"LoginAuthType": "LocalSystemAuth",
"LoginTime": "2024-05-25T18:31:48.703367+08:00",
"ClientVersion": "YourProject V6.0/Android 6.12",
"DeviceMID": "移动端设备MID",
"DeviceType": "Android"
},
"Language": "zh_cn",
"PublicKey": "",
"AppId": "csframework"
}
返回:
JSON 全选
{
"Data": {
"TS": "0001-01-01 00:00:00",
"Account": "admin",
"NovllAccount": null,
"DomainDd": null,
"DomainName": null,
"UserName": "超级用户",
"Address": null,
"Tel": "13899882288",
"Email": "13899882288@163.com",
"Password": "Snj6+Q3dGGb1ukbEi0igFw==",
"LastLoginTime": "2024-05-31 17:27:16",
"LastLogoutTime": "2024-05-30 22:59:56",
"IsLocked": "N",
"CreateTime": "0001-01-01 00:00:00",
"FlagAdmin": "Y",
"Flagonline": "Y",
"Logincounter": 12735,
"Datasets": ",Normal,QiangSheng,DongLian,Normal1",
"WorkerID": "13899882288",
"Org1": "ND",
"Org2": "201",
"Token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJhZG1pbiIsInVzZXJOYW1lIjoi6LaF57qn55So5oi3IiwicHVibGljS2V5IjoiIiwiYXBwSWQiOiJjc2ZyYW1ld29yayIsImxhbmd1YWdlIjoiemhfY24iLCJkYmlkIjoiTm9ybWFsIiwibmJmIjoxNzE3MTQ3NjM2LCJleHAiOjE4MDM1NDc2MzYsImlzcyI6Ind3dy5jc2ZyYW1ld29yay5jb20iLCJhdWQiOiJXZWJBcGkoTkVUQ29yZSkifQ.KLgpv5eGpsqumPFuNVoDCJsP03IpEl-82Ll4mm63OVA",
"Phone": "13899882288"
},
"Success": true,
"ErrorCode": 0,
"Message": "请求成功(Request Successfully)!"
}
LoginAPP - 模拟WebApi框架用户登录
请求:
C# 全选
{
"validationTicket": "#ZuBaSz+G$*FGs2+a/z3aDd3aGqo0F34f160$^",
"LoginUser": {
"Account": "13888888888",
"Password": "e10adc3949ba59abbe56e057f20f883e",
"DBID": "Normal",
"IP": "127.0.0.1",
"MAC": "10-FF-84-46-04-62",
"LoginTime": "2024-05-25T18:31:48.703367+08:00",
"ClientVersion": "YourProject V6.0/Android 6.12",
"DeviceMID": "移动端设备MID",
"DeviceType": "Android"
},
"Language": "zh_cn",
"PublicKey": "",
"AppId": "csframework"
}
返回:
JSON 全选
{
"Data": {
"RowID": "10112",
"Account": "admin",
"Password": "e10adc3949ba59abbe56e057f20f883e",
"UserName": "管理员",
"UserType": 1,
"UserLevel": 1,
"UID": "567",
"Phone": "13888888888",
"Status": 1,
"LoginCount": 406,
"FlagLock": "N",
"MIDMobile": "345",
"DeviceType": "3",
"DeviceOSVersion": "3",
"RegisterTime": "2022-12-01 14:26:32",
"LastUpdateDate": "2022-12-01 14:26:32",
"TokenExpires": 60480,
"Token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJhZG1pbiIsInVzZXJOYW1lIjoi566h55CG5ZGYIiwicHVibGljS2V5IjoiIiwiYXBwSWQiOiJjc2ZyYW1ld29yayIsImxhbmd1YWdlIjoiemhfY24iLCJkYmlkIjoiTm9ybWFsIiwibmJmIjoxNzE3MTQ3Nzk1LCJleHAiOjE4MDM1NDc3OTUsImlzcyI6Ind3dy5jc2ZyYW1ld29yay5jb20iLCJhdWQiOiJXZWJBcGkoTkVUQ29yZSkifQ.Zsg6qCpsPm_BGzaDfp_8j8Jjl3efQgCPzCMuidTqArc",
"LastLoginTime": "2024-05-31 17:29:55",
"Permissions": "[{\"name\":\"成品入库\",\"actions\":127},{\"name\":\"纸板库存查询\",\"actions\":127},{\"name\":\"纸箱库存查询\",\"actions\":127},{\"name\":\"辅料库存查询\",\"actions\":127},{\"name\":\"收款查询\",\"actions\":127},{\"name\":\"付款查询\",\"actions\":127},{\"name\":\"纸箱送货明细\",\"actions\":127},{\"name\":\"订单汇总\",\"actions\":127},{\"name\":\"订单未入库表\",\"actions\":127},{\"name\":\"订单未采购表\",\"actions\":127},{\"name\":\"纸箱送货汇总\",\"actions\":127},{\"name\":\"成品出库\",\"actions\":127},{\"name\":\"订单汇总\",\"actions\":127},{\"name\":\"订单未入库表\",\"actions\":127},{\"name\":\"订单未采购表\",\"actions\":127},{\"name\":\"订单未交货\",\"actions\":127},{\"name\":\"采购明细\",\"actions\":127},{\"name\":\"采购汇总\",\"actions\":127},{\"name\":\"采购未交明细\",\"actions\":127},{\"name\":\"采购未领料明细\",\"actions\":127},{\"name\":null,\"actions\":127},{\"name\":null,\"actions\":127},{\"name\":\"纸板入库\",\"actions\":127},{\"name\":\"纸板出库\",\"actions\":127},{\"name\":\"产量登记\",\"actions\":127},{\"name\":\"销售报价\",\"actions\":127},{\"name\":\"订单明细查询\",\"actions\":127},{\"name\":\"客户查询\",\"actions\":127},{\"name\":\"供应商查询\",\"actions\":127}]"
},
"Success": true,
"ErrorCode": 0,
"Message": "请求成功(Request Successfully)!"
}
RefreshToken - 刷新令牌(C/S框架用户)
请求:
C# 全选
{
"UserId": "admin",
"Password": "Snj6+Q3dGGb1ukbEi0igFw=="
}
返回:
JSON 全选
{
"Data": {
"Token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJhZG1pbiIsInVzZXJOYW1lIjoi6LaF57qn55So5oi3IiwicHVibGljS2V5IjoiIiwiYXBwSWQiOiIiLCJsYW5ndWFnZSI6IiIsImRiaWQiOiIiLCJuYmYiOjE3MTcxNDcyMjUsImV4cCI6MTgwMzU0NzIyNSwiaXNzIjoid3d3LmNzZnJhbWV3b3JrLmNvbSIsImF1ZCI6IldlYkFwaShORVRDb3JlKSJ9.Az15LDq6B9uWi7JWsdXifbeF027jqMlQ4O0Gd_9R5WU",
"Time": "2024-05-31 17:20:27"
},
"Success": true,
"ErrorCode": 0,
"Message": "请求成功(Request Successfully)!"
}
RefreshTokenAPP - 刷新令牌(WebApi框架用户)
请求:
C# 全选
{
"UserId": "13888888888",
"Password": "e10adc3949ba59abbe56e057f20f883e"
}
返回:
JSON 全选
{
"Data": {
"Token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiJhZG1pbiIsInVzZXJOYW1lIjoi566h55CG5ZGYIiwicHVibGljS2V5IjoiIiwiYXBwSWQiOiIiLCJsYW5ndWFnZSI6IiIsImRiaWQiOiIiLCJuYmYiOjE3MTcxNDY5OTIsImV4cCI6MTgwMzU0Njk5MiwiaXNzIjoid3d3LmNzZnJhbWV3b3JrLmNvbSIsImF1ZCI6IldlYkFwaShORVRDb3JlKSJ9.FwOpuO8XfLPAP82LEtSuiHwYdQUjSkjtQucu3TBeVYo",
"Time": "2024-05-31 17:16:37"
},
"Success": true,
"ErrorCode": 0,
"Message": "请求成功(Request Successfully)!"
}
Logout - 登出(C/S框架用户)
请求:
C# 全选
{
"Account": "admin",
"Password": "Snj6+Q3dGGb1ukbEi0igFw=="
}
返回:
JSON 全选
{
"Data": true,
"Success": true,
"ErrorCode": 0,
"Message": "请求成功(Request Successfully)!"
}
LogoutAPP - 登出(WebApi框架用户)
请求:
C# 全选
{
"Account": "13888888888",
"Password": "e10adc3949ba59abbe56e057f20f883e"
}
返回:
JSON 全选
{
"Data": true,
"Success": true,
"ErrorCode": 0,
"Message": "请求成功(Request Successfully)!"
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网