3

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?

mattmar10
  • 515
  • 1
  • 4
  • 16
  • does the bearer token need to be encoded in some way? – mattmar10 Apr 12 '22 at 15:15
  • would `.addCredentials` work? (instead of withHeaders method) – AminMal Apr 12 '22 at 15:17
  • I think it would be worth checking what is actually rendered for that header on the request. It could give you a hint at the root of the problem. Just fire that request against netcat for example and see what you're getting – artur Apr 12 '22 at 20:53

1 Answers1

1

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.

mattmar10
  • 515
  • 1
  • 4
  • 16