How to integrate OpenId with ASP.Net Membership in MVC

后端 未结 2 1290
失恋的感觉
失恋的感觉 2020-12-29 00:21

I am using the following code from MVC Storefront to test OpenId in MVC. How do I integrate it with my ASP.Net Membership so I can use roles and save a user name for

相关标签:
2条回答
  • 2020-12-29 00:53

    The open id provider will return data about the user. If you don't request/require specific tokens of information, then all you'll be given is the user's display name and identity URL.

    Depending on what open id library you're using, you can request tokens like FirstName LastName, DOB (if you really cared) and if the user provided that information on their chosen identity, then you'd get it returned to you.

    You can then use this to create a new user in the membership system. You'll probably have to give them a dummy password to get around the requirements of the Membership API.

    To validate a login, provide 1 form that takes username & password and the other that takes an identity URL. After you've validated the user via open id, try to find the user by username (identity url) in the Membership API. If it doesn't exist, create it.

    0 讨论(0)
  • 2020-12-29 01:04

    There are several questions like yours already on StackOverflow. This one seems particularly similar.

    If you're already using the Membership provider for your site and are just adding OpenID to it, then I guess you're stuck with Membership for now and can use one of the answers to the question I linked to to get a semi-decent membership provider that MAY work for you.

    But if you're writing a new site and just want "use roles and save a user name for the user in my tables" as you said, then DON'T use ASP.NET Membership at all. It's SO not worth it! It doesn't fit OpenID's password-less paradigm and just causes more grief than anything else. If you're not afraid of a little bit of database access yourself, do it that way. And you can get Roles behavior very easily by just issuing your own FormsAuthentication.RedirectFromLoginPage or FormsAuthentication.SetAuthCookie call and passing in the roles the user fills.

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