Authentication with custom authenticator via Azure Mobile Services and cordova app -
Authentication with custom authenticator via Azure Mobile Services and cordova app -
i building phone app using cordova/phonegap , azure mobile services backend. need utilize custom authenticator since integrating current software product.
i built server side using info http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-get-started-custom-authentication/
i set config.setishosted(true);
in webapiconfig
from client, seem authenticating fine , getting valid token, i'm not sure it. i've tried setting client.currentuser
, api calls coming unauthorized.
here's code:
client = new windowsazure.mobileserviceclient("http://`localhost`:50523"); login = function () { client.invokeapi("customlogin", { method: "post", body: { "username": "user1", "password": "pass1" } }) .done(function (result) { var login = json.parse(result.response); client.currentuser = login.user; client.currentuser.mobileserviceauthenticationtoken = login.authenticationtoken; //lets seek i'm valid getmembers(); app.navigate("views/home.html"); }, function(error) { alert(error); }); }; getmembers = function () { client.invokeapi("member", { method: "get", body: {} }) .done( function(result) { alert(result.result[0].lname); }, function(error) { alert(error); }); };
is there more need authentication token create work? thanks!
edit: more info --
using fiddler monitor traffic, see phone call /api/member
has few headers set:
x-zumo-auth: set token got before x-zumo-features: aj x-zumo-installation-id: guid x-zumo-version: zumo/1.2(...)
ok. looked @ in detail. first, sample creating users in local azure mobile service db. assuming creating user on actual mobile service in azure. can see line of code commented out below can add together if want test. here code should want. sorry c#, should translate easy enough. note "usertodo" string customloginprovider.providername returns.
protected override async void onnavigatedto(navigationeventargs e) { logininfo dude = new logininfo() { username = "user", password = "p-dub" }; // await app.mobileservice.invokeapiasync<logininfo, loginresult>("customregistration", dude); // phone call custom api log in var result = await app.mobileservice.invokeapiasync<logininfo,loginresult>("customlogin", dude); // create user credentials. passwordcredential credential = new passwordcredential("usertodo", result.user.userid, result.authenticationtoken); mobileserviceuser user = new mobileserviceuser(credential.username); credential.retrievepassword(); user.mobileserviceauthenticationtoken = credential.password; // set user stored credentials. app.mobileservice.currentuser = user; await refreshtodoitems(); // accesses mobile service. } public class logininfo { public string username { get; set; } public string password { get; set; } } public class loginresult { public user user { get; set; } public string authenticationtoken { get; set; } } public class user { public string userid { get; set; } }
authentication azure-mobile-services
Comments
Post a Comment