Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication 在Azure移动服务中注册和登录用户_Authentication_Azure_Windows Phone 8_Authorization_Azure Mobile Services - Fatal编程技术网

Authentication 在Azure移动服务中注册和登录用户

Authentication 在Azure移动服务中注册和登录用户,authentication,azure,windows-phone-8,authorization,azure-mobile-services,Authentication,Azure,Windows Phone 8,Authorization,Azure Mobile Services,我是以下,我使用的例子在最新的教程。现在我想推动注册和登录Windows Phone为例。我更改为向具有应用程序密钥的任何人插入权限,并且我可以通过以下代码插入新用户: await accountTable.InsertAsync(new accounts() { Username = "admin", Password = "mypassword" }); 但我不知道现在如何检查登录用户?如何获取令牌?您提到的帖子是在去年年底写的,当时Azure Mobile Services上不支持自定义

我是以下,我使用的例子在最新的教程。现在我想推动注册和登录Windows Phone为例。我更改为向具有应用程序密钥的任何人插入权限,并且我可以通过以下代码插入新用户:

await accountTable.InsertAsync(new accounts() { Username = "admin", Password = "mypassword" });

但我不知道现在如何检查登录用户?如何获取令牌?

您提到的帖子是在去年年底写的,当时Azure Mobile Services上不支持自定义API—您唯一可以为用户调用执行脚本的地方是在表上。现在你应该使用定制的API来实现这一点,你可以定义两个API,一个用于注册用户,另一个用于登录。在客户端上,当您调用login时,API将验证用户名/密码,然后返回Zumo令牌(使用该博客文章中显示的脚本创建),然后客户端可以将其设置为
MobileServiceClient
对象的
CurrentUser
属性

类似下面的代码:

var loginInput = new JObject();
loginInput.Add("userName", "theUserName");
loginInput.Add("password", "thePassword");
var loginResult = await client.InvokeApiAsync("login", loginInput);
client.CurrentUser = new MobileServiceUser((string)loginResult["user"]);
client.CurrentUser.MobileServiceAuthenticationToken = (string)loginResult["token"];
exports.post = function(req, res) {
    var user = req.body.userName;
    var pass = req.body.password;
    validateUserNamePassword(user, pass, function(error, userId, token) {
        if (error) {
            res.send(401, { error: "Unauthorized" });
        } else {
            res.send(200, { user: userId, token: token });
        }
    });
}
API看起来像下面的代码:

var loginInput = new JObject();
loginInput.Add("userName", "theUserName");
loginInput.Add("password", "thePassword");
var loginResult = await client.InvokeApiAsync("login", loginInput);
client.CurrentUser = new MobileServiceUser((string)loginResult["user"]);
client.CurrentUser.MobileServiceAuthenticationToken = (string)loginResult["token"];
exports.post = function(req, res) {
    var user = req.body.userName;
    var pass = req.body.password;
    validateUserNamePassword(user, pass, function(error, userId, token) {
        if (error) {
            res.send(401, { error: "Unauthorized" });
        } else {
            res.send(200, { user: userId, token: token });
        }
    });
}

这可能会有帮助:我以前见过。它正在使用LoginAsync,但需要MobileServiceAuthenticationProvider作为参数,但我不知道从何处获取自定义身份验证。请不要在数据库中存储密码。做其他网站做的事情,只存储它的一个(盐渍的)散列。当然,它在数据库中是盐渍的散列。它使用的是我之前提到的教程中的javascript代码。对不起,我的错误-使用用户名/密码的“插入”操作让我很失望。我应该先看一下教程。非常感谢您给我的建议:在azure移动服务中使用自定义身份验证非常简单。不知道为什么会这样搞砸。Parse.com身份验证真是太棒了。