【发布时间】: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