0

I was following custom authentication for my azure mobile app (https://www.newventuresoftware.com/blog/custom-authentication-with-azure-mobile-apps)

I created AuthControll which accepts username and password and creates token. When i call MobileServiceClient.InvokeApiAsync("Auth", loginInfoDictionary), I receive the user name and token succesfully. I created new MobileServiceUser(username) with received token an set it to MobileSeviceClient.CurrentUser. But When i call MobileServiceClient.InvokeApi over method which requiere authorization, it tells me i am unauthorized.

What i am supposed to do with received token then ? Can i use MobileServiceClient.InvokeApiAsync and MobileServiceClient.GetTable methods with this type of authorization ? If yes what i am missing ?

Erik Parso
  • 194
  • 14
  • Refer to this document https://github.com/Azure/azure-mobile-services/blob/master/docs/mobile-services-dotnet-backend-get-started-custom-authentication.md – Lucas Zhang Nov 21 '18 at 06:12

1 Answers1

0

I found a problem in my solution on server side. I forgot to specify my url site when creating a token. Like this

var signingKey = Environment.GetEnvironmentVariable("WEBSITE_AUTH_SIGNING_KEY");
var audience = "https://TheSiteIForgotToSpecify.azurewebsites.net/"; // audience must match the url of the site
var issuer = "https://TheSiteIForgotToSpecify.azurewebsites.net/"; // audience must match the url of the site
JwtSecurityToken token = AppServiceLoginHandler.CreateToken(
    claims, signingKey, audience, issuer, TimeSpan.FromHours(24));
Erik Parso
  • 194
  • 14