How to change validation type in runtime?
See original GitHub issueConfirm youāve already contributed to this project or that you sponsor it
- I confirm Iām a sponsor or a contributor
Version
4.x
Question
Hi @kevinchalet š I updated openIdDict to version 4 and Iām trying to use ChangeToken as you said. Unfortunately it doesnāt work, change token is executed but OpenIdDict doesnāt switch between Introspection and Direct. I tried with ChangeToken registered outside AddValidation, the same efect.
services
.AddOpenIddict()
.AddCore(options =>
{
options.UseEntityFrameworkCore()
.UseDbContext<ApplicationDbContext>()
.ReplaceDefaultEntities<Client, Authorization, Scope, Token, int>();
})
.AddServer(options =>
{
options
.SetTokenEndpointUris("connect/token")
.SetRevocationEndpointUris("connect/revocation")
.SetIntrospectionEndpointUris("connect/introspect");
options.AddEventHandler<OpenIddictServerEvents.ProcessSignInContext>(builder =>
{
builder.UseInlineHandler(context =>
{
if (context.Transaction.Request != null)
{
context.Response["scope"] = string.Join(" ", context.Transaction.Request.GetScopes().OrderBy(z => z));
}
return default;
});
});
options.AddEventHandler<OpenIddictServerEvents.ProcessChallengeContext>(builder =>
{
builder.UseInlineHandler(context =>
{
var authPropertiesKey = typeof(AuthenticationProperties).ToString();
if (context.Transaction.Properties.ContainsKey(authPropertiesKey))
{
var props = context.Transaction.Properties[authPropertiesKey] as AuthenticationProperties;
context.Response["message"] = props.Items["message"];
}
return default;
});
});
options.AllowClientCredentialsFlow();
options.AllowPasswordFlow();
options.AllowRefreshTokenFlow();
options.UseReferenceRefreshTokens();
options.RegisterScopes(
OpenIddictConstants.Permissions.Scopes.Profile.Replace(OpenIddictConstants.Permissions.Prefixes.Scope, string.Empty),
OpenIddictConstants.Permissions.Scopes.Roles.Replace(OpenIddictConstants.Permissions.Prefixes.Scope, string.Empty),
CustomScopes.APPLICATION,
CustomScopes.IDENTITY_SETUP,
CustomScopes.SUPPORT_PACKAGE);
options.SetAccessTokenLifetime(TimeSpan.FromHours(1));
options.SetRefreshTokenLifetime(TimeSpan.FromDays(7));
options.AddEncryptionCertificate(signingCertificate)
.AddSigningCertificate(signingCertificate);
options.DisableAccessTokenEncryption();
options.UseAspNetCore()
.EnableTokenEndpointPassthrough();
})
.AddValidation(options =>
{
SetValidation(options);
ChangeToken.OnChange(configuration.GetReloadToken, () => SetValidation(options));
});
SetValidation method
private static void SetValidation(OpenIddictValidationBuilder builder)
{
MasterUrlManager masterSettings = MasterUrlManager.Get();
if (!string.IsNullOrWhiteSpace(masterSettings.Host) && masterSettings.Status == MasterStatus.Healthy)
{
string clientId = LocalClientManager.GetId();
builder.SetIssuer($"https://{masterSettings.Host}:{masterSettings.HttpsPort}/");
builder.AddAudiences(clientId);
builder.UseIntrospection()
.SetClientId(clientId)
.SetClientSecret(LocalClientManager.GetSecret());
builder.UseSystemNetHttp();
}
else
{
builder.UseLocalServer();
}
builder.UseAspNetCore();
}
Issue Analytics
- State:
- Created 8 months ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
How can I change annotations/Hibernate validation rules at ...
One way to customize hibernate validator is to write your own annotations, but that won't work for what DR is trying to do...
Read more >How to allow creating and changing validation rules at ...
I am trying to create a runtime validation engine based on all your types of validations in the validation module, and let administratorsĀ ......
Read more >How to: Customize Data Field Validation in the Data Model ...
In the Name box, enter the name of the custom validation attribute class. You can use any name that is not already being...
Read more >How to set/clear validationRules.type 'required' at dxForm ...
Hi Alexey,. To modify the form item validationRules option at runtime, you can use the itemOption dxForm method. You can find more informationĀ ......
Read more >Validating object's type at runtime? : r/typescript
To do this you must define the type at runtime so that a library like io-ts can validate against it. This is necessary...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Note: itās absolutely not specific to OpenIddict, so you can use the same approach with any other library that uses
Microsoft.Extensions.Options
.Awesome! šš»
Thanks again for sponsoring the project, much appreciated ā¤ļø