Вот мой OIDC Конфигурация: < /p>
Код: Выделить всё
private void ConfigureOptions(OpenIdConnectOptions options)
{
options.Authority = _options.RealmUrl; // the URL is private
options.ClientId = _options.ClientId;
options.RequireHttpsMetadata = _options.SslRequired;
options.ClientSecret = _options.Secret;
options.GetClaimsFromUserInfoEndpoint = true;
options.ResponseType = OpenIdConnectResponseType.Code;
options.UsePkce = true;
options.SaveTokens = true;
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.SignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.TokenValidationParameters = new TokenValidationParameters
{
ClockSkew = _options.TokenClockSkew,
ValidateAudience = _options.ValidateAudience,
ValidateIssuer = false,
NameClaimType = ClaimHelper.Login,
RoleClaimType = ClaimHelper.Role
};
options.Events.OnRedirectToIdentityProvider = OnRedirectToIdentityProvider;
}
< /code>
А вот и onredirecttoidentityprovider handler: < /p>
private Task OnRedirectToIdentityProvider(RedirectContext ctx)
{
return RedirectToIdentityProvider(ctx, ctx.HandleResponse);
}
private Task RedirectToIdentityProvider(RedirectContext ctx, Action handleResponseAction)
{
var msg = new OpenIdConnectMessage
{
ClientSecret = _options.Secret,
ClientId = _options.ClientId,
ResponseType = OpenIdConnectResponseType.Code,
Scope = "openid email profile roles",
ResponseMode = "form_post",
IssuerAddress = _configuration.GetSection(PublicAuthorizationEndpointUrl).Value, // here I set the public KeyCloak URL
RedirectUri = "https" + Uri.SchemeDelimiter + ctx.Request.Host + ctx.Request.PathBase + "/signin-oidc",
Nonce = Guid.NewGuid().ToString("N"),
RequestType = OpenIdConnectRequestType.Authentication
};
var properties = new AuthenticationProperties();
properties.Items[OpenIdConnectDefaults.RedirectUriForCodePropertiesKey] = msg.RedirectUri;
msg.State = ctx.Options.StateDataFormat.Protect(properties);
var url = msg.CreateAuthenticationRequestUrl();
ctx.Response.Redirect(url);
handleResponseAction.Invoke();
return Task.CompletedTask;
}
Я буду признателен за любую помощь.
Подробнее здесь: https://stackoverflow.com/questions/794 ... o-endpoint