简体   繁体   中英

Azure mobile app custom authentication and MobileServiceClient

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 ?

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM