ASP.NET Core分布式项目实战(Consent视图制作)--学习笔记
任务19:Consent视图制作
按照上一节 Consent 的思路
在 mvcCookieAuthSample 项目的 Controllers 文件夹下新建一个 ConsentController
在 Views 文件夹下新建一个 Consent 文件夹,然后在该文件夹下新建一个 Index 视图
在 ViewModels 文件夹下新建一个 ConsentViewModel
在 ViewModels 文件夹下新建一个 ScopeViewModel
ScopeViewModel.cs
namespace mvcCookieAuthSample.ViewModels
{
public class ScopeViewModel
{
public string Name { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
public string Emphasize { get; set; }
public string Required { get; set; }
public bool Checked { get; set; }
}
}
这个定义来自于 IdentityServer4 官方文档中 Identity Resource 和 API Resource 的模型
https://identityserver4.readthedocs.io/en/latest/reference/identity_resource.html

ConsentViewModel.cs
namespace mvcCookieAuthSample.ViewModels
{
public class ConsentViewModel
{
public string ClientId { get; set; }
public string ClientName { get; set; }
public string ClientLogoUrl { get; set; }
/// <summary>
/// 是否允许第二次登录不需要再次授权
/// </summary>
public bool AllowRemeberConsent { get; set; }
// 对两种用户分别做出选择
public IEnumerable<ScopeViewModel> IdentityScopes { get; set; }
public IEnumerable<ScopeViewModel> ResourceScopes { get; set; }
}
}
接下来需要把两个 ViewModel 的信息显示在 Index 里面,实现类似微博授权页面

_ScopeListitem.cshtml
@using mvcCookieAuthSample.ViewModels;
@model ScopeViewModel
<li>
</li>
Index.cshtml
@using mvcCookieAuthSample.ViewModels;
@model ConsentViewModel
<p>Consent Page</p>
<div class="row page-header">
<div class="col-sm-10">
@if (string.IsNullOrWhiteSpace(Model.ClientLogoUrl))
{
<div><img src="@Model.ClientLogoUrl"/></div>
}
<h1>
@Model.ClientName
<small>希望使用您的账户</small>
</h1>
</div>
</div>
<div class="row">
<div class="col-sm-8">
<form asp-action="Index">
@if (Model.IdentityScopes.Any())
{
<ul class="list-group">
@foreach (var scope in Model.IdentityScopes)
{
@Html.Partial("_ScopeListitem", scope)
}
</ul>
}
@if (Model.ResourceScopes.Any())
{
<ul class="list-group">
@foreach (var scope in Model.IdentityScopes)
{
@Html.Partial("_ScopeListitem", scope)
}
</ul>
}
</form>
</div>
</div>
上半部分展示图标和提示,下半部分分为三部分,分别列出 IdentityScopes 和 ResourceScopes,以及选择是否记住,最后实现授权
课程链接
http://video.jessetalk.cn/course/explore


本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。
欢迎转载、使用、重新发布,但务必保留文章署名 郑子铭 (包含链接: http://www.cnblogs.com/MingsonZheng/ ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。
如有任何疑问,请与我联系 (MingsonZheng@outlook.com) 。
ASP.NET Core分布式项目实战(Consent视图制作)--学习笔记的更多相关文章
- ASP.NET Core分布式项目实战
ASP.NET Core开发者成长路线图 asp.net core 官方文档 https://docs.microsoft.com/zh-cn/aspnet/core/getting-started/ ...
- 【笔记目录1】ASP.NET Core分布式项目实战
当前标签: ASP.NET Core分布式项目实战 共2页: 1 2 下一页 35.Docker安装Mysql挂载Host Volume GASA 2019-06-20 22:02 阅读:51 评论 ...
- 【笔记目录2】ASP.NET Core分布式项目实战
当前标签: ASP.NET Core分布式项目实战 共2页: 上一页 1 2 11.ClientCredential模式总结 GASA 2019-03-11 12:59 阅读:26 评论:0 10. ...
- 【ASP.NET Core分布式项目实战】(三)整理IdentityServer4 MVC授权、Consent功能实现
本博客根据http://video.jessetalk.cn/my/course/5视频整理(内容可能会有部分,推荐看源视频学习) 前言 由于之前的博客都是基于其他的博客进行开发,现在重新整理一下方便 ...
- ASP.NET Core分布式项目实战-目录
前言 今年是2018年,发现已经有4年没有写博客了,在这4年的时光里,接触了很多的.NET技术,自己的技术也得到很大的进步.在这段时光里面很感谢张队长以及其他开发者一直对.NET Core开源社区做出 ...
- 【ASP.NET Core分布式项目实战】(二)oauth2 + oidc 实现 server部分
本博客根据http://video.jessetalk.cn/my/course/5视频整理(内容可能会有部分,推荐看源视频学习) 资料 我们基于之前的MvcCookieAuthSample来做开发 ...
- 【ASP.NET Core分布式项目实战】(五)Docker制作dotnet core控制台程序镜像
Docker制作dotnet core控制台程序镜像 基于dotnet SDK 新建控制台程序 mkdir /home/console cd /home/console dotnet new cons ...
- 【ASP.NET Core分布式项目实战】(六)Gitlab安装
Gitlab GitLab是由GitLabInc.开发,使用MIT许可证的基于网络的Git仓库管理工具,且具有wiki和issue跟踪功能.使用Git作为代码管理工具,并在此基础上搭建起来的web服务 ...
- 【ASP.NET Core分布式项目实战】(一)IdentityServer4登录中心、oauth密码模式identity server4实现
本博客根据http://video.jessetalk.cn/my/course/5视频整理 资料 OAuth2 流程:http://www.ruanyifeng.com/blog/2014/05/o ...
- 【ASP.NET Core分布式项目实战】(四)使用mysql/mysql-server安装mysql
Docker安装Mysql 拉取镜像 docker pull mysql/mysql-server 运行mysql docker run -d -p : --name mysql01 mysql/my ...
随机推荐
- vscode如何优雅的拥抱eslint
https://www.toutiao.com/a6826129210260587019/?tt_from=weixin&utm_campaign=client_share&wxsha ...
- Redis 常用五种数据类型编码
转载请注明出处: 目录 Redis 的五种数据结构 Redis 数据结构的内部编码 1.String 1.1 常用命令 1.2 内部编码 1.3 典型使用场景 2. Hash 2.1 常用命令及时间复 ...
- java中native源码查找方法
以Object的hashCode()方法为例: 1. 下载openjdk源码或从github中查找,这里以github中查找为例:2. GitHub中查找https://github.com/bpup ...
- Redis-逻辑库-select
- [转帖]MySQL的版本情况
Introducing MySQL Innovation and Long-Term Support (LTS) versions (oracle.com) Introducing MySQL Inn ...
- [转帖]dd - Linux世界中的搬运工
<存储工具系列文章>主要介绍存储相关的测试和调试工具,包括不限于dd.fio.vdbench.iozone.iometer.cosbench等性能负载工具,及strace等调试工具. dd ...
- Linux 处理CPU和内存参数的方式总结
Linux 处理CPU和内存参数的方式总结 关闭NUMA,关闭透明大页 比较简单的方法: vim /etc/default/grub 在 GRUB_CMDLINE_LINUX 里面添加配置: tran ...
- [转帖]Linux IO调度之队列、队列深度
有关数据结构 请求队列:struct request_queue 请求描述符:struct request 队列深度 可以在端口队列中等待IO请求数量: 具体代表其值的是request_queue的成 ...
- redis 6源码解析之 object
redis对象作为redis存储的基本单元,对应redisDb->dict 中的dictEntry->key和dictEntry->val. 更全面的图谱 源码解析参见:object ...
- rust入坑指南之ownership
作者:京东零售 王梦津 I. 前言 Rust,不少程序员的白月光,这里我们简单罗列一些大牛的评价. Linus Torvalds:Linux内核的创始人,对Rust的评价是:"Rust的主要 ...