Failing to authorize connection to own GAE endpoints API with service account

后端 未结 1 1245
一向
一向 2021-02-11 03:59

I\'ve been beating my head against the wall trying to successfully authorize an API hit on the Google App Engine (GAE) project I\'m running from a python script using OAuth2 and

相关标签:
1条回答
  • 2021-02-11 04:28

    Thank you for the help. There are a couple things I did wrong above.

    Firstly, I needed to reference the app engine project id in the allowed ids list.

    API_ID = 'project-id-number.apps.googleusercontent.com'
    
    @endpoints.method(message_types.VoidMessage, StatusCollection,
                  allowed_client_ids=[API_ID, SERVICE_ACCOUNT_ID,
                                      endpoints.API_EXPLORER_CLIENT_ID],
                  audiences=[ANDROID_AUDIENCE],
                  scopes=[endpoints.EMAIL_SCOPE],
                  path='status', http_method='GET',
                  name='statuses.listStatus')
    

    I had incorrectly come to the assumption that the build() method would only work with official google APIS, but it turned out I was referencing my project incorrectly. With the project id in place, I could use build() instead of writing my own httplib2 call in the server side file (which didn't work).

    Erasing the code beneath 'http = credentials.authorize(http)' I replaced it with the following:

    myservice = build('my-service', 'v1', http=http, discoveryServiceUrl=discoveryServiceUrl)
    data = myservice.my-path().endpoint-name()
    results = data.execute()
    

    This successfully authorizes my account and calls the endpoint. Woot! If anyone else has questions about this, or if my solution isn't clear, please feel free to comment. This was a painful process I don't wish upon anyone else.

    0 讨论(0)
提交回复
热议问题