mirror of
https://github.com/ysoftdevs/odc-analyzer.git
synced 2026-01-14 07:44:00 +01:00
24 lines
878 B
Scala
24 lines
878 B
Scala
package services
|
|
|
|
import play.api.libs.json.Json
|
|
import play.api.libs.ws.{WS, WSClient}
|
|
|
|
import scala.concurrent.{Future, ExecutionContext}
|
|
|
|
case class LoginResponse(error: Option[String], email: Option[String])
|
|
|
|
class ExternalCredentialsVerificationService(url: String)(implicit executionContext: ExecutionContext, wSClient: WSClient) extends CredentialsVerificationService{
|
|
|
|
private implicit val loginResponseFormat = Json.format[LoginResponse]
|
|
|
|
override def verifyCredentials(username: String, password: String): Future[Either[String, String]] = {
|
|
WS.clientUrl(url).post(Json.toJson(Map("username" -> username, "password" -> password))).map{ response =>
|
|
val loginResponse = loginResponseFormat.reads(response.json).get
|
|
loginResponse.error match {
|
|
case Some(err) => Left(err)
|
|
case None => Right(loginResponse.email.get)
|
|
}
|
|
}
|
|
}
|
|
}
|