Closed kesane-msft closed 4 years ago
@kesane-msft nice work in figuring out a workaround. Definitely a bug we should fix.
@kesane-msft what is happening here is we throw without trying all keys. We should add a try / catch inside GetContentEncryptionKeys.
@brentschmaltz - not sure I get your comment over here. Could you please elaborate a bit more?
@kesane-msft we throw without trying the rest of the keys, so unless the first one works we fault.
My application receives encrypted web tokens from AAD. I am using the OWIN middleware for setting up the token decryption parameters. I am setting the
TokenValidationParameters.TokenDecryptionKeys
with a set of two certificates either of which might be used to encrypt the token. (I am testing the certificate rotation flow). However, when I am testing the code, I see the following error being reported -If I remove the certificate which is currently not being used to encrypt the tokens then the error goes away.
I believe this has to do with the code here - https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/e4928aff114bf17ee04bd0360b15da6d33694b06/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.cs#L966
It should not be enclosing the if condition at https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/blob/e4928aff114bf17ee04bd0360b15da6d33694b06/src/Microsoft.IdentityModel.JsonWebTokens/JsonWebTokenHandler.cs#L981
Looking for suggestions of what is the correct way out here.
Currently to unblock myself, I am adding a token decryption key resolver with the following code - (which is heavily influenced with the code in JsonWebTokenHandler)