Facebook C# MVC MVC3 store token alongside asp.net membership scenario - asp.net

Hi does someone have a link or can offer some guidance on HOW the facebook C# SDK could be used to provide access credentials to facebook along side ASP.Net membership?
Basically what i would like to do is have some kind of connect button on my profile view that when clicked opens the facebook app authorization window, if the user signs in and agrees the facebook auth cookie is returned or accessible so i can store in locally in my DB.
I originally tried to figure out how to do this using dotnetopenauth about 9 months ago and eventually gave up. ANY help is appreciated. thanks!

I haven't done it, but it shouldn't be too hard I think.
I'm assuming you already know how to "authenticate" users with Facebook using the C# SDK. At that very point where you consider them "authenticated" hook into it and perhaps use FormsAuthentication.SetAuthCookie() to manually authenticate the user from the default ASP.NET membership's perspective.

Related

Simple asp.net Facebook authentication sample

I've read tons of documentation about Facebook authentication, but anything seems to work.
I've tried everything, including Facebook C# SDK, and many other options.
My application is an asp.net 4.0 web site (outside facebook).
Does anyone have an working sample?
All i need is to authenticate a user and get basic user information such as name, surname, email and picture.
Thanks in advance!
You can use http://www.dotnetopenauth.net/ which is very good. You can also use facebook api javascript library which is very easy to use. Maybe you haven't configured your application in facebook correctly. It needs callback url. Some related questions:
Facebook/ Twitter with dotnetopenauth?
DotNetOpenAuth Get Facebook Email Address
How to log in with Facebook using DotNetOpenAuth

Using Sessions in an ASP.NET 4.0 Log-In Control

I'm currently developing a website using Visual Studio 2010. As you all might know, creating a new website here automatically adds an Account folder which contains webpages like Login.aspx, etc. I am implementing this Login.aspx which contains the ASP.NET Login control. It's now functioning the way it should but I have a few concerns.
Before, I used to create my own UI for the log-in so managing sessions is not a problem to me. But since i'm currently using the Login.aspx which has a CS file almost empty, i don't have an idea where I can start implementing my session. Meaning to say, I don't know how to check programatically if the user has been successfully logged in so I can start implementing my session.
I would very much appreciate any pointer regarding this matter.
Thanks in advance. :)
You could subscribe for the Authenticate event and perform some custom authentication logic. Also you may take a look at the following article.
There are events associate with ASP.NET Login Control that you can use to create session like OnLoggingIn. Moreover you can find more about user validation from here Validating User Credentials Against the Membership

How can I use an ASP.NET MembershipProvider to carry over users' session data stored in cookies set by ColdFusion?

I'm working on adding a new webapp to an existing website. I've been directed to write the webapp in ASP.NET. The existing website is written in ColdFusion. For the most part, the ASP.NET webapp is completely stand-alone, but it needs to interact with the ColdFusion code in one important way - if somebody logs in to the ColdFusion site, we don't want them to have to log in again when visiting an ASP.NET page.
When someone logs in to the ColdFusion site, their username is stored in a cookie, along with a login token that can be looked up in our database. My .NET is a little rusty, so I'm having trouble visualizing how the ASP.NET code should use this data. I've already written a simple MembershipProvider that can be used to log in/out out the ASP.NET app using the data in our existing database tables, which are shared with the ColdFusion code.
What I'd like to know is - how can I make sure the ASP.NET app detects the cookies set by the ColdFusion app (I imagine they'd be sent to the ASP.NET pages, since everything is hosted on one domain), and automatically logs the user in using the MembershipProvider and Forms Authentication, using the credentials supplied in the cookie? I'm thinking that putting some kind of cookie check and log in function in the Global.asax file, set to run every page load for every page... but that seems kind of clunky. Also, do people still use the Global.asax file anyway? I had thought there was a more modern method.... Also, how can I manually log someone in using Forms Authentication and a custom membership provider? Currently my code allows the user to log in using the provided login control, but I'm not sure how to log the user in without them having to do anything.
Thanks in advance for any help. Looking over the MembershipProvider tutorials and the MSDN documentation it seems to me like the answer should be staring me in the face, but for some reason I just can't see it. Maybe not enough coffee....
Not sure if this is what you're looking for:
FormsAuthentication.SetAuthCookie("the username goes here",false);
Reference
I'm a CF developer ususally, but we had to do some integration with a .NET application recently and the way we approached it was to keep the CF and .NET sessions separate but ensure that login happened on both so when the user moved from one to the other they were still logged in.
So is there perhaps a way for you to hit your ASP.NET application with a request to login a user when you login using the CF application? Perhaps you could have an iframe on the page that you can load when the CF login is complete that holds a login service for the .NET app?
This way you would not need to worry about one app server reading the other app server's cookies, instead there would be two sets of cookies, one for ASP and one for CF.
Hope that helps!
The way I would approach it, is I would have a specific page that acts as a liaison between the CF and .NET layer. That page would implement your business layer and just check to see if the Cookie is there, if so read it in, do the lookup and login the user or whatever business logic that needs to be done. How would you accomplish the login/authentication, well that’s all based on your login/authentication code.
The only link I can offer is the basic of cookies in ASP.net
http://msdn.microsoft.com/en-us/library/aa289495(v=vs.71).aspx
Edit: found another link that might be helpful.
http://www.aspnettutorials.com/tutorials/network/cookies-csharp.aspx

Has anyone written or used a Asp.NET membership provider that integrates with Facebook Connect?

I'm looking to allow Facebook Connect logins on my site, but still want to capture some user information and store it in the Profile object. Would also like to allow standard login/pass authentication, with an option to link it to your Facebook account. Much like the way many sites handle Facebook Connect...
I'm wondering if someone has something pre-written (aside from the Facebook Toolkit on CodePlex) specifically for Asp.NET Membership integration with Facebook Connect.
Related questions on StackOverflow:
Facebook Connect Integration with a site using ASP.NET Membership Provider
Facebook Connect and ASP.NET
An open source provider:
http://fbmembership.codeplex.com/

ASP.NET Windows Authentication Impersonation

I am trying to figure out how to implement an ASP.NET page with Windows Authentication without getting that annoying IIS login box.
I currently have 3 domains in my network so all the people logging in would have to prefix their user names with the domain. This is not user friendly. I would like to have a custom login page that would have a domain combo box.
Most examples I found implement this using Form security, however I need Windows Authentication since I want to connect to the SQL server using Integrated Authentication rather than a hard coded user name and password.
Does anyone know of a good article or sample code that shows how to implement this?
The following links to an article that explains how to authenticate a windows user using forms authentication, it uses a call to the native win32 api function LogonUser to acheive this. This way you can design your own custom login page with a drop down list to select a domain. Take a look, perhaps it will help.
Windows Authentication using Form Authentication
To get this setup so you don't have the authentication prompt, you are going to need to have the domains trust the accounts from one another. This article should get you pointed in the right direction:
http://technet.microsoft.com/en-us/library/cc787646%28WS.10%29.aspx

Resources