4

Trying to use firebase auth as the authentication system. I have read through the verify ID token docs and went through the Firebase SDK Setup. Using GAE and Datastore as backend, Python and webapp2 framework.

Whenever trying to verify id token

decoded_claims = auth.verify_id_token(id_token)

I get the below warning and error (using Mac), error happens when using the auth module in general, ex: when trying to use get_user, get_user_by_email...etc.

Warning

Warning: urllib3 is using URLFetch on Google App Engine sandbox instead of sockets. To use sockets directly instead of URLFetch see https://urllib3.readthedocs.io/en/latest/reference/urllib3.contrib.html.

Error

File /<mypath>/lib/cachecontrol/adapter.py", line 26, in __init__
super(CacheControlAdapter, self).__init__(*args, **kw)
File "/<mypath>/lib/requests/adapters.py", line 121, in __init__
super(HTTPAdapter, self).__init__()
TypeError: super(type, obj): obj must be an instance or subtype of type

The error seems to be related to the libraries requests and cachecontrol and not something related to our code. My guess is that this is related to the installation of some libraries which may have been missing some dependencies. We install all libraries to a /lib folder under our project as indicated in the docs here using:

sudo pip install -t <path>/lib <library>

Including the installation for firebase-admin i.e. sudo pip install -t <path>/lib firebase-admin

Updated the Firebase SDK to 2.12.0, tried removing and reinstalling Firebase auth, read through Verify ID tokens using a third-party JWT library (still having problems getting it to work) which seems like a workaround rather than using the Admin SDK directly and makes more sense. Anyone knows a solution around the TypeError: super(type, obj): obj must be an instance or subtype of type error?

UPDATE 1

Reading through Another super() wrinkle – raising TypeError regarding the TypeError, I checked line 121 in the file adapters.py as logged in the error output

/lib/requests/adapters.py", line 123, in __init__ super(HTTPAdapter, self).__init__()

and added print statements as noted in the above blog

print "HTTPAdapter", HTTPAdapter
print isinstance(self, HTTPAdapter)

and got the same False output result!

HTTPAdapter <class 'requests_toolbelt.adapters.appengine.AppEngineAdapter'>
True
HTTPAdapter <class 'requests_toolbelt.adapters.appengine.AppEngineAdapter'>
True
HTTPAdapter <class 'requests_toolbelt.adapters.appengine.AppEngineAdapter'>
True
HTTPAdapter <class 'requests_toolbelt.adapters.appengine.AppEngineAdapter'>
True
HTTPAdapter <class 'requests_toolbelt.adapters.appengine.AppEngineAdapter'>
True
HTTPAdapter <class 'requests_toolbelt.adapters.appengine.AppEngineAdapter'>
True
HTTPAdapter <class 'requests_toolbelt.adapters.appengine.AppEngineAdapter'>
True
HTTPAdapter <class 'requests_toolbelt.adapters.appengine.AppEngineAdapter'>
True
HTTPAdapter <class 'requests_toolbelt.adapters.appengine.AppEngineAdapter'>
False

So apparently this seems to be called multiple times and isinstance is failing for the last call which is raising the error.. Not sure why no one else seem to have encountered that when using Firebase auth with those libraries..

5
  • Have you installed the requests-toolbelt, and followed the additional set up instructions for App Engine? google-auth.readthedocs.io/en/latest/… Commented Jul 30, 2018 at 0:00
  • Yup, I did that earlier and followed the steps from stackoverflow.com/questions/9604799/… Commented Jul 30, 2018 at 0:39
  • I opened a python terminal and tried using the SDK directory from there (versus, running from local Google App Engine!) and it works from the terminal! So it is clearly something related to libraries and dependencies. since for GAE libraries are installed in a separate lib folder. I tried comparing some of the files from the system path to the ones in the GAE lib folder, ex: requests, cachecontrol, jwt but I believe they are either the same version or the ones in the lib are actually the updates ones! Commented Jul 30, 2018 at 3:34
  • Following through with some debugging, I stumbled upon thingspython.wordpress.com/2010/09/27/… which discusses when this error is thrown when using super and module reload occurs in the code. Not sure, why no one else had this error as it seems related to requests/adapters.pymodule... Commented Jul 30, 2018 at 11:56
  • I tried removing firebase-admin (latest version 2.12.0) and reinstalled it again using version 2.9.0 instead pip install -t ./lib/ "firebase-admin==2.9.0" and function get_user_by_phone_number worked without errors! function verify_id_token is giving a permission denied error. Unfortunately, this means that the latest version doesn't work with this setup environment(!) that means newer functions like session cookies won't be accessible! Commented Aug 1, 2018 at 16:01

2 Answers 2

3

The problem was that I have misplaced the requests_toolbelt.adapters.appengine.monkeypatch line in my code. I don't remember why it was moved down after importing firebase and credentials and auth. But for some reason it was moved down thus causing the error to happen.

The wrong placement:

import webapp2

import requests_toolbelt.adapters.appengine

from firebase_admin import credentials
from firebase_admin import auth
import firebase_admin

cred = credentials.Certificate(myjson)
default_app = firebase_admin.initialize_app(cred)

requests_toolbelt.adapters.appengine.monkeypatch() # <-- wrong placement!

The correct placement:

import webapp2

import requests_toolbelt.adapters.appengine
requests_toolbelt.adapters.appengine.monkeypatch() # <-- correct placement!

from firebase_admin import credentials
from firebase_admin import auth
import firebase_admin

cred = credentials.Certificate(myjson)
default_app = firebase_admin.initialize_app(cred)

Although embarrassing, but I will keep this here in case someone else faces the same issue!

Sign up to request clarification or add additional context in comments.

2 Comments

Sadly, this didn't solve it for me. Did you change anything else?
Can you use firebase_admin with a later version (>2.9.1)? Maybe that's the problem I'm seeing.
0

I had the same exact problem but sadly the monkeypatching alone did not work for me what did work is switching firebase-admin to version 2.9.1

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.