【发布时间】:2014-12-08 08:57:39
【问题描述】:
我正在使用 Cordova/Phonegap 和 Azure 移动服务后端构建一个电话应用程序。我需要使用自定义身份验证器,因为它与当前的软件产品集成。
我使用来自http://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-get-started-custom-authentication/ 的信息构建了服务器端
我在WebApiConfig中设置了config.SetIsHosted(true);
从客户端,我似乎可以很好地进行身份验证并取回一个有效的令牌,但我不确定如何处理它。我已尝试设置 client.currentUser,但我的 api 调用返回为未经授权。
这里有一些代码:
client = new WindowsAzure.MobileServiceClient("http://`localhost`:50523");
login = function () {
client.invokeApi("CustomLogin", {
method: "post",
body: { "username": "user1", "password": "pass1" }
})
.done(function (result) {
var login = JSON.parse(result.response);
client.currentUser = login.user;
client.currentUser.mobileServiceAuthenticationToken = login.authenticationToken;
//lets try now that i'm valid
getMembers();
app.navigate("views/home.html");
}, function(error) {
alert(error);
});
};
getMembers = function () {
client.invokeApi("Member", {
method: "get",
body: {}
})
.done(
function(result) {
alert(result.result[0].lName);
},
function(error) {
alert(error);
});
};
我还需要对身份验证令牌做更多的事情来完成这项工作吗? 谢谢!
编辑:更多信息 --
使用 Fiddler 监控流量,我看到对/api/member 的调用设置了几个标头:
X-ZUMO-AUTH: set to the token I got back earlier
X-ZUMO-FEATURES: AJ
X-ZUMO-INSTALLATION-ID: a guid
X-ZUMO-VERSION: ZUMO/1.2(...)
【问题讨论】:
-
Azure 移动服务不支持自定义标识提供程序。只有 Microsoft、Facebook、Twitter、Google 和 Active Directory。您尝试使用什么身份验证?
-
自定义身份提供者...正如我在条目顶部的链接中所讨论的那样。
-
登录后只调用API会发生什么?不要设置任何用户。我认为客户端在调用 API 时将其存储为访问。因此,除非您想缓存用户令牌,否则您不必做任何事情。在这种情况下,您可以执行此处的建议:azure.microsoft.com/en-us/documentation/articles/…
标签: authentication azure-mobile-services