diff --git a/core/src/main/java/tech/ydb/core/auth/JwtUtils.java b/core/src/main/java/tech/ydb/core/auth/JwtUtils.java index 1ca346e0..e82e24b5 100644 --- a/core/src/main/java/tech/ydb/core/auth/JwtUtils.java +++ b/core/src/main/java/tech/ydb/core/auth/JwtUtils.java @@ -23,48 +23,12 @@ public class JwtUtils { private JwtUtils() { } private static class JwtClaims { - @SerializedName("iss") - private String issuer; - @SerializedName("sub") - private String subject; - @SerializedName("aud") - private String audience; @SerializedName("exp") private Long expiredAt; - @SerializedName("nbf") - private Long notBeforeAt; - @SerializedName("iat") - private Long issuedAt; - @SerializedName("jti") - private String jwtID; - - public String getIssuer() { - return this.issuer; - } - - public String getSubject() { - return this.subject; - } - - public String getAudience() { - return this.audience; - } public Long getExpiredAt() { return this.expiredAt; } - - public Long getNotBeforeAt() { - return this.notBeforeAt; - } - - public Long getIssuedAt() { - return this.issuedAt; - } - - public String getJwtID() { - return this.jwtID; - } } public static Instant extractExpireAt(String jwt, Instant defaultValue) { diff --git a/core/src/test/java/tech/ydb/core/auth/JwtUtilsTest.java b/core/src/test/java/tech/ydb/core/auth/JwtUtilsTest.java new file mode 100644 index 00000000..3bd77750 --- /dev/null +++ b/core/src/test/java/tech/ydb/core/auth/JwtUtilsTest.java @@ -0,0 +1,27 @@ +package tech.ydb.core.auth; + +import java.time.Instant; + +import org.junit.Assert; +import org.junit.Test; + +/** + * + * @author Aleksandr Gorshenin + */ +public class JwtUtilsTest { + + @Test + public void parseTest() { + // { "alg": "HS256", "typ": "JWT" }.{ "sub": "1234567890", "iat": 1516239022, "exp": 1726544488 } + String jwt1 = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE3MjY1NDQ0ODh9"; + // { "alg": "HS256", "typ": "JWT" }.{ "aud": "Base", "sub": "1234567890", "iat": 1516239022, "exp": 1726544488 } + String jwt2 = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJCYXNlIiwic3ViIjoiMTIzNDU2Nzg5MCIsImlhdCI6MTUxNjIzOTAyMiwiZXhwIjoxNzI2NTQ0NDg4fQ"; + // { "alg": "HS256", "typ": "JWT" }.{ "aud": [ "Base" ], "sub": "1234567890", "iat": 1516239022, "exp": 1726544488 } + String jwt3 = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiQmFzZSJdLCJzdWIiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE3MjY1NDQ0ODh9"; + + Assert.assertEquals(Instant.ofEpochSecond(1726544488), JwtUtils.extractExpireAt(jwt1, Instant.EPOCH)); + Assert.assertEquals(Instant.ofEpochSecond(1726544488), JwtUtils.extractExpireAt(jwt2, Instant.EPOCH)); + Assert.assertEquals(Instant.ofEpochSecond(1726544488), JwtUtils.extractExpireAt(jwt3, Instant.EPOCH)); + } +}