微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net-mvc – 在Owin Identity和Asp.Net MVC中正确使用声明类型

我正在使用Owin和身份认证,而且我在索赔中遇到问题.

我有一个应用程序,用户使用电子邮件进行身份验证,而其他用户使用用户名.

>业务层的登录方式可以根据情况接受电子邮件用户名.
>要显示具有用户信息的页面时,为了“模糊”用户身份,我使用每个用户唯一的GUID.

我也使用这个,因为有时一个电子邮件用户名可能是一个问题在url …

当我签署一个用户时,我有以下声明类型:

new Claim(ClaimTypes.Email,user.Email),new Claim(ClaimTypes.Name,user.FullName),new Claim(ClaimTypes.Givenname,user.FirstName),new Claim(ClaimTypes.Surname,user.LastName),new Claim(ClaimTypes.NameIdentifier,user.UserUniqueIdentifier.ToString())

所以我的解释是:

Email is the user's email

Name is the user's full name

Givenname is the user's first name

Surname is the user's last name

NameIdentifier is the user's unique identifier ... It can be the email,the username or in this case I am using an Unique ID.

什么是奇怪的是没有用户名的声明类型.放在哪里?

基本上,当用户名不被用作唯一的名称标识符但仍然有必要时,似乎有问题.

我的逻辑索赔类型有问题吗?

解决方法

应该使用ClaimTypes.Name(http:// schemas.xmlsoap.org/ws/2005/05/identity/claims/name)作为用户名.

Claims.NameIdentifier通常用于用户的ID.在某些情况下,它可能是一个用户名.

ASP.NET身份使用ClaimTypes.Name存储用户名,Claims.NameIdentifier存储用户的主键GUID.

原文地址:https://www.jb51.cc/aspnet/246387.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐