Google 身份验证未返回与 IdentityServer4 一致的 ID

Google Auth not returning a consistent ID with IdentityServer4

我正在尝试设置 IdentityServer4,使用 Example 8_EntityFramework 作为基础。

问题 - Google 身份验证似乎 return 我可以 link 返回我的应用程序的一致 ID。

查看此 Whosebug post,一位用户从文档中声称 'sid' 可以做到这一点。但是,如果我重新启动服务器并清除缓存,返回的 SID 会有所不同(见下文),所以不要认为它值得信赖。

按照另一个思路,我尝试将 UserInformationEndpoint 设置为“https://www.googleapis.com/oauth2/v1/userinfo”,但完全失败了。

这是我的身份验证服务器代码 startup.js - 它与 example 中的标准差不多。

public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();

var connectionString = @"server={myserver};database=IdentityServer4.QuickStart;trusted_connection=yes";
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;



// configure identity server with in-memory users, but EF stores for clients and scopes
services.AddIdentityServer()
    .AddSigningCredential(new X509Certificate2(@"{pathtocertificate}\{certname}.pfx", "{password}"))
    //.AddTemporarySigningCredential()
    .AddInMemoryUsers(Config.GetUsers())
    .AddConfigurationStore(builder =>
        builder.UseSqlServer(connectionString, options =>
            options.MigrationsAssembly(migrationsAssembly)))
    .AddOperationalStore(builder =>
        builder.UseSqlServer(connectionString, options =>
            options.MigrationsAssembly(migrationsAssembly)));

}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// this will do the initial DB population
InitializeDatabase(app);

loggerFactory.AddConsole(LogLevel.Debug);
app.UseDeveloperExceptionPage();

app.UseIdentityServer();

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme,

    AutomaticAuthenticate = false,
    AutomaticChallenge = false
});

app.UseGoogleAuthentication(new GoogleOptions
{
    AuthenticationScheme = "Google",
    DisplayName = "Google",
    SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme,
    Scope = { "openid", "email" },



    ClientId = "434483408261-55tc8n0cs4ff1fe21ea8df2o443v2iuc.apps.googleusercontent.com",
    ClientSecret = "3gcoTrEDPPJ0ukn_aYYT6PWo"
});

app.UseStaticFiles();
app.UseMvcWithDefaultRoute();

}

Google 验证结果 1

清除缓存并重新启动 IdentityServer4 - 所有密钥都已更改!

有谁知道我可以使用什么钩子来匹配我的资源服务器(即 google ID abc 始终 = 我的用户 xyz)?

根据 Gitter IdentityServer4 forum 的讨论,问题似乎与使用内存中用户存储的示例 8 有关。

我认为因为身份验证是外部的并且一些信息 存储在数据库中,所以内存存储是无关紧要的,但事实并非如此。

Example 6 使用 AspNetIdentity 正确连接所有内容并且 returns 一致的 ID。