Skip to content

Instantly share code, notes, and snippets.

@kmikulski
Created December 5, 2018 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmikulski/58419a21d5b5eea68cd481fc55dee79c to your computer and use it in GitHub Desktop.
Save kmikulski/58419a21d5b5eea68cd481fc55dee79c to your computer and use it in GitHub Desktop.
the description for this gist
def verifyToken(token: String): Future[Option[AccessToken]] = {
val tokenVerifier = RSATokenVerifier.create(token).realmUrl(keycloakDeployment.getRealmInfoUrl)
for {
publicKey <- publicKeys.map(_.get(tokenVerifier.getHeader.getKeyId))
} yield publicKey match {
case Some(publicKey) =>
val token = tokenVerifier.publicKey(publicKey).verify().getToken
Some(token)
case None =>
log.warning(s"no public key found for id ${tokenVerifier.getHeader.getKeyId}")
None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment