具有 Google 移动应用程序身份验证的 IdentityServer4?

IdentityServer4 with Google authentication for mobile application?

我已经设法让我的 IS4 与 Web 应用程序的 Google 身份验证一起工作。

services.AddAuthentication()
        .AddGoogle("Google", o =>
        {
            o.SignInScheme = IdentityServer4.IdentityServerConstants.ExternalCookieAuthenticationScheme;
            o.ClientId = "11111.apps.googleusercontent.com";
            o.ClientSecret = "1231231";
        });

现在,如何为移动应用程序添加?

我尝试更改 ClientId 以使用从 Google 控制台获得的新客户端。删除了 ClientSecret(因为对于移动应用程序没有给出秘密)。使用相同的 ExternalCookieAuthScheme。我得到了一个错误,因为必须提供“ClientSecret”。那么我该如何让它发挥作用呢?

此处的客户端凭据:

        o.ClientId = "11111.apps.googleusercontent.com";
        o.ClientSecret = "1231231";

仅在 IdentityServer 和 Google 之间,不应存储在移动客户端中。

移动应用程序中使用的 clientid + secret 可在 IdentityServer 中移动应用程序的客户端定义中找到。

Google 在这种情况下不关心用户是通过 Web 应用程序还是客户端应用程序进行身份验证。 Google 只会看到通过 IdentityServer 尝试登录的用户。所以google完全屏蔽了什么样的应用程序在使用IdentityServer。

因此,在 IdentityServer 中,您可以为 Web 应用程序创建一个客户端条目,为您的移动应用程序创建一个客户端条目。

请参阅文档中的客户端类型 here

在这种情况下,您正尝试通过 google 作为外部身份提供者从 IdentityServer 登录。从google来看,客户端就是IdentityServer。而 IdentityServer 是一个 Web 应用程序。 您应该坚持在 google.

上创建的原始客户端

供将来参考:当我们尝试直接从移动应用程序登录时,我们需要将应用程序类型设置为 android 或 IOS。