I am using Azure app services for my Api (ASP.NET Core) and I have an Api Controller like this
[Route("api")]
public class PingController : Controller
{
[HttpGet]
[Route("ping")]
public string Ping()
{
return "Pong";
}
[Authorize]
[HttpGet("claims")]
public object Claims()
{
return User.Claims.Select(c =>
new
{
Type = c.Type,
Value = c.Value
});
}
}
Then I am trying to access this from a Ionic2 (TypeScript & Cordova) implementation like this
this.client = new WindowsAzure.MobileServiceClient('https://mysite.azurewebsites.net/');
this.client.login('google').then(result=>{
this.client.invokeApi("claims", {
body: null,
method: "get"
}).done(function (results) {
alert(JSON.stringify(results));
}, function (error) {
let msg = error.message;
let request = error.request;
alert(msg+';'+request.status);
});
});
The login screen shows up correctly and the service gets called, but fails with 401 error. It works if I call the 'ping' service. The HTTP call has X-ZUMO headers that I think should be good for authentication(?):
GET /api/claims HTTP/1.1
Host: mysite.azurewebsites.net
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
ZUMO-API-VERSION: 2.0.0
X-ZUMO-INSTALLATION-ID: 10badf87-...
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
X-ZUMO-AUTH: eyJ0eXAiOiJKV...
accept: application/json
X-ZUMO-VERSION: ZUMO/2.0 (lang=Cordova; os=--; os_version=--; arch=--; version=2.0.0-41128.193844)
Referer: http://localhost:8000/index.html
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: en-US,en;q=0.8
Cookie: ARRAffinity=4df5cc005....
the Azure app debug log just shows IIS's default 401 screen. saying the resource has been access as 'anonymous'. I have used Auth0 before and you have to register JWT Bearer options in app configuration. But for Azure, I don't see any tutorials doing a similar step. So what is that I am missing to get this working?