Azure的移动服务 - 获取更多的用户信息 [英] Azure Mobile Services - Getting more user information

查看:139
本文介绍了Azure的移动服务 - 获取更多的用户信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承了与XAML编写的Windows 8的应用程序。因此,在C#中,当我拨打这个电话

I inherited a Windows 8 application that is written with XAML. So in C# when I make this call

user = await MobileServices.MobileService
                    .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);

(这是Azure的移动服务)

(This is for Azure Mobile Services)

用户对象的给我的令牌和MicrosoftAccount:..............

The user object is ONLY giving me the Token and the MicrosoftAccount:..............

为了获得认证的人,我需要能够看到请求访问...

In order to get to authenticate people, I need to be able to see WHO is requesting access...

我看着像下面的文章,但我似乎失去了一些东西?这是JavaScript中的文章是我会在Node.js的写?

I looking at articles like below, but I seem to be missing something? Is this javascript in the article something I would have to write in Node.js?

示例文章:
<一href=\"http://blogs.msdn.com/b/carlosfigueira/archive/2013/12/12/expanded-login-scopes-in-azure-mobile-services.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/carlosfigueira/archive/2013/12/12/expanded-login-scopes-in-azure-mobile-services.aspx

推荐答案

目前,以便能够获取登录用户的详细信息,您需要到服务第二个电话来获取用户信息。你并不真的需要问其他登录的作用域(你提到的帖子的主题)来检索用户名,因为这是在默认情况下为所有供应商给定的。

Currently to be able to get more information about the logged in user, you need to make a second call to the service to retrieve the user info. You don't really need to ask for additional login scopes (the topic of the post you mentioned) to retrieve the user name, since that is given by default for all the providers.

<一个href=\"http://blogs.msdn.com/b/carlosfigueira/archive/2012/10/25/getting-user-information-on-azure-mobile-services.aspx\"相对=nofollow>这个帖子应该有code,你需要在服务器端(node.js的)来写,以获取有关登录用户的详细信息。 ;在TL以下DR版本给出:

This post should have the code you need to write in the server side (node.js) to get more information about the logged in user. The TL;DR version is given below:

在服务器端:添加此定制的API(我称之为 USERINFO 设置GET的权限,用户,和所有其他管理员):

On the server side: add this custom API (I'll call it "userInfo"; set the permission of GET to "user", and all others to admin):

exports.get = function(request, response) {
    var user = request.user;
    user.getIdentities({
        success: function(identities) {
            var accessToken = identities.microsoft.accessToken;
            var url = 'https://apis.live.net/v5.0/me/?method=GET&access_token=' + accessToken;
            var requestCallback = function (err, resp, body) {
                if (err || resp.statusCode !== 200) {
                    console.error('Error sending data to the provider: ', err);
                    response.send(statusCodes.INTERNAL_SERVER_ERROR, body);
                } else {
                    try {
                        var userData = JSON.parse(body);
                        response.send(200, userData);
                    } catch (ex) {
                        console.error('Error parsing response from the provider API: ', ex);
                        response.send(statusCodes.INTERNAL_SERVER_ERROR, ex);
                    }
                }
            }
            var req = require('request');
            var reqOptions = {
                uri: url,
                headers: { Accept: "application/json" }
            };
            req(reqOptions, requestCallback);
        }
    });
}

在客户端,成功登录后,调用API:

On the client side, after a successful login, call that API:

user = await MobileServices.MobileService
    .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);
var userInfo = await MobileServices.MobileService.InvokeApiAsync(
    "userInfo", HttpMethod.Get, null);

USERINFO 将包含 JObject 与用户的信息。这里是一个开放的功能要求,使在<一个这更好href=\"http://feedback.azure.com/forums/216254-mobile-services/suggestions/5211616-ability-to-intercept-the-login-response\" rel=\"nofollow\">http://feedback.azure.com/forums/216254-mobile-services/suggestions/5211616-ability-to-intercept-the-login-response.

userInfo will contain a JObject with the user information. There is an open feature request to make this better at http://feedback.azure.com/forums/216254-mobile-services/suggestions/5211616-ability-to-intercept-the-login-response.

这篇关于Azure的移动服务 - 获取更多的用户信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆