First I would like to describe how our system looks like. We have two servers.
The first one is on Google App Engine and has some logic that provides access to database for Android application and also has some servlets written for external communication (more about that later).
The second one is on Google Cloud Engine. Application is written in Meteor (to simplify, it's just Node.js). We would like to communicate between those servers (GCE -> GAE). We have rest API on this servlet endpoint under address e.g. https://appname.appspot.com/admin/upload. When I'm making request without authentication, everything work fine:
HTTP.get(getURL, {}, getCallback);
However, I have no idea how to do it using oAuth2 authentication. When I go to the address https://appname.appspot.com/admin/upload from the browser, it redirects me to Google authentication and everything works fine (I have my account added in the Google Console). But how to send http request from the Node.js server using oAuth2 authentication?
To give you more details, here is servlet configuration:
<security-constraint>
<display-name>SecurityConstraint</display-name>
<web-resource-collection>
<web-resource-name>WRCollection</web-resource-name>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
and
<servlet-mapping>
<servlet-name>UploadRequestServlet</servlet-name>
<url-pattern>/admin/upload</url-pattern>
</servlet-mapping>
I know that I have to set server to server communication but how to accomplish this using Node.js? Could anyone help? I don't know where to start...
If anyone have problem with server-to-server communication (Meteor.js server to Google server) using OAuth 2.0 checkout library I've created https://github.com/jagi/meteor-google-oauth-jwt. It makes calling Google REST API from Meteor.js server much simpler.