-
Notifications
You must be signed in to change notification settings - Fork 462
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
Decoding JWT with array of Claim causes exception #427
Comments
I think it is working if I update to a prerelease nuget. So you might be able to close this. |
Hi! Yes, support for a complex object (inside claims) was added only recently. Before it was a dictionary of string, string. |
Whilst it doesn't raise an exception decoding, there is some other issue perhaps with the mapping of claims.
If I protect with a claim check on email, it works.
If I look at the ticket supplied in OnSuccessfulTicket I see.... This looks to me like nothing is getting mapped. Could it be because it was a string and now it is a complex object? |
It might have to be a comma-separated list. By default, claim value is a string, according to its constructor. Or might not be supported at all :( Please let me know what you find out - happy to learn, make any changes if necessary. Note that the screenshot shows claims that aren't present in the initial sample token. Or I'm missing something? |
The screenshot is showing that rather than a List, it is a string with the contents of the type. Shouldn't it be a real List? All the samples I've seen for Role seem to indicate it can be an array of strings. |
From quickly googling, I see it's always something like Can you share any docs when it's an array? |
I've also tried adding the role using the name "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" too, e.g.:
|
Sorry, I'm on vacation for another week, can't run any code to debug. First things first. Let's identity the primary issue. What it is? Is something not working in JWT library itself or only in ASP.NET Core extension? |
Try to change |
Another option is to continue using an array of roles but then you need to provide custom |
Upon rerun, I'll make DefaultIdentityFactory more friendly for inheritance and extension. |
Yeah, I think the problem is the extension. Having just debugged the extension I find this is the line that maps the array to a string.
There is so much conflicting information online vs APIs it is difficult to know how to proceed. I shall keep reading the MS docs as this is what we're trying to make work together. There may be a limitation in their implementation which restricts what is possible in an easy way. |
Using the DI container, register another version of the interface's implementation where you'll decode the payload and read the claims manually. |
@m1dst ping. I can publish the extension package if the proposed change would help you. |
Thanks for your speedy response. I've been looking and thinking about this but haven't yet come to a conclusion. It seems there is a clear difference between the JWT spec and the way it has been implemented in Net Core. Or perhaps in the way we are understanding it. There is ClaimValueType to consider. https://stackoverflow.com/questions/44677784/custom-claim-with-boolean-type I think for the moment a full rethink of my approach is needed until I understand why there is so much conflicting information. I want to do things a standard way rather than just override what is there and make it do things in the way I think they should work. |
Hi, let me close the issue for now. Feel free to reopen or open a new one. |
If I have an encoded JWT:
Which looks like this:
I can decode it successfully using the following code:
However, if I try to decode it as part of the ASPNetCore auth pipeline it fails with an exception.
If I have only a single claim called Role or remove it completely then it works fine. I saw something in an old issue that seemed similar and I'm wondering if that was fixed which is why I can decode it manually. Does something need fixing for the AspNetCore pipeline to make it work?
I suppose I could encode the array and decode it later but that just masks the issue.
The text was updated successfully, but these errors were encountered: