Skip to content

Commit

Permalink
leave JWT signature as bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
angryziber committed Jan 31, 2024
1 parent 393b1ee commit b485cdd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions oauth/src/JWT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ data class JWT(private val token: String) {

override fun toString() = token

private val parts = token.split(".").map { it.base64UrlDecode().decodeToString() }
val headerJson get() = parts[0]
val payloadJson get() = parts[1]
private val parts = token.split(".").map { it.base64UrlDecode() }
val headerJson get() = parts[0].decodeToString()
val payloadJson get() = parts[1].decodeToString()
val signature get() = parts[2]

val header by lazy { Header(jsonMapper.parse<JsonNode>(headerJson)) }
Expand All @@ -38,6 +38,4 @@ data class JWT(private val token: String) {
val emailVerified get() = getOrNull<Boolean>("email_verified")
val locale get() = getOrNull<String>("locale")?.let { Locale.forLanguageTag(it) }
}

data class Signature(val fields: JsonNode): JsonNode by fields
}
2 changes: 1 addition & 1 deletion oauth/test/JWTTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class JWTTest {
expect(jwt.payload.subject).toEqual("1234567890")
expect(jwt.payload.name).toEqual("John Doe")
expect(jwt.payload.issuedAt).toEqual(Instant.ofEpochSecond(1516239022))
expect(jwt.signature).toEqual("SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c".base64UrlDecode().decodeToString())
expect(jwt.signature.decodeToString()).toEqual("SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c".base64UrlDecode().decodeToString())
}

@Test fun converter() {
Expand Down

0 comments on commit b485cdd

Please sign in to comment.