前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ASP.NET Core分布式项目实战(运行Consent Page)--学习笔记

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

作者头像
郑子铭
发布2021-01-13 15:38:37
3590
发布2021-01-13 15:38:37
举报

任务21:运行Consent Page

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

修改 ConsentController 的 Index 为异步
代码语言:javascript
复制
[HttpGet]
public async Task<IActionResult> Index(string returnUrl)
{
    var model = await BuildConsentViewModel(returnUrl);

    if (model == null)
    {

    }

    return View(model);
}
构造函数改为 public
代码语言:javascript
复制
public ConsentController
Index.cshtml 添加用户信息和 icon
代码语言:javascript
复制
@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
代码语言:javascript
复制
@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 中补充客户端信息
代码语言:javascript
复制
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,不然看不到图片

代码语言:javascript
复制
@if (!string.IsNullOrWhiteSpace(Model.ClientLogoUrl))

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

课程链接

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

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-05-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DotNet NB 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 任务21:运行Consent Page
    • 修改 ConsentController 的 Index 为异步
      • 构造函数改为 public
        • Index.cshtml 添加用户信息和 icon
          • _ScopeListitem.cshtml
            • 在 Config 的 GetClients 中补充客户端信息
            • 课程链接
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档