0

I'm implementing custom authentication in Google Cloud Endpoints for an Android app. To do so, I'm sending an auth token in an HTTP header. From Android:

private static final String HEADER_AUTH_TOKEN = "HTTP_AUTHORIZATION";

private GoogleClientRequestInitializer requestInitializer =
    new GoogleClientRequestInitializer() {

   @Override
   public void initialize(AbstractGoogleClientRequest<?> request) throws IOException {
      HttpHeaders headers = request.getRequestHeaders();
      if (authPrefs.authToken().exists()) {
          headers.set(HEADER_AUTH_TOKEN, authPrefs.authToken().get().toString());
      }
      request.setRequestHeaders(headers);
   }
};

Api.Builder apiBuilder = new Api.Builder(
    AndroidHttp.newCompatibleTransport(),
    new GsonFactory(),
    null);

return apiBuilder.setApplicationName(APPLICATION_NAME)
         .setGoogleClientRequestInitializer(requestInitializer)
         .build()

Then in Python I'm trying to retrieve the auth token header:

import os
auth_token = os.getenv('HTTP_AUTHORIZATION')

auth_token is None. What am I missing?

1 Answer 1

1

It turns out "HTTP_" was being prepended to any HTTP header sent. HTTP_AUTHORIZATION was being sent as "HTTP_HTTP_AUTHORIZATION".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.