I'm trying to split a monolith Google App Engine application (using Python & standard environment) into several services within one application. Default service is calling API implemented using the Endpoints framework in another service.
Everything works nicely except that I don't understand how to correctly check authentication of the default service (and make it work both in local development server and in production).
To call the service I'm using google-api-python-client
and default application credentials.
from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials
service = build(
name, version,
credentials=GoogleCredentials.get_application_default(),
discoveryServiceUrl=discovery_url)
service.client_token().execute()
My service API code looks like the following
@endpoints.api(
name='test',
version='v1',
)
class TestApi(remote.Service):
@endpoints.method(
message_types.VoidMessage,
TestResponse,
path='test',
http_method='GET',
name='test')
def get_test(self, request):
# user = endpoints.get_current_user()
# if not user:
# raise endpoints.UnauthorizedException
return TestResponse(test='test')
In production endpoints.get_current_user()
seems to return a correct application user, but I don't know how to correctly validate that it's the same application. In local development environment endpoints.get_current_user()
returns None
.