Skip to content

Instantly share code, notes, and snippets.

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