2 回答
TA贡献1860条经验 获得超9个赞
我正在更改架构如下
public static void AddCookieAuthentication(this IServiceCollection services, IConfiguration configuration)
{
_configuration = configuration;
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options =>
{
options.TokenValidationParameters.AuthenticationType = IdentityConstants.ApplicationScheme;
options.ResponseType = "code";
options.MetadataAddress = configuration["Authentication:Cognito:MetadataAddress"];
options.ClientId = configuration["Authentication:Cognito:ClientId"];
options.ClientSecret = configuration["Authentication:Cognito:ClientSecret"];
options.GetClaimsFromUserInfoEndpoint = true;
options.Scope.Add("openid");
options.Scope.Add("profile");
options.Scope.Add("email");
options.Scope.Add("aws.cognito.signin.user.admin");
options.Events = new OpenIdConnectEvents
{
// this makes signout working
OnRedirectToIdentityProviderForSignOut = OnRedirectToIdentityProviderForSignOut,
OnRedirectToIdentityProvider = OnRedirectToIdentityProvider,
};
});
}
private static Task OnRedirectToIdentityProvider(RedirectContext ctx)
{
ctx.Options.Events.OnRedirectToIdentityProvider = async context =>
{
**context.ProtocolMessage.RedirectUri = context.ProtocolMessage.RedirectUri.Replace("http:", "https:");**
await Task.FromResult(0);
};
return Task.CompletedTask;
}
- 2 回答
- 0 关注
- 326 浏览
添加回答
举报