我试图更改IdentityServer4 AspNetIdentity示例以便能够从本地创建的用户和Google登录。当通过Google OAuth登录时使用IProfileService
我能够加入谷歌认证要做到这一点:
app.UseIdentity();
app.UseIdentityServer();
var cookieScheme = app.ApplicationServices.GetRequiredService<IOptions<IdentityOptions>>().Value.Cookies.ExternalCookieAuthenticationScheme;
// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
app.UseGoogleAuthentication(new GoogleOptions
{
AuthenticationScheme = "Google",
SignInScheme = cookieScheme,
ClientId = "client_id",
ClientSecret = "client_secret"
});
正如预期的那样在主页视图显示正确的用户声明:
sub
c51da331-0348-45dd-352f-08d4526f6266
name
[email protected]
AspNet.Identity.SecurityStamp
568a167f-a431-4f70-ba66-918f99e95eef
idp
Google
amr
external
auth_time
1486815555
在使用谷歌账户在首次用户登录我向数据库添加了一些信息,我想我可以通过使用自定义IProfileService实现并将IdentityServer配置为使用我的自定义IProfileService将它们添加到用户声明中:
var builder = services.AddIdentityServer();
builder.AddTemporarySigningCredential();
builder.AddConfigurationStore(b => b.UseSqlServer(connectionString, options => options.MigrationsAssembly(migrationAssembly)));
builder.AddOperationalStore(b => b.UseSqlServer(connectionString, options => options.MigrationsAssembly(migrationAssembly)));
builder.AddAspNetIdentity<MyUser>();
builder.AddProfileService<MyCustomProfileService>();
但现在,当我导航到主页时,用户声明保持不变,甚至GetProfileDataAsync方法也不会发生。
我很感激有人能告诉我这是什么感觉。