protected def requestRefresh()

in app/controllers/Auth.scala [400:439]


  protected def requestRefresh(refreshToken:String) = {
    val params = Map(
      "grant_type"->"refresh_token",
      "refresh_token"->refreshToken
    )
    val encodedParams = assembleFromMap(params)
    val contentBody = HttpEntity(ContentTypes.`application/x-www-form-urlencoded`, encodedParams)
    val headers = scala.collection.immutable.Seq(
      Accept(MediaRange(MediaTypes.`application/json`)), Origin(HttpOrigin(config.get[String]("oAuth.origin")))
    )
    val req = HttpRequest(HttpMethods.POST, config.get[String]("oAuth.tokenUrl"), headers, contentBody)

    (for {
      response <- http.singleRequest(req)
      responseBody <- consumeBody[OAuthResponse](response.entity)
    } yield (response, responseBody) ).map({
      case (response, Right(oAuthResponse))=>
        response.status match {
          case StatusCodes.OK=>
            Right(oAuthResponse)
          case StatusCodes.BadGateway | StatusCodes.ServiceUnavailable=>
            Left("Authorization server is not available at the moment, hopefully refresh will work next time")
          case _=>
            Left(s"Server returned ${response.status}")
        }
      case (response, Left(err))=>
        logger.error(s"Could not parse response from server: $err")
        response.status match {
          case StatusCodes.BadGateway | StatusCodes.ServiceUnavailable=>
            Left("Authorization server is not available at the moment, hopefully refresh will work next time")
          case StatusCodes.BadRequest=>
            Left("Internal error, server rejected our request")
          case StatusCodes.InternalServerError=>
            Left("Authorization server failed trying to process our request, contact Infrastructure")
          case _=>
            Left(s"Server returned ${response.status}")
        }
    })

  }