ASP.NET Core分布式项目实战(运行Consent Page)--学习笔记

任务21:运行Consent Page

修改 Config.cs 中的 RequireConsent 为 true,这样登录的时候就会跳转到 Consent 页面

修改 ConsentController 的 Index 为异步
[HttpGet]
public async Task<IActionResult> Index(string returnUrl)
{
    var model = await BuildConsentViewModel(returnUrl);

    if (model == null)
    {

    }

    return View(model);
}
构造函数改为 public
public ConsentController
Index.cshtml 添加用户信息和 icon
@if (Model.IdentityScopes.Any())
{
    <div>
        <span class="glyphicon glyphicon-user"></span>
        用户信息
    </div>
    <ul class="list-group">
        @foreach (var scope in Model.IdentityScopes)
        {
            @Html.Partial("_ScopeListitem", scope)
        }
    </ul>
}
_ScopeListitem.cshtml
@using mvcCookieAuthSample.ViewModels;
@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>

启动服务端 mvcCookieAuthSample,再启动客户端 MvcClient,登录之后跳转到 Consent 页面

如果界面出现乱码,可将文件 Index.cshtml 与 _ScopeListitem.cshtml 另存为 UTF-8 编码

在 Config 的 GetClients 中补充客户端信息
public static IEnumerable<Client> GetClients()
{
    return new List<Client>
    {
        new Client()
        {
            ClientId = "client",
            ClientName = "Client",
            ClientUri = "http://localhost:5001",
            LogoUri = "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQe9J82GNBVtbc0Co3IV63l4mQgRlMdn4lQI7cDmICHjA4VmFuv&usqp=CAU",
            AllowRememberConsent = true,
            AllowedGrantTypes = GrantTypes.Implicit,// 隐式模式
            ClientSecrets =
            {
                new Secret("secret".Sha256())
            },

            RequireConsent = true,
            RedirectUris = { "http://localhost:5001/signin-oidc" },
            PostLogoutRedirectUris = { "http://localhost:5001/signout-callback-oidc" },

            //AllowedScopes = {"api"},
            AllowedScopes =
            {
                IdentityServerConstants.StandardScopes.Profile,
                IdentityServerConstants.StandardScopes.OpenId,
                IdentityServerConstants.StandardScopes.Email,
            }
        }
    };
}

修改 Index.cshtml,不然看不到图片

@if (!string.IsNullOrWhiteSpace(Model.ClientLogoUrl))

再次启动程序,显示如下:

课程链接

http://video.jessetalk.cn/course/explore

相关文章

ASP.NET Core分布式项目实战(Consent Controller Get请求逻辑实现)--学习笔记

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&nbsp;Core分布式项目实战(第三方ClientCredential模式调用)--学习笔记

ASP.NET Core分布式项目实战(客户端集成IdentityServer)--学习笔记

ASP.NET Core分布式项目实战(业务介绍,架构设计,oAuth2,IdentityServer4)--学习笔记

ASP.NET Core分布式项目实战(课程介绍,MVP,瀑布与敏捷)--学习笔记

ASP.NET Core快速入门 -- 学习笔记汇总

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值