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.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....