asp.net mvc 5 - Azure Mobile Services custom authentication with MVC5 -


i've setup custom authentication process azure mobile services , windows phone 8.1 app (following guide here)

i'm creating mvc5 single page application (spa) manage admin side of things system. i'm relatively new mvc5 , need little started performing login in phone app?

currently phone app performs login by

app.mobileservice.currentuser = await authenticateasync(this.textbox_email.text, textbox_password.password); 

which does

    private async task<mobileserviceuser> authenticateasync(string username, string password)     {          // call customlogin api , set returned mobileserviceuser         // current user.         var user = await app.mobileservice             .invokeapiasync<loginrequest, mobileserviceuser>(             "customlogin", new loginrequest()             {                 username = username,                 password = password             });          return user;     } 

this works guess question how do make call customer authentication api in same way in mvc5 , set user context if successful?

startup.auth.cs:

 public partial class startup {            public void configureauth(iappbuilder app)     {         // enable application use cookie store information signed in user         app.usecookieauthentication(new cookieauthenticationoptions         {             authenticationtype = defaultauthenticationtypes.applicationcookie,             loginpath = new pathstring("/account/login")         });         // use cookie temporarily store information user logging in third party login provider         app.useexternalsignincookie(defaultauthenticationtypes.externalcookie);          // uncomment following lines enable logging in third party login providers         //app.usemicrosoftaccountauthentication(         //    clientid: "",         //    clientsecret: "");          //app.usetwitterauthentication(         //   consumerkey: "",         //   consumersecret: "");          //app.usefacebookauthentication(         //   appid: "",         //   appsecret: "");          //app.usegoogleauthentication();     } 

let me know if i'm missing info or detail. thanks!

unfortunately not easy in mobile services. while achieve login using mobile services html/js sdk (served in mvc view), not set user context.

because of mobile services incompatibility mvc (addressed in new mobile apps product), won't able rely on sdk. unfortunately means writing custom middleware/filters.

the easiest solution package username/password validation , storage logic code can shared mobile services project , mvc project. mvc project need take validated user , issue session cookie read custom middleware or filter.

writing authorizationfilter implementation easier owin middleware, recommend approach. check if cookie present , valid, , if set user context.


Comments