Skip to content

Instantly share code, notes, and snippets.

@bandrzejczak
Created February 9, 2018 22:53
Show Gist options
  • Save bandrzejczak/314a8129abccc239d73d06f0b58aad96 to your computer and use it in GitHub Desktop.
Save bandrzejczak/314a8129abccc239d73d06f0b58aad96 to your computer and use it in GitHub Desktop.
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