Created
February 10, 2018 17:28
-
-
Save bandrzejczak/6df2aeff5810b478a29ded99e706506d to your computer and use it in GitHub Desktop.
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
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