Skip to content

Instantly share code, notes, and snippets.

@bandrzejczak
Created February 10, 2018 17:28
Show Gist options
  • Save bandrzejczak/6df2aeff5810b478a29ded99e706506d to your computer and use it in GitHub Desktop.
Save bandrzejczak/6df2aeff5810b478a29ded99e706506d to your computer and use it in GitHub Desktop.
private def exchangeToken(token: String, userId: String): Future[TokenResponse] = {
import io.circe.generic.auto._
sttp
.post(uri"${config.authServerUrl}/realms/${config.realm}/protocol/openid-connect/token")
.body(
"grant_type" -> "urn:ietf:params:oauth:grant-type:token-exchange",
"client_id" -> config.clientId,
"requested_subject" -> userId,
"subject_token" -> token
)
.response(asJson[TokenResponse])
.send()
.flatMap {
_.body match {
case Left(error) => Future.failed(new RuntimeException(error))
case Right(Left(circeError)) => Future.failed(circeError)
case Right(Right(tokenResponse)) => Future.successful(tokenResponse)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment