Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping Simple Membership OAuth Session Alive

We are using the Simple Membership Provider with ASP.NET MVC 4, and we're using the Facebook Client to provide Facebook login support (similar to http://www.asp.net/mvc/overview/getting-started/using-oauth-providers-with-mvc).

We have gotten this working, but the session always times out within a day, and we want the login to be persistent, so the user can login and use the service just once.

In the out-of-the-box ExternalLoginCallback function, I am attempting to set the createPersistentCookie parameter to true, but it won't keep the login alive. Here is the call I am making:

OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: true)

Am I going to have to set the Forms Authentication cookie manually in order to accomplish a persistent login? Or is there another way of doing this while still taking advantage of the out-of-the-box Facebook login functionality?

like image 388
BlueSam Avatar asked Oct 21 '22 14:10

BlueSam


1 Answers

The ASPXAUTH cookie is used to determine if a user is authenticated. You can track expiration time with firebug or any other web debug tool. In your project the cookie is set in ExternalLoginCallback. Here is example screen setting cookies' expiration timeout.

All what I had to do to make it work was to use SSL, and change cookie timeout in web.config. Here is example with timeout set to 1 minute. Don't forget to mark requireSSL on true.

<authentication mode="Forms">
   <forms loginUrl="~/Account/Login" timeout="1" requireSSL="true"/>
</authentication>

But in your case i believe the problem is with short live access token from facebook(default around 2h). In case if the problem is with access token here is link how to extend lifetime of access token.

like image 123
jan salawa Avatar answered Nov 02 '22 07:11

jan salawa