简体   繁体   中英

Facebook Login using MembershipProvider and RoleProvider in ASP.net mvc 3

I would like users to login to my site using only their Facebook credentials. I would like to have a FacebookMembershipProvider class that extends the MembershipProvider class. This way I can still use the built in security features of ASP.net such as : [Authorize(roles = "Admin")]

Has anyone tried this? How did you implement it?

One approach would be to log in with Facebook and then create an associated membership account, I am looking at some of the code in the microsoft-web-helpers package for web matrix and their facebook helpers seem to support this approach.

This way you can still use the default Membership and role providers.

You don't create a custom membership provider though since Facebook login doesn't work like that. Instead of using username and password you use the facebook api which returns an authentication token. Having validated the authentication token, you can store their Facebook ID using FormsAuthentication.SetAuthCookie(Username, Persist) . This will then work as expected with Role providers and [Authorize] tags etc. You may still wish to create a custom role provider though as it will allow for a simpler database schema and will probably be more suited given the lack of a need to store usernames and passwords.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM