ASP.NET Core分布式项目实战(Consent Controller Get请求逻辑实现)--学习笔记
任务20:Consent Controller Get请求逻辑实现
接着上一节的思路,实现一下 ConsentController
根据流程图在构造函数注入 IClientStore,IResourceStore,IIdentityServerInteractionService
构造函数
private readonly IClientStore _clientSotre;
private readonly IResourceStore _resourceStore;
private readonly IIdentityServerInteractionService _identityServerInteractionService;private ConsentController(IClientStore clientStore,IResourceStore resourceStore,IIdentityServerInteractionService identityServerInteractionService)
{_clientSotre = clientStore;_resourceStore = resourceStore;_identityServerInteractionService = identityServerInteractionService;
}
Index
public IActionResult Index(string returnUrl)
{var model = BuildConsentViewModel(returnUrl);if (model == null){}return View(model);
}
BuildConsentViewModel
private async Task<ConsentViewModel> BuildConsentViewModel(string returnUrl)
{var request = await _identityServerInteractionService.GetAuthorizationContextAsync(returnUrl);if (request == null)return null;var client = await _clientSotre.FindEnabledClientByIdAsync(request.ClientId);var resources = await _resourceStore.FindEnabledResourcesByScopeAsync(request.ScopesRequested);return CreateConsentViewModel(request, client, resources);
}
CreateConsentViewModel
private ConsentViewModel CreateConsentViewModel(AuthorizationRequest request, Client client, Resources resources)
{var vm = new ConsentViewModel();vm.ClientName = client.ClientName;vm.ClientLogoUrl = client.LogoUri;vm.ClientUrl = client.ClientUri;vm.AllowRemeberConsent = client.AllowRememberConsent;vm.IdentityScopes = resources.IdentityResources.Select(i => CreateScopeViewModel(i));vm.ResourceScopes = resources.ApiResources.SelectMany(i => i.Scopes).Select(x => CreateScopeViewModel(x));return vm;
}
在获取 vm.ResourceScopes 的时候我们用到了 SelectMany,如果我们使用 resources.ApiResources.Select 的话,我们会得到一个 List<List>,而我们想要得到的是一个 List,所以通过 SelectMany 会把 List<List> 展开得到里面的每一个 List
CreateScopeViewModel
private ScopeViewModel CreateScopeViewModel(IdentityResource identityResource)
{return new ScopeViewModel{Name = identityResource.Name,DisplayName = identityResource.DisplayName,Description = identityResource.Description,Required = identityResource.Required,Checked = identityResource.Required,Emphasize = identityResource.Emphasize,};
}private ScopeViewModel CreateScopeViewModel(Scope scope)
{return new ScopeViewModel{Name = scope.Name,DisplayName = scope.DisplayName,Description = scope.Description,Required = scope.Required,Checked = scope.Required,Emphasize = scope.Emphasize,};
}
ConsentViewModel 添加 ClientUrl
public string ClientUrl { get; set; }
ScopeViewModel 修改字段类型为 bool
public bool Emphasize { get; set; }
public bool Required { get; set; }
课程链接
http://video.jessetalk.cn/course/explore
相关文章
ASP.NET Core分布式项目实战(Consent视图制作)--学习笔记
ASP.NET Core分布式项目实战(Identity Server 4回顾,Consent 实现思路介绍)--学习笔记
ASP.NET Core分布式项目实战(oauth2 + oidc 实现 client部分)--学习笔记
ASP.NET Core分布式项目实战(oauth2 + oidc 实现 server部分)--学习笔记
ASP.NET Core分布式项目实战(oauth2与open id connect 对比)--学习笔记
ASP.NET Core分布式项目实战(详解oauth2授权码流程)--学习笔记
ASP.NET Core分布式项目实战(oauth密码模式identity server4实现)--学习笔记
ASP.NET Core分布式项目实战(第三方ClientCredential模式调用)--学习笔记
ASP.NET Core分布式项目实战(客户端集成IdentityServer)--学习笔记
ASP.NET Core分布式项目实战(业务介绍,架构设计,oAuth2,IdentityServer4)--学习笔记
ASP.NET Core分布式项目实战(课程介绍,MVP,瀑布与敏捷)--学习笔记
ASP.NET Core分布式项目实战(Consent Controller Get请求逻辑实现)--学习笔记相关推荐
- ASP.NET Core分布式项目实战(第三方ClientCredential模式调用)--学习笔记
任务10:第三方ClientCredential模式调用 创建一个控制台程序 dotnet new console --name ThirdPartyDemo 添加 Nuget 包:IdentityM ...
- ASP.NET Core分布式项目实战(Consent 确认逻辑实现)--学习笔记
任务22:Consent 确认逻辑实现 接下来,我们会在上一节的基础上添加两个按钮,同意和不同意,点击之后会把请求 post 到 ConsentController 处理,如果同意会通过 return ...
- ASP.NET Core分布式项目实战(运行Consent Page)--学习笔记
任务21:运行Consent Page 修改 Config.cs 中的 RequireConsent 为 true,这样登录的时候就会跳转到 Consent 页面 修改 ConsentControll ...
- ASP.NET Core分布式项目实战(集成ASP.NETCore Identity)--学习笔记
任务24:集成ASP.NETCore Identity 之前在 Index 页面写了一个 strong 标签,需要加个判断再显示,不然为空没有错误的时候也会显示 @if (!ViewContext.M ...
- ASP.NET Core分布式项目实战(oauth2 + oidc 实现 client部分)--学习笔记
任务16:oauth2 + oidc 实现 client部分 实现 client 之前启动一下上一节的 server,启动之前需要清除一些代码 注释 Program 的 MigrateDbContex ...
- ASP.NET Core分布式项目实战(oauth2 + oidc 实现 server部分)--学习笔记
任务15:oauth2 + oidc 实现 server部分 基于之前快速入门的项目(MvcCookieAuthSample): ASP.NET Core快速入门(第5章:认证与授权)--学习笔记 A ...
- ASP.NET Core分布式项目实战(详解oauth2授权码流程)--学习笔记
最近公司产品上线,通宵加班了一个月,一直没有更新,今天开始恢复,每日一更,冲冲冲 任务13:详解oauth2授权码流程 我们即将开发的产品有一个用户 API,一个项目服务 API,每个服务都需要认证授 ...
- ASP.NET Core分布式项目实战(客户端集成IdentityServer)--学习笔记
任务9:客户端集成IdentityServer 新建 API 项目 dotnet new webapi --name ClientCredentialApi 控制器添加验证 using Microso ...
- ASP.NET Core分布式项目实战(业务介绍,架构设计,oAuth2,IdentityServer4)--学习笔记...
任务4:第一章计划与目录 敏捷产品开发流程 原型预览与业务介绍 整体架构设计 API 接口设计 / swagger Identity Server 4 搭建登录 账号 API 实现 配置中心 任务5: ...
最新文章
- base64 python兼容js_无法在中读取Base64编码的图像节点.js它是从Python发送的
- [转]JDBC中日期时间的处理技巧
- Oracle计划新的移动OpenJDK项目
- python 编程一日一练-python每日一练
- 项目中遇到的几件有趣事
- 3dContactPointAnnotationTool开发日志(三三)
- chrome网页自动化插件_chrome网页注释插件
- AUTOSAR从入门到精通100讲(二十二)-AUTOSAR通信篇—CANTP模块
- c++ 分页展示_分合相宜 Excel透视报表生成分页和汇总报表
- Astro Panel Pro for Mac - ps天文景观插件 支持ps2021
- 如何选择B2C电商仓储系统?
- MySQL安装教程及配置环境变量(建议收藏)
- cedit多行文本设置透明背景会重叠_python:电商用户评价文本分析(wordcloud+jieba)...
- html中怎样写渐变色代码,html颜色渐变代码 怎样用css实现网页背景颜色渐变
- k8s使用命令报错:error: You must be logged in to the server (Unauthorized)
- 文字图片滚动 jquery 实现代码
- 无人驾驶-控制-自行车模型
- BERT Word Embeddings 教程
- Linux权限委派(生产环境必备)
- 【物联网专题】2.2_设备管理平台_什么是物模型?
热门文章
- 数学图形(2.18)Hyperbolical conical spiral双曲圆锥螺线
- 数组面试题--数组求和
- [HTML5]3D标签云
- 如何用C#在Excel中生成图表?
- 养鹿专辑二:恋鹿篇之枕着老婆的梦编程
- 弹窗php整人_[整人小程序] 超级信息框(无限弹窗++)
- .net调用c++方法时如何释放c++中分配的内存_C/C++编程笔记:C语言编程知识要点总结!大一C语言知识点(全)...
- win10任务栏和开始菜单_如何将网站固定到Windows 10任务栏或开始菜单
- 如何使用Avira Rescue CD清洁感染的PC
- PHP: 深入了解一致性哈希