user1866308
user1866308

Reputation: 146

How to get identities in Azure Mobile Services?

I am using the following code in an Azure Mobile Service API. but I am not getting any response or error. If I go specifically for ideitities.google or facebook I get error 500 Internal Server Error. In log it appears as if the identities is null. whereas I am loggedin to gmail and facebook with the current browser session.. Error in script '/api/test123.js'. TypeError: Cannot read property 'google' of null at Object.request.user.getIdentities.success

exports.get = function (request, response) {
 request.user.getIdentities({
 success: function (identities) {
     //response.send(statusCodes.OK, identities);
         //  request.respond(200, identities);
       response.send(statusCodes.OK, identities);

 // Do something with identities, send response
 },
 error: function (err) {
 // handle errors

 }
 });
}

What am I doing wrong? I have also enables the preview user feature using the Azure CLI but no effect.

Upvotes: 0

Views: 487

Answers (1)

Matt Milner
Matt Milner

Reputation: 825

The identities you get back from that call are identities used to authenticate with the mobile service. Just being logged into google in your browser session has nothing to do with the identities in your mobile service. The mobile service is going to read the signed JWT token you are sending with the request and provide you the identities. That token is generated when you call the login method on the mobile service.

To login using an existing token from google or facebook, you can use this API: http://msdn.microsoft.com/en-us/library/azure/jj710106.aspx

To have mobile services initiate the login process with the provider (i.e. show you the OAuth login for the provider) then you can use this API: http://msdn.microsoft.com/en-us/library/azure/dn283952.aspx

Note that for this to work you have to have previously setup your mobile service, on the identity tab, with the information about your application setup with that identity provider. Also, all of the client SDKs for mobile services provide login methods that wrap these REST API calls.

Upvotes: 2

Related Questions