I am trying to execute a function provided by one app engine app that I have written (python) that uses Endpoints, in a second similar app engine app.
I currently have both app engine applications running on appspot using endpoints with oauth2. I have a working javascript client that consumes the endpoint, executes the functions with authorization and authentication. So I know the backend app engine servers are working and are a properly exposed endpoint. I can also browse the API using the api explorer and the discovery service.
Since this is a server to server link, I think that Service Accounts are what I want to use for the oauth2 authentication. So I created the Service account in the client app on the app engine console.
Here is the code that runs on the caller:
f = file('key2.pem', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
'my-service-account-email-from-caller-app@developer.gserviceaccount.com',
key,
scope='https://my-app-id.appspot.com/_ah/api/my-api/v1')
http = credentials.authorize(httplib2.Http())
service = build("my-api", "v1", http=http)
When I run this code, I get an error: AccessTokenRefreshError: invalid_grant
I have tried many other things, adding a developerKey or a discoveryUrl parameter to the credentials, still invalid grant. I looked at other people who have seen this error and have tried messing with the clocks, although this is a server to server call so I don't think that is the problem. I have added the caller's service account email address to the permissions of the callee app.
I have not found a sample app or a post about using service accounts to call a custom Endpoints API, only to call Google APIs such as Youtube or Plus, most of which have a method for registering a calling app engine application.
Has anyone been able to call an endpoint api function on one app engine application with another app engine application using oauth2?
Thanks in advance, -mat