在Owin Identity和Asp.Net MVC中正确使用声明类型 [英] Using Claims Types properly in Owin Identity and Asp.Net MVC

查看:47
本文介绍了在Owin Identity和Asp.Net MVC中正确使用声明类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Owin和Identity,但对索偿有疑问.

I am using Owin and Identity and I am having a problem with Claims.

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

I have applications where users use an email to authenticate and others that use an username.

  1. 业务层中的登录方法可以根据情况接受电子邮件或用户名.

  1. The sign in method in the business layer can accept an Email or an Username depending on the case.

为了混淆"用户身份,我在显示带有用户信息的页面时使用了每个用户唯一的GUID.

To "obfuscate" the user identity I use a GUID, unique to each user, when displaying a page with user info.

我也使用它,因为有时电子邮件或用户名可能是url中的问题...

I also use this because sometimes an email or an username can be a problem in the url ...

我在签名用户时具有以下声明类型:

When I sign a user I have the following claims types:

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.

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

What is strange is there is no Claim Type for Username. Where would to place it?

基本上,当用户名不用作唯一名称标识符时,似乎仍然存在问题.

Basically it seems there is a problem when a Username is not used as the Unique name identifier but it is still necessary.

我的逻辑声明类型有问题吗?

Is something wrong with my logic claims types?

推荐答案

ClaimTypes.Name(http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name).

ClaimTypes.Name (http:// schemas.xmlsoap.org/ws/2005/05/identity/claims/name) should be used for the username.

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

ClaimTypes.NameIdentifier is typically used for the user's id. In some cases it could be a username.

ASP.NET Identity使用ClaimTypes.Name存储用户名,并使用ClaimTypes.NameIdentifier存储用户的主键GUID.

ASP.NET Identity uses ClaimTypes.Name to store the username, and ClaimTypes.NameIdentifier to store the primary key GUID of the user.

这篇关于在Owin Identity和Asp.Net MVC中正确使用声明类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆