Skip to content

Commit f43f0d7

Browse files
committed
docs: add JWT support
1 parent 91e62c2 commit f43f0d7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,30 @@ For decryption, make sure the field's value with `encrypted:` prefix.
116116

117117
**Tips**: please use `dotenvx init --stdout` to generate a new key pair for this case. Don't use app config key pair.
118118

119+
# JWT support
120+
121+
Most web applications use JWT to authorize user, and Dotenvx Spring Boot
122+
uses [Nimbus JOSE + JWT](https://connect2id.com/products/nimbus-jose-jwt) to generate and verify JWT token.
123+
124+
```java
125+
@Test
126+
public void testGenerateJwt() throws Exception {
127+
final ECKeyPair keyPair = Ecies.generateEcKeyPair();
128+
String subject = "example-user";
129+
JWTClaimsSet claimsSet = new JWTClaimsSet.Builder()
130+
.subject(subject)
131+
.issuer("dotenvx")
132+
.issueTime(new Date())
133+
.expirationTime(new Date(System.currentTimeMillis() + 3600000)) // 1 hour expiration
134+
.build();
135+
final BCECPublicKey publicKey = keyPair.getPublic();
136+
final BCECPrivateKey privateKey = keyPair.getPrivate();
137+
final String jwtToken = Secp256k1JwtService.createJwtToken(privateKey, claimsSet);
138+
final JWTClaimsSet jwtClaimsSet = Secp256k1JwtService.verifyJwt(jwtToken, publicKey);
139+
assertThat(jwtClaimsSet.getSubject()).isEqualTo(subject);
140+
}
141+
```
142+
119143
# Credits
120144

121145
* jasypt-spring-boot: https://github.com/ulisesbocchio/jasypt-spring-boot

0 commit comments

Comments
 (0)