How to set Bearer token in akka-htpp client request

Viewed 197

I’m receiving a warning from akka http when trying to make a POST request with a bearer token.

Here is the snippet where I am making the request.

val bearerToken: String = "..." 

val resp = Http(context.system)
      .singleRequest(
        HttpRequest(
          HttpMethods.POST,
          endpoint,
          entity = HttpEntity(MediaTypes.`application/json`, payloadJson)
        ).withHeaders(Authorization(OAuth2BearerToken(bearerToken))) 
      )

Then I see this in the log:

WARN akka.actor.ActorSystemImpl - Illegal header: Illegal ‘authorization’ header: Invalid input ‘2’, expected ‘=’, OWS or ‘EOI’ (line 1, column 1152): Bearer token-string-here

And the external endpoint is returning a 400, so it seems I'm doing something wrong in constructing the request. Any tips?

1 Answers

It turns out the error message was a little misleading (or confusing at best). The problem was that the endpoint not correct. Once I corrected that, it worked as expected.

Related