title: How to generate OAuth2.0 Bearer when calling App Engine Endpoints API?
body: <p>I am providing a REST API via App Engine. I used Cloud Endpoints to generate it, although the client will not be mobile Android/iPhone but rather a known web server. Since I am familiar with this server (it is part of my application), I decided to use Service Account authorization in order to authorize the API calls (In addition, I will do IP validation, but that's beside the point).</p>
  
  <p>I made all the necessary arrangement, created a Google developer project, generated a service account id (and email), with a p12 file, and added all the annotations needed on the server side (including a User object in the implementing function).</p>
  
  <p>Now I want to implement a call to this API, and in order for it to work, I need to include a proper authorization header in my request. </p>
  
  <p>When working with Google APIs, the client libraries generate some Credential object which you later need to pass in building some Service object, which represents a Google API you wish to call. For example, if you want to access Drive API in Java, you will do:</p>
  
  <p>Drive drive = new Drive.Builder(Globals.httpTransport, Globals.jsonFactory, credential).build();</p>
  
  <p>Where credential object is the object I previously build as follows:</p>
  
  <p>credential = new GoogleCredential.Builder().setTransport(Globals.httpTransport)
  .setJsonFactory(Globals.jsonFactory)
  .setServiceAccountId(serviceAccountEmail)
  .setServiceAccountScopes(scopes)
  .setServiceAccountUser(serviceAccountUser)
  .setServiceAccountPrivateKeyFromP12File(file(serviceAccountPrivateKeyP12File))
  .build();</p>
  
  <p>However, in my case, the client is not calling a Google API, but rather my App Engine REST API. How do I go about generating (or using the credential object I created to obtain) a proper Authorization header?</p>