GetExternalLoginInfoAsync的实现不同于LiveAuthClient.GetUserId(auth

本文关键字:GetUserId auth LiveAuthClient 不同于 实现 GetExternalLoginInfoAsync | 更新日期: 2023-09-27 18:12:58

谁能帮我解释一下Live SDK (v5.6)的实现和Microsoft.AspNet.Identity.Owin.dll中的情况?

认证成功后返回的用户id:

//MVC5 UserController for SSO with Microsoft Account
var result = await AuthenticationManager.GetExternalLoginInfoAsync();
var userId = result.Login.ProviderKey;

…不同于

返回的标识。
//WebAPI 2 custom AuthFilter (performs HMAC, etc)
var liveAuthClient = new LiveAuthClient(clientKey, secretKey, redirectUrl);
var userId = liveAuthClient.GetUserId(authTokenFromHttpHeader);

在这两种情况下,相同的ClientId和ClientSecret被Windows Phone 8客户端应用程序,MVC5 WebApp和WebAPI 2使用。

MVC5网站返回的id长度为16个字符,而从认证令牌中提取的id长度为32个字符。

我认为可能来自客户端应用程序的id是MD5散列,但是如果我尝试散列它,它们仍然不匹配。

任何想法?

GetExternalLoginInfoAsync的实现不同于LiveAuthClient.GetUserId(auth

我终于弄清楚这里发生了什么,似乎LiveAuthClient返回的ID在某种程度上特定于Live SDK,没有任何方式的消息会让我得到我需要的。

与WP8.1 Silverlight应用程序中的WebAuthenticationBroker指向https://login.live.com/oauth20_authorize.srf?client_id=the_clientid&scope=wl.signin&response_type=token&display=touch(其中'the_clientid'是实际的ClientID)相反,我能够检索一个access_token,然后可以用来访问原始用户ID,如下所示:

//get the UID
var accessToken = "the_token"; //replace with actual token
var meUri = new Uri(string.Format("https://apis.live.net/v5.0/me/?access_token={0}", accessToken));
var httpClient = new HttpClient();               
var response = await httpClient.GetAsync(meUri);
var responseString = await response.Content.ReadAsStringAsync();
var meObj = new { Id = ""};
meObj = JsonConvert.DeserializeAnonymousType(responseString, meObj);

meObj.Id是MD5哈希时,它完全匹配由MVC5 web应用程序返回的ProviderKey !

两个链接非常有助于理解如何实现WebAuthenticationBroker部分:

http://msicc.net/?p=4054 (Windows Runtime Apps)

http://msicc.net/?p=4074 (Silverlight 8.1应用程序)