首页
登录
原
.net core 3.1 Identity Server4 (ProfileService检测有效用户与获取Claims)
87
人阅读
2021/2/20 14:39
总访问:
195621
评论:
0
手机
收藏
分类:
.net后台框架
 >#.net core 3.1 Identity Server4 (ProfileService检测有效用户与获取Claims) [TOC]  目录 ------------ https://www.tnblog.net/hb/article/details/5458 关于IProfileService接口 ------------ tn>将用户所需的所有可能的声明放入cookie中是不切实际的,因此IdentityServer定义了一个扩展点(`IProfileService`),以允许根据用户的需要动态加载声明(`Claim`)。该接口通常会实现此接口来访问包含用户身份数据的自定义数据库或API。 Server中实现IProfileService ------------ tn>创建一个`ProfileService`类,实现`IProfileService`接口,具体如下代码所示。  ```csharp public class ProfileService : IProfileService { /// <summary> /// 获取用户的Claims /// </summary> /// <param name="context"></param> /// <returns></returns> public Task GetProfileDataAsync(ProfileDataRequestContext context) { // 添加claim context.IssuedClaims = new List<Claim> { new Claim("xType","xValue") }; return Task.CompletedTask; } /// <summary> /// identity server需要确定用户是否有效 /// </summary> /// <param name="context"></param> /// <returns></returns> public Task IsActiveAsync(IsActiveContext context) { // 这里写你的逻辑,IsActive表示通过还是不通过,true表示通过 context.IsActive = true; return Task.CompletedTask; } } ``` tn>在`Startup`类中添加`.AddProfileService<ProfileService>()`方法  设置启动项 ------------ tn>这里我们启动 `HybridMvc` 客户端  添加映射 ------------ tn>在 `HybridMvc` 客户端的 `Startup` 中添加相关字段映射 ```csharp options.ClaimActions.MapUniqueJsonKey("xType", "xType"); ``` 运行测试 ------------      
欢迎加群讨论技术,群号:677373950
评价
{{titleitem}}
{{titleitem}}
{{item.content}}
{{titleitem}}
{{titleitem}}
{{item.content}}
尘叶心繁
这一世以无限游戏为使命!
博主信息
排名
6
文章
6
粉丝
16
评论
8
文章类别
.net后台框架
129篇
linux
8篇
linux中cve
1篇
windows中cve
0篇
资源分享
8篇
Win32
2篇
前端
24篇
传说中的c
4篇
Xamarin
1篇
docker
7篇
容器编排
27篇
grpc
4篇
Go
15篇
yaml模板
1篇
理论
1篇
更多
Sqlserver
2篇
云产品
19篇
git
2篇
Unity
1篇
考证
2篇
RabbitMq
21篇
最新文章
.net core 3.1 依赖注入的内部结构介绍
使用xftp能登录,但不能上传文件,文件夹权限问题
.net core 3.1 Identity Server4 (ProfileService检测有效用户与获取Claims)
.net core 3.1 制作一个简单的依赖注入容器
RabbitMq集群镜像同步与应用
Centos7搭建高可用的RabbitMq集群
.net core 3.1 服务承载【Workservice】
.net core 3.1 服务承载【BackgroundService】
CentOS7安装RabbitMq
.net core 3.1 服务承载【目录】
.net core 3.1 服务承载【配置文件】
最新评价
{{item.articleTitle}}
{{item.blogName}}
:
{{item.content}}
关于我们
ICP备案 :
渝ICP备18016597号-1
网站信息:
2018-2020TNBLOG.NET
技术交流:
群号677373950
欢迎加群
欢迎加群交流技术