Using Claims Types properly in Owin Identity and Asp.Net MVC

前端 未结 2 760
旧巷少年郎
旧巷少年郎 2021-02-02 09:41

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.

相关标签:
2条回答
  • 2021-02-02 10:23

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

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

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

    0 讨论(0)
  • 2021-02-02 10:37

    If you examine what Facebook or Google return from oAuth you will see that ClaimTypes.Name is ClaimTypes.GivenName + ClaimTypes.Surname. LinkedIn returns then concatenated and I believe this is a bug because I have a completely different username there. Twitter returns username for ClaimTypes.Name, but Twitter is a special case and they do not even return email.

    All of them are using some opaque numeric identifier for ClaimTypes.NameIdentifier. And they use their own string names, usually starting with urn:facebook:link, urn:google:profile, etc for custom data.

    Asp.NET Identity model uses UserName for ClaimTypes.Name. The bottom line is that ClaimTypes.Name is used differently in practice. You could add any claim name as a string and could add the urn:... scheme to make it unambiguous.

    0 讨论(0)
提交回复
热议问题