22-Consent 确认逻辑实现
1-定义一个从前台传到后台的viewModel
namespace MvcCookieAuthSample.Models
{
public class InputConsentViewModel
{
public string Button { get; set; } public IEnumerable<string> ScopesConsented { get; set; } public bool RemeberConsent { get; set; } public string ReturnUrl { get; set; } }
}
2-确定逻辑实现
[HttpPost]
public async Task<IActionResult> Index(InputConsentViewModel viewModel)
{
ConsentResponse consentResponse = null;
if (viewModel.Button == "no")
{
consentResponse = ConsentResponse.Denied;
}
else if (viewModel.Button == "yes")
{
if(viewModel.ScopesConsented!=null && viewModel.ScopesConsented.Any())
{
consentResponse = new ConsentResponse {
ScopesConsented=viewModel.ScopesConsented,
RememberConsent = viewModel.RemeberConsent
}; }
}
if (consentResponse != null)
{
var request = await _identityServerInteractionService.GetAuthorizationContextAsync(viewModel.ReturnUrl);
await _identityServerInteractionService.GrantConsentAsync(request, consentResponse);
return Redirect(viewModel.ReturnUrl);
} return View();
}
3-前台consent/index.cshtml
@using MvcCookieAuthSample.ViewModel;
@model ConsentViewModel <div class="row page-header">
<div class="col-sm-10">
@if (string.IsNullOrWhiteSpace(Model.ClientLogUrl))
{
<div>
<img src="@Model.ClientLogUrl" />
</div>
}
<h1>
@Model.ClientName
<small>希望使用你的账号</small>
</h1>
</div> </div> <div class="row">
<form method="post" asp-route-ReturnUrl="@Model.ReturnUrl">
@if (Model.IdentityScopes.Any())
{ <div class="panel">
<div class="panel-heading">
<span class="glyphicon glyphicon-tasks"></span>
identity应用权限
</div> <ul class="list-group"> @foreach (var scope in Model.IdentityScopes)
{
@await Html.PartialAsync("_ScopeListItem", scope);
}
</ul>
</div> } @if (Model.ResourceScopes.Any())
{
<div class="panel">
<div class="panel-heading">
<span class="glyphicon glyphicon-tasks"></span>
resource应用权限
</div> <ul class="list-group">
@foreach (var scope in Model.ResourceScopes)
{
await Html.PartialAsync("_ScopeListItem", scope);
}
</ul>
</div> }
<div>
<button value="yes" name="button" class="btn btn-primary" autofocus>同意</button>
<button value="no" name="button" >取消</button> @if (!string.IsNullOrEmpty(Model.ClientUrl))
{
<a href="@Model.ClientUrl" class="pull-right btn btn-default">
<span class="glyphicon glyphicon-info-sign" ></span>
<strong>@Model.ClientUrl</strong>
</a> }
</div>
</form>
</div>
4 _scopeListItem.cshtml
@*
For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
*@
@using MvcCookieAuthSample.ViewModel;
@model ScopeViewModel <li>
<label>
<input type="checkbox"
name="ScopesConsented"
id="scopes_@Model.Name"
value="@Model.Name"
checked="@Model.Checked"
disabled="@Model.Required" />
@if (Model.Required)
{
<input type="hidden" name="ScopesConsented" value="@Model.Name"/> } <strong>@Model.Name</strong>
@if (Model.Emphasize)
{
<span class="glyphicon glyphicon-exclamation-sign"></span> }
</label> @if (string.IsNullOrEmpty(Model.Description))
{
<div>
<label for="scopes_@Model.Name"> @Model.Description</label>
</div>
}
</li>
22-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 评论 ...
- 【ASP.NET Core分布式项目实战】(三)整理IdentityServer4 MVC授权、Consent功能实现
本博客根据http://video.jessetalk.cn/my/course/5视频整理(内容可能会有部分,推荐看源视频学习) 前言 由于之前的博客都是基于其他的博客进行开发,现在重新整理一下方便 ...
- IdentityServer4【Topic】之确认(Consent)
Consent 确认 在授权请求期间,如果身份服务器需要用户同意,浏览器将被重定向到同意页面.也就是说,确认也算是IdentityServer中的一个动作.确认这个词直接翻译过来有一些古怪,既然大家都 ...
- 阿里云 ECS 逻辑卷挂载数据盘
查看磁盘信息: [root@ixx~]# fdisk -l Disk /dev/xvda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track ...
- 逻辑卷管理lvm
逻辑卷管理LVM 一 创建逻辑卷 1准备分区或硬盘 这里使用/dev/sdb./dev/sdc两块硬盘和/dev/sda9./dev/sda10两个分区,大小都为1G,磁盘有限,我也不想这么抠的. 添 ...
- IdentityServer4【Topic】Consent
Conset这个概念在Identityserver4中是表示要当前用户对第三方应用对资源请求的一个确认,它会被做成一个页面. 术语映射: Consent page--确认页面,我喜欢叫做Consent ...
- Linux fdisk命令详解[主分区/逻辑分区创建]
fdisk常见命令参数 -b<分区大小>:指定每个分区的大小: -l:列出指定的外围设备的分区表状况: -s<分区编号>:将指定的分区大小输出到标准输出上,单位为区块: -u: ...
- [转]物理CPU、CPU核数、逻辑CPU、超线程
转自:http://wulc.me/2016/01/06/物理CPU.CPU核数.逻辑CPU.超线程/ 基本概念 物理CPU: 物理CPU就是插在主机上的真实的CPU硬件,在Linux下可以数不同的p ...
随机推荐
- pc端配置详细 2017级机械设计新生 史浩然
品牌名称:SAMSUNG/三星 证书状态:有效 申请人名称:苏州三星电子电脑有限公司 型号:940X3K-K01 操作系统:window8.1 产品名 ...
- python 文件目录操作
在Python程序中执行目录和文件的操作 Python内置的os模块可以直接调用操作系统提供的接口函数 Python交互式命令行 >>> import os>>> ...
- .net 流(Stream) - 文件流、内存流、网络流
转自:http://www.oseye.net/user/kevin/blog/85 一.文件流 FileStream FileStream流继承与Stream类,一个FileStream类的实例实际 ...
- 【转载】Kali-linux安装之后的简单设置
1.更新软件源:修改sources.list文件:leafpad /etc/apt/sources.list然后选择添加以下适合自己较快的源(可自由选择,不一定要全部): #官方源deb h ...
- PHP面向对象(OOP)编程入门教程链接
PHP官方学习OOP: http://php.net/manual/zh/oop5.intro.php 从其他博主学习:(以下链接来源: http://blog.snsgou.com/post-41. ...
- HttpServletRequest的随手记
request对象的三个主要的方法: getParameter(String name):获取请求参数名字对应的参数值.只获取一个.如果名字对应有多个参数值的话,那么只会获取参数数组中的第一个.比如一 ...
- Many-to-many relationships in EF Core 2.0 – Part 1: The basics
转载这个系列的文章,主要是因为EF Core 2.0在映射数据库的多对多关系时,并不像老的EntityFramework那样有原生的方法进行支持,希望微软在以后EF Core的版本中加入原生支持多对多 ...
- php新闻静态化方法
$view=file_get_contents('./a.tpl'); //新闻详情页模板模式,需要数据位置定义标签如{title},{content} $php_content=str_replac ...
- springboot集成activiti工作流时容易出现的问题
No.1 启动报错 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'or ...
- java连接linux的三种方式(附执行命令)
# 本地调用使用JDK自带的RunTime类和Process类实现 public static void main(String[] args){ Process proc = RunTime.get ...