1-在授权服务端建立相应的显示ViewModel

namespace MvcCookieAuthSample.Models
{public class ConsentViewModel{public string ClientId { get; set; }public string ClientName { get; set; }public string Client { get; set; }public string ClientLogUrl { get; set; }public bool AllowRememberConsent { get; set; }public string ClientUrl { get; set; }public IEnumerable<ScopeViewModel> IdentityScopes { get; set; }public IEnumerable<ScopeViewModel> ResourceScopes { get; set; }}
}

namespace MvcCookieAuthSample.Models
{public class ScopeViewModel{public string Name { get; set; }public string DisplayName { get; set; }public string Description { get; set; }public bool Emphasize { get; set; }public bool Required { get; set; }public bool Checked { get; set; }}
}

2-新建相应的授权页ConsentController,

using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using IdentityServer4.Test;
using IdentityServer4.Services;
using IdentityServer4.Stores;
using MvcCookieAuthSample.Models;
using IdentityServer4.Models;namespace MvcCookieAuthSample.Controllers
{public class ConsentController:Controller{private readonly IClientStore _clientStore;private readonly IResourceStore _resourceStore;private readonly IIdentityServerInteractionService _identityServerInteractionService;public ConsentController(IClientStore clientStore,IResourceStore resourceStore,IIdentityServerInteractionService identityServerInteractionService ){_clientStore = clientStore;_resourceStore = resourceStore;_identityServerInteractionService = identityServerInteractionService;}public async Task<IActionResult> Index(string returnUrl){Models.ConsentViewModel model = await BuildConsentViewModel(returnUrl);if (model == null){}return View(model);}private async Task<ConsentViewModel> BuildConsentViewModel(string returnUrl){var request = await _identityServerInteractionService.GetAuthorizationContextAsync(returnUrl);if (request == null)return null;var client = await _clientStore.FindEnabledClientByIdAsync(request.ClientId);var resources = await _resourceStore.FindEnabledResourcesByScopeAsync(request.ScopesRequested);return CreateConsentViewModel(request, client, resources);}private ConsentViewModel CreateConsentViewModel(AuthorizationRequest request, Client client, Resources resources){var vm = new ConsentViewModel();vm.ClientName = client.ClientName;vm.ClientLogUrl = client.LogoUri;vm.ClientUrl = client.ClientUri;vm.AllowRememberConsent = client.AllowRememberConsent;vm.IdentityScopes = resources.IdentityResources.Select(i=>CreateScopeViewModel(i));vm.ResourceScopes = resources.ApiResources.SelectMany(i=>i.Scopes).Select(i=>CreateScopeViewModel(i));return vm;}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};}}
}

3-编写相应的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>@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>}</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" /><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>

5-Config.cs

namespace MvcCookieAuthSample
{public class Config{public static IEnumerable<ApiResource> GetApiResources() {return new List<ApiResource>() {new ApiResource("api1","api DisplayName")};}public static IEnumerable<Client> GetClients(){return new List<Client>() {new Client(){ClientId="mvc",ClientName="mvc Name",ClientUri="http://localhost:5001",AllowRememberConsent=true, AllowedGrantTypes= GrantTypes.Implicit,ClientSecrets= new List<Secret>(){new Secret("secret".Sha256())},RedirectUris = {"http://localhost:5001/signin-oidc" },PostLogoutRedirectUris = { "http://localhost/signout-callback-oidc"},RequireConsent=true,//启用客户端手动授权AllowedScopes={IdentityServerConstants.StandardScopes.Profile,IdentityServerConstants.StandardScopes.OpenId,}}};}public static IEnumerable<IdentityResource> GetIdentityResources(){return new List<IdentityResource>() {new IdentityResources.OpenId(),new IdentityResources.Email(),new IdentityResources.Profile()};}public static List<TestUser> GetTestUsers(){return new List<TestUser>() {new TestUser(){SubjectId="oa001",Username="qinzb",Password="123456"}};}}
}

6-显示结果

转载于:https://www.cnblogs.com/qinzb/p/9532445.html

19-21Consent Page页实现相关推荐

  1. mysql page_一文理解MySQL中的page页

    在介绍InnoDB中的页的时候,很有必要先让大家了解一下InnoDB中的存储结构 从InnoDB存储引擎的逻辑结构看,所有数据都被逻辑地存放在一个空间内,称为表空间(tablespace),而表空间由 ...

  2. Mysql中Page(页)和结构的认识

    文章目录 一.Page--页 一.Page Directory(记录在页中的展现) 二.B数 & B+树 一.B树和B+树的区别 三.Index--索引 1.聚簇索引--主键 2.二级索引-- ...

  3. Cadence Orcad Capture 疑难问题解答2:每次启动都会有个“Start Page”页图文教程

      

  4. 复合页( Compound Page )

    复合页(Compound Page)就是将物理上连续的两个或多个页看成一个      独立的大页,它可以用来创建hugetlbfs中使用的大页(hugepage),      也可以用来创建透明大页( ...

  5. mysql 页和叶子页_Mysql —— 页与索引

    一.前言 之前了解过Mysql中索引的数据结构,但是看得非常浅显,仅仅知道索引底层实现的数据结构是 B+ tree,以及B+ tree 简单的增加节点和删除节点.但是对一些细节问题依然不太明白,在此借 ...

  6. 如何设置word页码 第几页共几页 从第二页算起

    一.要实现的效果 (1)假设你有一个20页的文档,本文的目的是要实现在页脚中自动填充格式为 "第X页,共X页" 的页码: (2)且首页不显示页码: (3)同时 "共X页& ...

  7. Word2019设置页脚页码

    第一步:先将页脚设置为"第X页,共10页"的格式. 1.双击页脚,输入文字 "第 页,共 页",居中对齐: 2.光标点入"第"和" ...

  8. vue+ts在线文档编辑(类腾讯文档)多人在线编辑-自定义页眉和分页打印(三)

    目录 前言 一.自定义页眉内容 二.分页文档打印 1.加入分页符 2.打印方法 3.打印模块完整代码 总结 前言 随着在线办公场景越来越多,同时需要各式各样办公软件,在开发时就用得到在线文档来内容指定 ...

  9. linux内核设计与实现--19章 可移植性

    可移植的操作系统尽可能少的涉及与机器相关的代码,为了支持不同的体系结构,界面和功能在定义时尽最大可能的有普遍性和抽象性.一个一致性非常高而本身有比较简单的操作系统在支持新的体系结构时,可能只需修改很少 ...

  10. phppage类封装分页功能_封装page分页类

    类: //分页工具类 class Page{ /* * 获取分页字符串 * @param1 string $uri,分页要请求的脚本url * @param3 int $counts,总记录数 * @ ...

最新文章

  1. java Servlet学习笔记
  2. srm linux字符界面,如何使用srm安全的删除Linux中的文件
  3. Reroute Unassigned Shards——遇到主shard 出现的解决方法就是重新路由
  4. 关于equals和hashcode方法
  5. 100c之29:求具有abcd= ( ab + cd )^2 性质的四位数
  6. Web加固linux,Linux系统下web服务器的加固
  7. 华军java_Java SE Runtime Environment 8
  8. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_6-1.常用的第三方支付和聚合支付介绍...
  9. iis服务器网站启动不了,IIS上打不开asp网站怎么办
  10. 迷你聊天室_简介:聊天机器人与我们的第一个迷你课程
  11. 一些常见html5语义化标签
  12. MFC__ZPL语言Zbor打印机打印数据换行问题
  13. 程序员必备的七个电脑软件
  14. 最新雷速问卷调查系统V7.15+ASP内核开发
  15. eclipse+ADT使用第三方静态库及COCOS2d问题汇总
  16. 2021微信大数据挑战赛总结(微信视频号推荐)
  17. ElasticSearch索引生命周期管理(ILM)
  18. Ajax Interceptor工具分享
  19. C语言class 1:初识与准备
  20. One PUNCH Man——降维

热门文章

  1. 【Google Paper】对比学习用于解决推荐系统长尾问题
  2. 12306 验证码识别源码
  3. VirtualBox升级VirtualBox Guest Additions增强功能
  4. vue项目中如何简单的读取声音文件
  5. css改变透明背景png图片的图标颜色
  6. linux基础知识总结(二)
  7. 【EduCoder答案】HTML——表单类的标签
  8. 数十位院士/大咖亮相,近千人到场交流,物联网人年终必聚的产业盛会来了!...
  9. conda删除环境 显示cannot remove current environment. deactivate and run conda remove again
  10. 简单的CSS3动画案例——奔跑的熊哥