question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calls to firebase_auth.get_user() can add 100-200ms to request time

See original GitHub issue

Hi,

Just reviewing my web API performance and found high latency whenever firebase_auth.get_user() is called, since it sends a blocking HTTP request to the Firebase Auth API.

I’ve read a few different Python Firebase Auth tutorials and they all just use the decoded JWT to supply user data, they do not make a call out to the Firebase web API. This makes sense since a synchronous HTTP call is bad for performance.

If FIREBASE_CHECK_JWT_REVOKED is enabled, the get_user() call is made twice per request cycle. One of these calls is surely redundant.

Apart from revocation is there a reason to fetch the user rather than using the properties that are already embedded in the JWT?

Thanks!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
garyburgmanncommented, May 7, 2021

Hey guys this is still on my radar, just need to find time to get my head into it. Thanks for the feedback so far!

If there is some sort of consensus re: best way forward and I haven’t gotten to it yet, feel free to make a pull req.

Have opened a ticket in Trello to track this, feel free to add code snippets/screenshots/more info

https://trello.com/c/RlMcBCmi

2reactions
Longwelwindcommented, May 6, 2021

I’ve looked a bit into this question, here are the result of my investigation, so that if someone is interested in solving this, s.he can have more info on this. At the moment, when a request is received by Django, FirebaseAuthentication:

  • Decodes the uid out of the JWT token
  • Fetches the Firebase user data based on the uid (including the email)
  • Check if a local user already exists with this email
    • If no, create a local user associated with this mail
  • Return the local user (either fetch or created)

The step in bold includes a request to Firebase.

What it truly should be doing is:

  • Decodes the uid and the email out of the JWT token
  • Check if a local user already exists with this email
    • If no, fetch the Firebase user data, create a local user associated with this mail based on the firebase user data.
  • Return the local user (either fetch or created)

That way, a trip to Firebase is only needed during local user creation. In case the local user creation doesn’t require data from the firebase user, a request to Firebase is not even needed.

I’ll try to create a PR if I get the time to do this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase Authentication Limits
The following limits are daily usage limits for users of Firebase Authentication with Identity Platform on the no-cost Spark plan.
Read more >
Build a Role-based API with Firebase Authentication - Toptal
In a nutshell, Firebase Authentication is an extensible token-based auth ... Now, we can call the API to get the logged-in user by...
Read more >
Using Firebase Authentication - FlutterFire
If the user signs in anonymously multiple times, they will be signed-in with the ... To get started, call the signInAnonymously() method on...
Read more >
Getting started with Firebase Authentication on the web
In this episode of Firebase Fundamentals, Firebase Developer Advocate Peter Friese will show you how to get up and running quickly with ...
Read more >
Firebase Auth Tutorial #15- Firestore Users Collection
Hey gang, in this Firebase auth tutorial I'll show you how to create a Users collection in our Firestore database and store additionaluser ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found