美文网首页
Identity Server 4 学习(四)—— 完善客户端

Identity Server 4 学习(四)—— 完善客户端

作者: 寻找无名的特质 | 来源:发表于2021-11-08 06:58 被阅读0次

    我们还需要完善客户端,首先增加Logout功能,这非常简单,首先增加一个Logout页面,只需要一行代码就可以解决问题:

        public class LogoutModel : PageModel
        {
            public IActionResult OnGet()
            {
                return SignOut("Cookies", "oidc");
            }
        }
    }
    

    然后在Layout中增加指向这个页面的链接:

    <a class="nav-link text-dark" asp-area="" asp-page="/Logout">Logout</a>
    

    这样就可以了,登出完成的页面跳转到认证中心,其中有返回网站的链接。

    还有一个需要完善的是现在显示的Claims不包括我们需要的用户信息,比如用户名等等,这需要在AddOpenIdConnect中增加如下代码:

                        options.Scope.Add("profile");
                        options.GetClaimsFromUserInfoEndpoint = true;
    

    这样,就可以获取用户的详细信息了。

    还有一个需要注意的是,诸如Edge等浏览器只能使用https访问,否则会出错。

    相关文章

      网友评论

          本文标题:Identity Server 4 学习(四)—— 完善客户端

          本文链接:https://www.haomeiwen.com/subject/iaskzltx.html