azure-activedirectory-identitymodel-extensions-for-dotnet icon indicating copy to clipboard operation
azure-activedirectory-identitymodel-extensions-for-dotnet copied to clipboard

[Feature Request] Add new api RequestRefreshAsync().

Open brentschmaltz opened this issue 1 year ago • 2 comments

RequestRefresh was originally implemented as sync method where the method simply reset the 'syncafter' variable so that the next GetConfigurationAsync would get new Configuration.

GetConfigurationAsync was originally blocking and guarded with a lock. The lock was removed, and configuration is obtained on a background task. This seemed reasonable as in the normal flow, new configuration is obtained periodically controlled by AutomaticRefreshInterval and is not the result of an error condition.

RequestRefresh is different, this is called when token validation fails for reasons that indicate a Configuration refresh could result in a token being successfully validated.

Last-Known-Good (LKG) logic uses a set of Configuration that successfully validated a token associated with a particular identity provider. This reduces the failure rate when an identity provider accidentally posts metadata that is invalid.

LKG logic first calls RequestRefresh (which previously reset 'syncafter'), then GetConfigurationAsync (which was blocking) to obtain new metadata before using historical Configuration.

see: https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/ae57a3cbf9bcef8a1f0789010bf19cb32035d6ab/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ValidateToken.cs#L514

RequestRefreshAsync would result in the same logic as the above two calls and provide a deterministic way to obtain new metadata.

brentschmaltz avatar Nov 26 '24 16:11 brentschmaltz

related - #3025

jennyf19 avatar Nov 26 '24 19:11 jennyf19

RequestRefresh se implementó originalmente como un método de sincronización donde el método simplemente restablecía la variable 'syncafter' para que el próximo GetConfigurationAsync obtuviera la nueva configuración.

GetConfigurationAsync originalmente estaba bloqueado y protegido con un bloqueo. El bloqueo se eliminó y la configuración se obtiene en una tarea en segundo plano. Esto parecía razonable ya que en el flujo normal, la nueva configuración se obtiene periódicamente controlada por AutomaticRefreshInterval y no es el resultado de una condición de error.

RequestRefresh es diferente, esto se llama cuando la validación del token falla por razones que indican que una actualización de la configuración podría resultar en la validación exitosa de un token.

La lógica de último valor conocido (LKG) utiliza un conjunto de configuraciones que validaron correctamente un token asociado con un proveedor de identidad en particular. Esto reduce la tasa de errores cuando un proveedor de identidad publica metadatos no válidos por accidente.

La lógica LKG primero llama a RequestRefresh (que anteriormente restablecía 'syncafter'), luego a GetConfigurationAsync (que estaba bloqueando) para obtener nuevos metadatos antes de usar la configuración histórica.

ver:

https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/ae57a3cbf9bcef8a1f0789010bf19cb32035d6ab/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.ValidateToken.cs#L514

RequestRefreshAsync tendría como resultado la misma lógica que las dos llamadas anteriores y proporcionaría una forma determinista de obtener nuevos metadatos.

[email protected]•Home

armandRobled avatar Nov 28 '24 04:11 armandRobled