-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support refreshtoken (as JWT) from keycloak (#242)
* feat: support keycloak refresh token format * includes nonce from auth request in a plain JWT * see #210 Co-authored-by: Youssef Bel Mekki <[email protected]>
- Loading branch information
1 parent
6ee165a
commit 5484d34
Showing
4 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/kotlin/no/nav/security/mock/oauth2/grant/RefreshTokenManagerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package no.nav.security.mock.oauth2.grant | ||
|
||
import com.nimbusds.jwt.PlainJWT | ||
import io.kotest.assertions.asClue | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.shouldNotBe | ||
import no.nav.security.mock.oauth2.token.DefaultOAuth2TokenCallback | ||
import org.junit.jupiter.api.Test | ||
|
||
internal class RefreshTokenManagerTest { | ||
|
||
@Test | ||
fun `refresh token should be a jwt with nonce included if nonce is not null (for keycloak compatibility)`() { | ||
val mgr = RefreshTokenManager() | ||
val tokenCallback = DefaultOAuth2TokenCallback() | ||
|
||
mgr.refreshToken(tokenCallback, "nonce123").asClue { | ||
val claims = PlainJWT.parse(it).jwtClaimsSet.claims | ||
|
||
claims["nonce"] shouldBe "nonce123" | ||
claims["jti"] shouldNotBe null | ||
} | ||
} | ||
|
||
@Test | ||
fun `tokencallback should be available in cache for specific refresh token`() { | ||
val mgr = RefreshTokenManager() | ||
val tokenCallback = DefaultOAuth2TokenCallback() | ||
|
||
val refreshToken = mgr.refreshToken(tokenCallback, null) | ||
mgr[refreshToken] shouldBe tokenCallback | ||
val refreshToken2 = mgr.refreshToken(tokenCallback, "nonce123") | ||
mgr[refreshToken2] shouldBe tokenCallback | ||
} | ||
} |