-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add issuer/scheme mapping middleware to improve authentication perf #287
Conversation
Hvis en bare optimaliserer rekkefølgen på definering av schemes (f.eks. ha Altinn først i options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
if (context.HttpContext.Items.TryGetValue("IsAuthenticated", out var isAuthenticated) && (bool)isAuthenticated!)
{
context.NoResult();
}
return Task.CompletedTask;
},
OnTokenValidated = context =>
{
context.HttpContext.Items["IsAuthenticated"] = true;
return Task.CompletedTask;
},
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dette var en interessant optimaliseringsøvelse. ConfigurationManager<OpenIdConnectConfiguration>
👈 her lærte jeg noe nytt.
Jeg har gitt deg noen tilbakemeldinger, men ikke av en så graverende sort at det ikke blir approved, så du får velge selv hva du gjør med dem 😃
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/ApplicationBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/JwtSchemeSelectorMiddleware.cs
Outdated
Show resolved
Hide resolved
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/ApplicationBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/TokenIssuerCache.cs
Outdated
Show resolved
Hide resolved
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/TokenIssuerCache.cs
Outdated
Show resolved
Hide resolved
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/TokenIssuerCache.cs
Outdated
Show resolved
Hide resolved
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/TokenIssuerCache.cs
Outdated
Show resolved
Hide resolved
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/TokenIssuerCache.cs
Outdated
Show resolved
Hide resolved
src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
Quality Gate passedKudos, no new issues were introduced! 0 New issues |
Fixes #212
Blir en exceptions i knyttet til autentisering, fordi en løper sekvensielt gjennom de konfigurerte issuerne en etter en.
Denne PR-en introduserer en mellomvare som lagrer i request context hvilken issuer som er brukt. For hver scheme benyttes OnMessageReceived for å sjekke om oppgitt token-issuer matcher, hvis ikke bailes det før man forsøker å dekode token/sjekke signatur/kaste. Det benyttes en singleton for å cache map mellom schema-navn og issuer (alternativt kan dette hardkodes i konfig).
Uklart om dette er verdt det. Antageligvis vil ID-porten-tokens være i kraftig flertall i prod, etterfulgt av Maskinporten, så Altinn. Så med å definere ID-porten først av de schemaene som registreres vil en muligens optimalisere nok (og slippe all koden i denne PR-en)