无法从Cloud Endpoints Python访问HTTP标头

时间:2023-02-13 23:08:07

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:

我正在Google Cloud Endpoints中为Android应用实施自定义身份验证。为此,我在HTTP标头中发送一个身份验证令牌。来自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:

然后在Python中我试图检索身份验证令牌标头:

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

auth_token is None. What am I missing?

auth_token是无。我错过了什么?

1 个解决方案

#1


1  

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

事实证明,“HTTP_”被添加到任何发送的HTTP标头中。 HTTP_AUTHORIZATION被发送为“HTTP_HTTP_AUTHORIZATION”。

#1


1  

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

事实证明,“HTTP_”被添加到任何发送的HTTP标头中。 HTTP_AUTHORIZATION被发送为“HTTP_HTTP_AUTHORIZATION”。