首页 文章

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

提问于
浏览
1

Setup:

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

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

我存储了返回的“userId”和“mobileServiceAuthenticationToken”以供将来使用 .

Problem:

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

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

收益:

401(未经授权)

我错过了什么吗?我期待客户端准备好调用我的后端服务 .

我在登录后尝试直接使用现有客户端但没有成功 .
设置新客户端的"userId"和"mobileServiceAuthentication token"时也会失败 .

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

2 回答

  • 0

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

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

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

相关问题