Код: Выделить всё
builder.Services.AddOpenIddict()
.AddCore(opt => { })
.AddServer(opt =>
{
opt.AllowAuthorizationCodeFlow()
.AllowRefreshTokenFlow();
opt.SetIssuer(new Uri("http://"));
opt.SetAuthorizationEndpointUris("oauth2/authorize")
.SetTokenEndpointUris("oauth2/token")
.SetIntrospectionEndpointUris("oauth2/introspect")
.SetConfigurationEndpointUris("oauth2/.well-known/openid-configuration")
.SetCryptographyEndpointUris("oauth2/.well-known/jwks");
opt.AddEphemeralEncryptionKey();
opt.AddEphemeralSigningKey();
opt.EnableDegradedMode();
opt.UseAspNetCore()
.DisableTransportSecurityRequirement();
opt.DisableAccessTokenEncryption();
opt.RequireProofKeyForCodeExchange();
// no use in degraded mode
opt.UseReferenceAccessTokens()
.UseReferenceRefreshTokens();
opt.AddEventHandler(x =>
{
x.UseInlineHandler(c =>
{
return default;
});
});
opt.AddEventHandler(x =>
{
// validate client, e.g., client_id, redirect_url
x.UseScopedHandler();
});
opt.AddEventHandler(x =>
{
x.UseScopedHandler();
});
opt.AddEventHandler(x =>
{
x.UseInlineHandler(c =>
{
return default;
});
});
public class ValidateAuthorizationRequestContext : IOpenIddictServerHandler
{
public ValueTask HandleAsync(OpenIddictServerEvents.ValidateAuthorizationRequestContext context)
{
if (!String.Equals(context.ClientId, "test", StringComparison.Ordinal))
{
context.Reject(
error: Errors.InvalidClient,
description: "The specified 'client_id' doesn't match a registered application."
);
}
return default;
}
}
public class HandleAuthorizationRequestContext : IOpenIddictServerHandler
{
public ValueTask HandleAsync(OpenIddictServerEvents.HandleAuthorizationRequestContext context)
{
// play with the ClaimsPrincipal
var identity = new ClaimsIdentity(TokenValidationParameters.DefaultAuthenticationType);
var claim = new Claim(Claims.Subject, "testSubject");
claim.SetDestinations(Destinations.AccessToken);
identity.AddClaim(claim);
//context.Principal = new ClaimsPrincipal(identity);
context.SignIn(new ClaimsPrincipal(identity));
return default;
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... raded-mode