Created
February 9, 2018 22:53
-
-
Save bandrzejczak/314a8129abccc239d73d06f0b58aad96 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 obtainImpersonatorToken(): Future[String] = { | |
import io.circe.generic.auto._ | |
sttp | |
.post(uri"${config.authServerUrl}/realms/${config.realm}/protocol/openid-connect/token") | |
.body( | |
"grant_type" -> "password", | |
"username" -> config.impersonatorUsername, | |
"password" -> config.impersonatorPassword, | |
"client_id" -> config.clientId | |
) | |
.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.access_token) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment