0

I am integrating Firebase Authentication into my Android App. After successful login, the Android App will call some Google Cloud Endpoints running on Google App Engine.

So I need to pass the Firebase Token I received from the Authentication to the Google Cloud Endpoints. I am using the following code to call the endpoints (source)

MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
                new AndroidJsonFactory(), null)
myApiService = builder.build();

myApiService.sayHi(name).execute();

So how can I forward the token to my backend?

AL.
  • 36,815
  • 10
  • 142
  • 281
Michael Meyer
  • 2,179
  • 3
  • 24
  • 33

1 Answers1

1

You can use an HttpRequestInitializer to inject the token:

HttpRequestInitializer requestInitializer = new HttpRequestInitializer() {
  @Override
  public void initialize(HttpRequest request) throws IOException {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setAuthorization("Bearer " + getFirebaseToken());
    request.setHeaders(httpHeaders);
  }
};

MyApi.Builder builder = new MyApi.Builder(AndroidHttp.newCompatibleTransport(),
            new AndroidJsonFactory(), requestInitializer)
myApiService = builder.build();
saiyr
  • 2,575
  • 1
  • 11
  • 13