Created
February 9, 2018 22:55
-
-
Save bandrzejczak/2f25a0fa38df6fec53b8e3f04afbe56e 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 getUserId(username: String, token: String): Future[String] = { | |
import io.circe.generic.auto._ | |
sttp | |
.get(uri"${config.authServerUrl}/admin/realms/${config.realm}/users?username=$username") | |
.auth.bearer(token) | |
.response(asJson[List[UserResponse]]) | |
.send() | |
.flatMap { | |
_.body match { | |
case Left(error) => Future.failed(new RuntimeException(error)) | |
case Right(Left(circeError)) => Future.failed(circeError) | |
case Right(Right(user :: Nil)) => Future.successful(user.id) | |
case _ => Future.failed(new RuntimeException(s"Couldn't find a single user with username $username")) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment