简体   繁体   中英

Not authorized returned to windows Universal app from Azure mobile app

I have created an azure mobile app which exposes an api. I have registered the mobile app for Microsoft account authentication. The mobile app is working when I access it from postman or even Microsoft edge after I log into my windows account.
The mobile app is a backend for a universal windows app. I followed the boilerplate Microsoft examples ( Add Authentication to UWA ). The code to login to the site works well (It either retrieves my stored credentials or has me log into the Microsoft account server). The credentials are stored in the CurrentUser of an instance of MobileServiceClient.

This is an example of one of the controllers.

    [MobileAppController]
    [Authorize]
    public class TeamsController : ApiController
    {
    private GameNoteContext db = new GameNoteContext();
    [HttpGet, Route("api/Teams")]
    // GET: api/Teams
    public IQueryable<Team> GetTeams()
    {
                   return db.Teams;
    }

The client calls the api with the following code: //myuri is the controller, param is the query strings as a dictionary object var response = await client.InvokeApiAsync(myuri, System.Net.Http.HttpMethod.Get, param);

The generated request is correct and appears to have the correct headers. I can copy them into postman and I get the correct response. But from my client (run from visual studio) I get unauthorized. Here is the request body that is sent from the client:

  X-ZUMO-FEATURES: AT,QS
  X-ZUMO-INSTALLATION-ID: theidiscorrect
  X-ZUMO-AUTH: atokenappearshere
  Accept: application/json
  User-Agent: ZUMO/2.1
  User-Agent: (lang=Managed; os=Windows Store; os_version=--; arch=X86; version=2.1.40707.0)
  X-ZUMO-VERSION: ZUMO/2.1 (lang=Managed; os=Windows Store; os_version=--; arch=X86; version=2.1.40707.0)
  ZUMO-API-VERSION: 2.0.0
  Accept-Encoding: gzip

I can't figure out what to try next.

You will need to turn on Application Logging in the portal and take a look at the server side logs. Short version is that the token is not being accepted. This could be because it has expired or because there is a configuration error on the server-side. However, you won't be able to tell until you take a look at the server side logs.

See Enable diagnostics logging for web apps in Azure App Service .

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