在 IdentityServer 3 中,我使用SecurityTokenValidated
Notifications 上的事件来建立我自己的带有名称和声明的身份。例如,我access_token
使用这样的资源所有者工作流程存储以供以后访问 n API:
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
AuthenticationType = "oidc",
// ...
Notifications = new OpenIdConnectAuthenticationNotifications
{
SecurityTokenValidated = async n =>
{
var nid = new ClaimsIdentity(
n.AuthenticationTicket.Identity.AuthenticationType,
"name",
ClaimTypes.Role);
nid.AddClaim(new Claim("id_token", n.ProtocolMessage.IdToken));
nid.AddClaim(new Claim("access_token", n.ProtocolMessage.AccessToken));
nid.AddClaim(new Claim("expires_at", DateTimeOffset.Now.AddSeconds(int.Parse(n.ProtocolMessage.ExpiresIn)).ToString()));
}
}
}
在 ASP.NET Core 的 IdentityServer 4 中,不是 Notifications 属性。我可以看到自动生成了很多声明,但我没有得到,access_token
也没有自动设置身份的用户名
我当前在 ASP.NET Core 中的客户端配置如下所示
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
AuthenticationScheme = "oidc",
SignInScheme = "Cookies",
Authority = identityServerUri,
RequireHttpsMetadata = false,
ClientId = clientId,
ResponseType = "id_token token",
Scope =
{
"openid profile email warehouseapi"
},
GetClaimsFromUserInfoEndpoint = true,
SaveTokens = true,
AutomaticAuthenticate = true,
AutomaticChallenge = true,
});
IdentityServer 4 中的预期方式是什么?