简体   繁体   中英

Accessing Firebase DB from Google App Engine

I am having trouble accessing Firebase DB from a GAE app. It works fine when running locally, but deployed to GAE (*.appspot.com) I get an unauthorized error back from Firebase. There is likely some obvious thing I missed...

This is the _get_http() function I use. It works fine (after doing gcloud beta auth application-default login )

def _get_http():
    _FIREBASE_SCOPES = [
    'https://www.googleapis.com/auth/firebase.database',
    #'https://www.googleapis.com/auth/userinfo.email'
    ]

    """Provides an authed http object."""
    http = httplib2.Http()

    # Use application default credentials to make the Firebase calls
    # https://firebase.google.com/docs/reference/rest/database/user-auth
    creds = GoogleCredentials.get_application_default().create_scoped(_FIREBASE_SCOPES)

    creds.authorize(http)

    return http

The error I get back from Firebase is:

{u'error': u'Unauthorized request.'}

The log from GAE looks includes this:

11:14:43.835
Attempting refresh to obtain initial access_token
11:14:44.625
Refreshing due to a 401 (attempt 1/2)
11:14:44.966
Refreshing due to a 401 (attempt 2/2)

Got it! I had commented out 'https://www.googleapis.com/auth/userinfo.email' thinking it was unnecessary. Wrong. Enabling it again, bingo!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM