0

我一直在使用身份提供者为 azure 应用程序配置我的访问控制命名空间,并且能够使用他们的声明令牌从 Google 和 Yahoo 返回电子邮件地址,但使用 Windows Live ID 我能找到的唯一识别值是:

http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier: gX5FDH7dCnWGUfe46CwiCSvRUosc2aM7kmMHBnjQOxM=

我知道这代表电子邮件地址,但我无法知道“ gX5FDH7dCnWGUfe46CwiCSvRUosc2aM7kmMHBnjQOxM= ”与用户注册时我在数据库中的电子邮件地址存储值有何关联,这导致我出现 YSoD,因为找不到用户. 我阅读了一些可以使用 Windows Live Connect 工具将其转换为电子邮件地址的内容,但我找不到任何进一步的信息。

任何人都知道如何在后面的 c# 代码中做到这一点?

4

1 回答 1

0

It seems like there are some code samples for what you are looking for here:

http://msdn.microsoft.com/en-us/library/hh243641.aspx

I think you need to request a token for the wl.basic scope to get an access token that contains the user email address claim.

So according to the link, one way to do this would be like this:

private async void btnGreetUser_Click(object sender, RoutedEventArgs e)
{
    try
    {
        LiveAuthClient auth = new LiveAuthClient();
        LiveLoginResult initializeResult = await auth.InitializeAsync();
        try
        {
            LiveLoginResult loginResult = await auth.LoginAsync(new string[] { "wl.basic" });
            if (loginResult.Status == LiveConnectSessionStatus.Connected)
            {
                LiveConnectClient connect = new LiveConnectClient(auth.Session);
                LiveOperationResult operationResult = await connect.GetAsync("me");
                dynamic result = operationResult.Result;
                if (result != null)
                {
                    this.infoTextBlock.Text = string.Join(" ", "Hello", result.name, "!");
                }
                else
                {
                    this.infoTextBlock.Text = "Error getting name.";
                }
            }
        }
        catch (LiveAuthException exception)
        {
            this.infoTextBlock.Text = "Error signing in: " + exception.Message;
        }
        catch (LiveConnectException exception)
        {
            this.infoTextBlock.Text = "Error calling API: " + exception.Message;
        }
    }
    catch (LiveAuthException exception)
    {
        this.infoTextBlock.Text = "Error initializing: " + exception.Message;
    }
}

So you pass the scope as a string array, and instead of using the wl.basic scope you have to use, the wl.emails scope, to get access to the email info, see:

http://msdn.microsoft.com/en-us/library/hh243646.aspx#wlemails

于 2014-08-03T08:55:39.227 回答