Azure 应用服务 - Google 帐户 ID 不匹配

Azure App Services - Google account Id's not matching

我正在测试 Azure 应用程序服务以创建 Web/移动应用程序。我正在使用 xamarin.forms 移动设备、App Services 移动服务(C# 服务器)进行移动访问和 2 个 App Services Web 应用程序。

服务器应用程序和两个 Web 应用程序已配置为使用 Google 身份验证,按照此处的说明使用相同的 Google 凭据:

https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-how-to-configure-google-authentication/

我正在尝试获取已登录 Google 用户的用户 ID,并且在网络应用程序中我获得了格式为 112567911111837839502 的 ID(匹配网络应用程序 1 和网络应用程序 2) ,但是当我通过移动设备使用相同的 Google 帐户登录时,我得到一个格式为 sid:dc7a23bc80cb2752822351cf5a111111 的 ID(在移动客户端和移动服务器项目上)

我在 Web 应用程序和移动服务器项目中用于获取 ID 的代码是相同的:

var claimsPrincipal = this.User as ClaimsPrincipal;
        string sid = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier).Value;

任何人都可以建议一种从移动和网络应用程序获取匹配 ID 的方法吗?我原以为这将是 Azure 应用服务的主要思想之一

谢谢

马克

您可以获得 /.auth/me 端点 (https://yoursite.azurewebsites.net/.auth/me) - 这将为您提供一个 JSON 对象,您可以解析该对象以获取 google 是返回。您的 UserId 将在那里。

在 link 部分找到答案 "How to: Retrieve authenticated user information"

https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-backend-how-to-use-server-sdk/#how-to-work-with-authentication

以下代码在控制器中有效

GoogleCredentials cred = await this.User
            .GetAppServiceIdentityAsync<GoogleCredentials>(this.Request);
        var googleId = cred.UserClaims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;

希望这对寻找此内容的其他人有所帮助