0

I have a problem when I try to send an "access_token" param in the Header of Lagom HTTP RestCall:

 @Override
public HeaderServiceCall<NotUsed, GetUserInfoWrapperResponse> getUserInfo() {
    return (request, requestBody) -> {
        UUID userId;
        try {
            userId = UUID.fromString(request.getHeader("access_token").get());
            System.out.println("user id = " + userId);
            return userEntityRef(userId).ask(new GetUserInfoCommand()).thenApply(reply -> Pair.create(ResponseHeader.OK, reply.userInfo.get()));
        } catch (Exception e) {
            throw new NotFound("User with access_token ");
        }
    };
}

I always get NotFoundException, because "access_token" is not present in the header.

But, when I changed "access_token" by "access-token" it works.

When I did some research, I understand that I need to Play CrosFilter to my application.conf:

play.http.filters = "com.test.user.impl.AccessFilter"
play.filters.cors {
      // review the values of all these settings to fulfill your needs. These values are not meant for production.
      pathPrefixes = ["/cms"]
      allowedOrigins = null
      allowedHttpMethods = null
      allowedHttpHeaders = ["Origin", "X-Requested-With", "Content-Type", "Accept", "Referer", "User-Agent", "access_token", "cache-control"]
      # The exposed headers
      exposedHeaders = ["Origin", "X-Requested-With", "Content-Type", "Accept", "Referer", "User-Agent", "access_token", "cache-control"]
      supportsCredentials = false
      preflightMaxAge = 6 hour
}

But even that, "access_token" header param is always not present.

Any help? please!

Imen
  • 161
  • 2
  • 14

1 Answers1

1

This is because you used an underscore for within the name; it is not forbidden but uncommon and some servers such as Nginx drops them, unless you explicitly define them in its config file.

You can look at this question as well: Why underscores are forbidden in HTTP header names.

o-0
  • 1,713
  • 14
  • 29