Comments (5)
Thanks for the quick response - this sort of helps but our code normally passes in the claims as a map.
Jwts.builder().claims().add(claims).and().signWith(key).compact()
for re-use.
As for your question, our JWT parsing code works fine, it's when we send JWT's to 3rd-parties.
Is there a way to get the single()
when using this way or do we need to use the .audience().single()
style?
FYI: this is much better than us using content() and creating the payload json ourselves.
from jjwt.
Hi there!
Now Get:
{ "aud": [ "audience" ], "exp": 1715888139211, "sub": "subject", "iat": 1715884539211, "jti": "77c6e241-79a1-435a-8a33-0d87f0d419d5", "iss": "issuer" }
How was that output produced?
It's not clear to me what you mean by backwards compatible
- are you talking how the JJWT API changes impact your application Java code directly? Or do you mean how compact JWT strings produced by JJWT now do not produce single-string aud
values by default?
The changes related to #77 ensure that an aud
value will be created as a JSON Array of Strings by default. However, when creating a new JWT, you are able to set a single string aud
value if you choose to do so, so you can retain backwards compatibility for JWT recipients that do not know how to process a set of strings. For example:
Jwts.builder()
.audience().single("singleAudValue").and()
... etc ...
.compact();
This is documented for the JwtBuilder
's audience() builder and its single(String) method supporting single-string values.
When parsing a JWT however, the aud
JSON value is always converted in the Java representation to a Set<String>
, even for a single JSON string value for two intentional reasons:
-
Your Java code never needs to change when receiving a JWT that uses a single-string-aud-value vs set-of-string-values - in both cases, JJWT normalizes the value to a
Set<String>
. It is generally a good philosophy to reduce cyclomatic complexity in a codebase by avoiding 'instanceof' checks in code with multiple branch conditions; your Java code can stay the same regardless of how a JWT issuer formats theaud
value. -
The RFC intentionally indicates that a set-of-strings should be the default for most applications so applications don't have do do the "if a string, do this, if a set of strings, do that" annoying logic. From https://tools.ietf.org/html/rfc7519#section-4.1.3:
In the general case, the "aud" value is an array of case-
sensitive strings, each containing a StringOrURI value. In the
special case when the JWT has one audience, the "aud" value MAY be a
single case-sensitive string containing a StringOrURI value. The
interpretation of audience values is generally application specific.
So JJWT 0.12.0
is not backwards compatible in Java code as to how you receive an aud
value, and this was very intentional as described above, and we tried to be clear about this in the 0.12.0 release.
However, you still have the ability to produce a single-string audience value for JWT recipients that do not process aud
set-of-string values. This is backwards compatible for JWT recipients.
Does this help?
from jjwt.
What JJWT version are you using?
#891 was merged and released in 0.12.4 and this should retain aud
single string values, even when using a Map:
Latest version is 0.12.5.
from jjwt.
Ah, we are using 0.12.3 which was the default version for used by our version of spring boot/security. Thank you.
from jjwt.
Great to hear! Thanks for the update 👍
from jjwt.
Related Issues (20)
- Disable Jackson ObjectMapper FAIL_ON_UNKNOWN_PROPERTIES Deserialization Feature HOT 1
- Unable to extract claims when cty specified in JWS header (>0.12.0) HOT 19
- Question: How far is version 1.0 (due to breaking changes in 0.12)?
- NIST Elliptic Curve JWK field element octet string padding HOT 1
- Allow parsing signed JWTs without the key HOT 1
- Impossible to build a JWK with `alg: HS512` and a `k` that is larger than 64 bytes HOT 2
- Make JacksonDeserializer constructor public
- Unable to access jcaName from Jwts.SIG HOT 2
- Jwts.builder - audience cannot be add without calling add() HOT 5
- Consider a convenience method to obtain a `Jwk` from a `JwkSet` by Key ID HOT 4
- Deprecation of support for unsecured JWT token parsing with algo != 'none' HOT 3
- NoSuchMethodError when using libraries built against older jjwt version HOT 2
- Unable to verify Elliptic Curve signature using configured ECPublicKey. Invalid encoding for signature HOT 2
- CVE reported against 0.11.5 HOT 5
- CVE-2024-31033 (v0.12.5) HOT 2
- java.lang.IllegalArgumentException: Invalid Map 'iv' (Initialization Vector) value: 1230868678. Values must be either String or [B instances. Value type found: java.math.BigInteger. HOT 4
- JWE arbitrary content compression/decompression error
- X5C header does not accept a chain of certificates longer than 1 HOT 6
- Algorithm Request/Result Builders
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jjwt.