From f3cfd364f9eb0efdec2abaffb3d48e6fc588ae1c Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Fri, 1 Dec 2023 08:44:40 +0300
Subject: Bump jjwt to 0.12.3
Upgrade API usage
---
pom.xml | 2 +-
.../scribejava/apis/AppleClientSecretGenerator.java | 18 +++++++++++-------
src/test/java/com/juick/server/tests/ServerTests.java | 14 +++++++-------
3 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3677a5e9..e912878c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -20,7 +20,7 @@
17
0ecd48781b
0.21.0
- 0.11.5
+ 0.12.3
2.1.0
diff --git a/src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java b/src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java
index 21254550..df98ee64 100644
--- a/src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java
+++ b/src/main/java/com/github/scribejava/apis/AppleClientSecretGenerator.java
@@ -30,13 +30,17 @@ public record AppleClientSecretGenerator(String subject, String teamId, String k
public String getClientSecret() {
Instant now = Instant.now();
return Jwts.builder()
- .setHeaderParam("kid", keyId)
- .setIssuer(teamId)
- .setAudience("https://appleid.apple.com")
- .setIssuedAt(Date.from(now))
- .setSubject(subject)
- .setExpiration(Date.from(ZonedDateTime.ofInstant(now, ZoneId.of("UTC")).plusMonths(1).toInstant()))
- .signWith(signingKey.getKey(), SignatureAlgorithm.ES256)
+ .header()
+ .add("kid", keyId)
+ .and()
+ .issuer(teamId)
+ .audience()
+ .add("https://appleid.apple.com")
+ .and()
+ .issuedAt(Date.from(now))
+ .subject(subject)
+ .expiration(Date.from(ZonedDateTime.ofInstant(now, ZoneId.of("UTC")).plusMonths(1).toInstant()))
+ .signWith(SignatureAlgorithm.ES256, signingKey.getKey())
.compact();
}
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index ce9b49d0..9a46f691 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -2445,18 +2445,18 @@ public class ServerTests {
}
@Test
- public void testAppleClientSecret()
- throws NoSuchAlgorithmException, IOException, InvalidKeySpecException, NoSuchProviderException {
+ public void testAppleClientSecret() {
String secret = new String(clientSecretGenerator.getClientSecret().getBytes(), StandardCharsets.UTF_8);
final java.security.Key publicKey = clientSecretGenerator.getPublicKey();
- Jws jwt = Jwts.parserBuilder().setSigningKey(publicKey).build().parseClaimsJws(secret);
+ Jws jwt = Jwts.parser()
+ .setSigningKey(publicKey).build().parseClaimsJws(secret);
assertThat(jwt.getHeader().get("kid"), is("keyid"));
assertThat(jwt.getHeader().get("alg"), is("ES256"));
- Claims claims = jwt.getBody();
- assertThat(claims.get("iss"), is("teamid"));
- assertThat(claims.get("sub"), is("com.example.app"));
- assertThat(claims.get("aud"), is("https://appleid.apple.com"));
+ Claims claims = jwt.getPayload();
+ assertThat(claims.getIssuer(), is("teamid"));
+ assertThat(claims.getSubject(), is("com.example.app"));
+ assertThat(claims.getAudience().contains("https://appleid.apple.com"), is(true));
}
@Test
--
cgit v1.2.3