【问题标题】:401 Unauthorized Error Reading Azure Mobile Services Table as an Authenticated User (Javascript)401 未经授权的错误以经过身份验证的用户 (Javascript) 读取 Azure 移动服务表
【发布时间】:2015-09-19 06:51:55
【问题描述】:

我有一个 Azure 移动服务表,其中读取权限设置为“仅经过身份验证的用户”。

我遵循https://azure.microsoft.com/en-us/documentation/articles/mobile-services-html-get-started-users/ 此处的示例并使用以下代码对用户进行身份验证:

    function logIn() {
    client.login("microsoftaccount").done(function (results) {
        console.log(results);
        //save auth data to local storage
        sessionStorage.loggedInUser = JSON.stringify(client.currentUser);

        //route to the next page based on the type of user that is logged  in
        getUserByUserID();
    }, function (err) {
        alert("Error: " + err);
    });
}

一旦用户通过身份验证,我会将 client.currentUser 信息存储在本地机器上的 sessionStorage 中。然后,我导航到另一个网页,在其中创建 MobileServiceClient 的新实例,并从前面提到的 sessionStorage 更新客户端变量的 currentUser 变量。我使用以下代码来做到这一点:

//load the session data into the client object
if (sessionStorage.loggedInUser) {
    client.currentUser = JSON.parse(sessionStorage.loggedInUser);
    console.log("getting stored user: " + JSON.parse(sessionStorage.loggedInUser));
}

但是,当我尝试使用以下代码从表中读取数据时,我收到“401:未经授权的错误”:

var query = client.getTable("towingProfiles").read().done(function (results) {
    console.log(JSON.stringify(results));
    _.each(results, function(towingProfile){
        towingProfiles.add(towingProfile);
    })
}, function (err) {
    alert("Error: " + err);
});

我不确定为什么这不起作用,希望能提供任何帮助。

【问题讨论】:

    标签: javascript authentication azure azure-mobile-services


    【解决方案1】:

    问题是我在制作 MobileServiceClient 时没有设置正确的应用程序密钥。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-09
      • 2013-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-06
      • 2016-04-15
      • 2018-01-23
      相关资源
      最近更新 更多