Randeep Singh
Randeep Singh

Reputation: 1018

Azure Mobile App engaging Xamarin Authentication

I'm using Xamarin Forms authentication with Auth0. Backend service is Azure Mobile App. Am trying to pass over the authorization token back to the service via :

            MobileServiceUser usr = new MobileServiceUser(User.UserName);
            usr.MobileServiceAuthenticationToken = User.jwt;
            App.client.CurrentUser = usr;

I'm yet to handle this in my Azure App. When I pass the user as above, I encounter following error in Xamarin project :

Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The request could not be completed. (Unauthorized)

This in fact that I have declared Anonymous access in my controller :

[AuthorizeLevel(AuthorizationLevel.Anonymous)]
public class MovementController : TableController<MoveHeaderDto>

How do I suppose to handle MobileServiceUser in my Azure Mobile App?

Upvotes: 2

Views: 510

Answers (1)

mattchenderson
mattchenderson

Reputation: 1620

I believe the 401 you are seeing is because the token is not in the expected format and cannot be validated.

The MobileServiceAuthenticationToken property is a JWT issued by the Mobile App Gateway itself. You will need to call the loginAsync() method overload that takes an additional token parameter, passing in the JWT you get from Auth0.

The loginAsync method will set the MobileServiceUser, and this will be attached to calls going to your service. Please note that for Xamarin forms, you need to have a custom renderer so that the right view element for the platform gets used. This similar to what is this blog post does for the ADAL library.

Upvotes: 2

Related Questions