【问题标题】:Azure App Services - Google account Id's not matchingAzure 应用服务 - Google 帐户 ID 不匹配
【发布时间】:2023-04-08 01:04:01
【问题描述】:

我正在测试 Azure 应用服务以创建 Web/移动应用。我将 xamarin.forms 用于移动设备、App Services Mobile Services(C# 服务器)用于移动访问和 2 个 App Services 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(在移动客户端和移动服务器项目上)

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

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

谁能建议一种从移动和网络应用程序中获取匹配 ID 的方法?我原以为这会是 Azure 应用服务的主要思想之一

谢谢

标记

【问题讨论】:

    标签: azure xamarin.forms azure-mobile-services azure-web-app-service


    【解决方案1】:

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

    【讨论】:

    • 有没有例子说明如何做到这一点?这不是我熟悉的东西
    【解决方案2】:

    在此链接“如何:检索经过身份验证的用户信息”部分找到答案

    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;
    

    希望这可以帮助其他正在寻找这个的人

    【讨论】:

      猜你喜欢
      • 2021-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-25
      • 2013-09-02
      • 2018-07-30
      • 2015-07-13
      • 2014-06-08
      相关资源
      最近更新 更多