Skip to content

Commit

Permalink
feat(DefaultOAuth2TokenCallback): Allow overriding tid claim (#663)
Browse files Browse the repository at this point in the history
As it's not a standard claim, it should be possible to override it by
the consumer of the library.
  • Loading branch information
oddsund authored Apr 17, 2024
1 parent c0cb266 commit 4e3819d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ open class DefaultOAuth2TokenCallback
}

override fun addClaims(tokenRequest: TokenRequest): Map<String, Any> =
claims.toMutableMap().apply {
putAll(
mapOf(
"azp" to tokenRequest.clientIdAsString(),
"tid" to issuerId,
),
)
mutableMapOf<String, Any>(
"tid" to issuerId,
).apply {
putAll(claims)
put("azp", tokenRequest.clientIdAsString())
}

override fun tokenExpiry(): Long = expiry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ internal class OAuth2TokenCallbackTest {
}
}
}

@Test
fun `Allow overriding tid`() {
val tokenRequest = clientCredentialsRequest()
DefaultOAuth2TokenCallback().asClue {
it.addClaims(tokenRequest) shouldContainAll mapOf("tid" to "default")
}

DefaultOAuth2TokenCallback(claims = mapOf("tid" to "test-tid")).asClue {
it.addClaims(tokenRequest) shouldContainAll mapOf("tid" to "test-tid")
}
}

}

private fun authCodeRequest(vararg formParams: Pair<String, String>) =
Expand Down

0 comments on commit 4e3819d

Please sign in to comment.