App with no DB: You must call the "WebSecurity.InitializeDatabaseConnection" method before you call any other method of the "WebSecurity" class

StackOverflow https://stackoverflow.com/questions/18376023

Pregunta

First things first. I'm a complete OAuth newbie. This will be my first stab at it, and things are getting hairy...

I'm writing a single page application using Durandal & Web API. The user needs to be able to login using any social network. I don't have access to a database whatsoever, I have to call an unprotected 3rd party web service which I consume server-side, and need to protect using OAuth.

So I've managed to add the files to my solution which generates the login using facebook contol/button (created a new MVC4 web application, and did a manual copy and paste of all the auth related files, updated bootstrappers etc..), and the code seems to work for the most part.

When facebook redirects back to

 [AllowAnonymous]
 public ActionResult ExternalLoginCallback(string returnUrl)
 {
     AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(this.Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
     if (!result.IsSuccessful)
     {
        return this.RedirectToAction("ExternalLoginFailure");
     }

     if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false))
     {
        return this.RedirectToLocal(returnUrl);
     }

        //code removed for brevity       ....
  } 

I get the error specified once the following line tries to execute.

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

I've removed the [InitializeSimpleMembership] attribute from the controller, as I don't have a database.

Please forgive me if this is the dumbest question ever, but...

Why does the login fail? I mean at that point, isn't the app trying to log into facebook, why does it need a databse? Or am I correct in saying I can remove/replace that code section, with a login/authorise call on the web-service I'm using?

¿Fue útil?

Solución

Not the dumbest question ever. Not by a long shot. But you are getting the error because your membership provider is still set to use the SimpleMembershipProvider and OAuthWebSecurity will use the default membership provider. If you don't want to use a database you will have to create or find a different membership provider to use.

EDIT: I know you said you don't have access to a DB but if you can use SQL Compact you can just stick with the default SimpleMembershipProvider(check out Hanselman's blog) or DevArt has a SQLLite provider. Also the MemFlex Project has a RavenDb provider. If none of those work I think you might just have to write your own.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top