azure-mobile-apps-client - invokeApi未经授权

时间:2016-08-14 14:50:40

标签: azure azure-mobile-services

设定:

使用js库并遵循我的C#Xamarin项目的客户端登录/身份验证流程 设置CORS并初始登录正常:

this.client = new WindowsAzure.MobileServiceClient(<endpoint>);
this.client.login(<provider>);

我存储了返回的&#34; userId&#34;和#34; mobileServiceAuthenticationToken&#34;供将来使用。

问题:

调用azure-mobile-apps-client的invokeApi:

this.client.invokeApi("myCustomerController", { method: 'GET' })

返回:

  

401(未经授权)

我错过了什么吗?我希望客户准备好接听我的后端服务。

我在登录后直接尝试使用现有客户端但没有成功 设置&#34; userId&#34;和#34; mobileServiceAuthentication令牌&#34;新客户。

从其他地方调用时,我调用的自定义ApiController工作正常(例如C#MobileServiceClient)。

2 个答案:

答案 0 :(得分:0)

我认为登录会让客户端准备好使用,但不是我的情况。我不得不调用login,获取结果中返回的userId和token,然后在进行任何将来的请求之前手动设置currentUser。

this.client = new WindowsAzure.MobileServiceClient("https://...");
this.client.currentUser = {
      userId: "xxxxx",
      mobileServiceAuthenticationToken: "xxxxx"}

答案 1 :(得分:0)

login 方法返回一个承诺。在继续进行 invokeApi 呼叫之前,您能否确认您确实在等待履行承诺?

相关问题