Solved

Forms Authenticaition and Connect using Facebook or Twitter

Posted on 2010-11-09
4
670 Views
Last Modified: 2012-05-10
Hey all,

We are developing a website that has standard forms authentication access to the underlying member system - nothing out of ordinary here!

How do we now integrate connecting using Facebook and/or Twitter?
Does anyone have experience with this and can point us in right direction.

We are just not sure what you do after you authenticate with Facebook/Twitter REST API - how do you assign forms authentication ticket?
Do you have to store the Facebook and Twitter details against the user account?

Would love to hear any commentary on this - much appreciated!

Thanks for your time.

Cheers.
Steve
0
Comment
Question by:smacca
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:VincentSG
ID: 34099904
Hi!

I assume you know how to authenticate with Facebook and Twitter using their respective API.

After you have authenticated the user, you can set your own cookie using

FormsAuthentication.RedirectFromLoginPage(facebookUserId, IsPersistent); // redirect to default logged in page

or

FormsAuthentication.SetAuthCookie(facebookUserId, false); // If you do not need to redirect to another page

More information can be seen here:
1) http://msdn.microsoft.com/en-us/library/ka5ffkce(v=VS.90).aspx
2) http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.setauthcookie(v=VS.90).aspx
3) http://msdn.microsoft.com/en-us/library/ff647070.aspx
0
 

Author Comment

by:smacca
ID: 34100649
Hi,

Thanks for the great examples and comments.

You have given fantastic direction but we are unsure of how the Facebook username associates with the underlying authentication module.
Normally, we would:

  1. Pass username to .net forms authentication (as with your example)
  2. Use the Application Authentication events to check the user details and assign roles to the Principal.

However, when you use Facebook and/or Twitter authentication, these details have no relation to our underlying system (e.g. roles - admin, user, guest).
So, do we:

  1. Have user login to the members area.
  2. Have them authenticate with Facebook/Twitter and then STORE their details against their member information (account).
  3. Then, when they return and sign-in with Facebook/Twitter we simply LOOKUP member account information using the Facebook/Twitter ID.
  4. Then, get their native username and authenticate as you would normally (as well as reassigning userid to the native one for identity, principal and context)


Hope this makes sense as I would really love to get on top of this algorithm.

Thanks kindly for your time.

Steve

 
0
 
LVL 5

Accepted Solution

by:
VincentSG earned 500 total points
ID: 34101425
Hi Steve,

If you want to authenticate the users with Facebook / Twitter directly (as in do not need to register with your site) , I would suggest:

1) Redirect to Facebook / Twitter login using their respective API. Once login is successful, then they will return a token, which I think is a GUID or user name, anyway you can treat it as a string.

2) Check the token with your database. If found, then proceed as usual. You should already have this user's profile in your database - whether he is a member or administrator.

3) Else you can go through the "Registration", for example, creating the entry in your own database and if necessary, ask the user a few questions to determine the type of user he is, for example, ask him to enter a code to prove he is admin or ask him to pay to access the premium section. This part is really your application design.


I hope this helps. Let me know if you need further explanation.


Best regards,
Vincent
0
 

Author Closing Comment

by:smacca
ID: 34105295
Great feedback. Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Shared Service Environment 2 54
asp.net mvc5 6 34
Put File 6 37
C# How to display the first five answers that have smallest value? 16 43
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question