Created
February 9, 2018 22:56
-
-
Save bandrzejczak/2801063e2a296cf988917ffc879b0e3d 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 obtainTokenBasedOnIdentity(impersonatedUserCookies: Seq[(String, String)]): Future[(String, Duration)] = { | |
val authUri = uri"${config.authServerUrl}/realms/${config.realm}/protocol/openid-connect/auth" | |
sttp | |
.get(uri"$authUri?response_mode=fragment&response_type=token&client_id=${config.clientId}&redirect_uri=${config.redirectUri}") | |
.cookies(impersonatedUserCookies: _*) | |
.followRedirects(false) // The response comes in the form of redirect | |
.send() | |
.map(extractTokenAndExpiration) | |
.flatMap { | |
case Some(tokenAndDuration) => Future.successful(tokenAndDuration) | |
case None => Future.failed(new RuntimeException("Failed to extract token and duration from response headers")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment