Facebook Connect with Membership API

May 2, 2009 at 11:08 PM
Hello,
I have create a Facebook Connect sample similar to the example shown in the URL http://devtacular.com/articles/bkonrad/how-to-retrieve-user-data-from-facebook-connect-in-aspnet/

However, after the user logs in using Facebook I want to link the user Id returned from the Facebook API and create a local account on my application using the Membership API.

Is there a way to do this?

any help would be appreciated

Thanks
Anup
Nov 18, 2010 at 8:21 PM

I'm interested in this as well. Does anyone have a good example they'd be willing to share on how to use Facebook Connect as a login session along with a website already using the ASP.net membership provider?

Nov 23, 2010 at 2:30 PM

I don't think it's a good idea to register a .NET user when someone logs in with Facebook Connect. Think of then having to manage that user, say if someone changes their Facebook name or other public information. I think your much better off changing the way your application behaves if a Facebook user signs in.

You can use the FBUID as the asp.net auth token:

Facebook.Session.ConnectSession session = new Facebook.Session.ConnectSession(APIKey, APISecret);

Facebook.Rest.Api api = new Facebook.Rest.Api(session);

api.Session.SessionKey = ConnectAuthentication.SessionKey;
api.Session.UserId = ConnectAuthentication.UserID;

Facebook.Schema.user user = api.Users.GetInfo();

// You can store facebook data in a local table now by making API calls. For instance you migth want to store FBUID and name so you dont have to do API calls later in the session.

FormsAuthentication.SetAuthCookie(user.uid.Value.ToString(), false);

Response.Redirect("wherever.aspx"); 

The only downside is if you have User.Identity being shown on the page anywhere you will have to go get the FB name, whether that means you make an API call, stored data, or some sort of session variable.

              

Nov 23, 2010 at 2:37 PM

ny2244111, Thanks for your reply. This makes sense.

I'm still new to the whole idea of using the Facebook api. If I have a 'sign in' page that ask a user to either login with the website login OR click a button to use Facebook connect... How do I set up the Facebook connect button to ask the user to 'Allow' my website to authenticate with the user's Facebook account?? Do you have an example of how this works? (or is there a sample of this already provided in the toolkit download).