Skip to content

Use google-auth instead of oauth2client - #249

Open
heston wants to merge 5 commits into
thisbejim:masterfrom
heston:upgrade-google-auth
Open

heston wants to merge 5 commits into
thisbejim:masterfrom
heston:upgrade-google-auth

Conversation

@heston

@heston heston commented Mar 29, 2018

Copy link
Copy Markdown

This replaces the now deprecated oauth2client with google-auth. This should fix issues with token expiration.

n.b. I also sorted the imports at the top of pyrebase.py to be compliant with PEP 8.

Comment thread pyrebase/pyrebase.py
exp = datetime.timedelta(minutes=60)
return jwt.generate_jwt(payload, private_key, "RS256", exp)
claims.update(additional_claims)
credentials = jwt.Credentials.from_signing_credentials(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of creating a credentials class you don't need, you can actually use self.credentials.signer and jwt.encode directly.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally had it set up the way you described. Then, I looked at the source of jwt.Credentials.refresh and realized it did the exact same thing with a more concise API. I also thought the current approach supported better separation of concerns—pyrebase doesn't have to worry about constructing a valid JWT payload in this case.

I admit credentials.refresh(None) is a little weird, but that seemed a small price to pay to avoid duplicating the refresh method.

What do you think?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine. :)

Comment thread requirements.txt Outdated
python-jwt==2.0.1
pycrypto==2.6.1 No newline at end of file
requests>=2.11.0
gcloud>=0.17.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would strongly recommend not depending on this package at all. It's not been updated in quite some time. I'd switch to depend on the individual google-cloud-{thing} packages.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Done.

@heston

heston commented Mar 31, 2018

Copy link
Copy Markdown
Author

@thisbejim Thoughts on getting this merged?

@quoctc

quoctc commented Apr 24, 2018

Copy link
Copy Markdown

Hi @thisbejim
Do you have any plan to merge this branch into master?
I have the same issue and still waiting it's merged

Thank for your support

@quoctc

quoctc commented Apr 25, 2018

Copy link
Copy Markdown

hi @heston .

I have just tried with my application, but I think it seem to do not fix the issue:
I show you my logs, do you have any idea?
https://screencast.com/t/ur34PxSm6NHV

@rawmean

rawmean commented May 7, 2018

Copy link
Copy Markdown

I'm experiencing the intermittent 401 problem as well. Please merge the google-auth branch with master

@heston

heston commented May 17, 2018

Copy link
Copy Markdown
Author

@quoctc It looks like the oauth2 request is returning a 200 (https://accounts.google.com/o/oauth2/token), but your other endpoint (/leds/0/status.json?...) is returning a 401. It's a little hard to tell exactly what's going on, since I'm not familiar with your code. However, it could mean that the leds endpoint is not properly authenticating with the oauth2 token.

@quoctc

quoctc commented May 18, 2018

Copy link
Copy Markdown

hi @heston , Sorry I'm busy these day. So I was not uppdated my problem at here. My application was worked fine.
Thank you. This fix soo great!

@lepture

lepture commented Jun 14, 2018

Copy link
Copy Markdown

It would be better if we can pass a requests.Session argument, in this case, we can use other library as well. For instance, we can pass a session into gspread, e.g. https://blog.authlib.org/2018/authlib-for-gspread

Comment thread pyrebase/pyrebase.py
from urllib import urlencode, quote


def initialize_app(config):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example:

def initialize_app(config, session=None):
    if session is not None:
        self.requests = session
    else:
        ...

In this case we can use our own session.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lepture That's a good idea. However, I think it's a bit outside the scope of this PR. It would change the external API, and I was trying not to do that as part of this change. I'm intending for google-auth to be a drop-in replacement for oauth2client.

@Rumidom

Rumidom commented Dec 11, 2018

Copy link
Copy Markdown

im not sure if it is only on my pc, but after installing this PR i got an error : ModuleNotFoundError: No module named 'google.auth'

pip install google.auth and pip install --upgrade google-cloud-storage

solved the issue

@abdelwahebmoalla

Copy link
Copy Markdown

@heston how can I install this version ?

@heston

heston commented Jan 13, 2019

Copy link
Copy Markdown
Author

@abdelwahebmoalla I install it in "editable" mode directly from GitHub:

pip install -e git+https://github.com/heston/Pyrebase.git@a77bd6f6def656b1dcd77d938fac2707f3c4ba61#egg=Pyrebase

This has some drawbacks (mainly, it's slow, since it has to clone the repo), but generally works fine.

@abdelwahebmoalla

Copy link
Copy Markdown

For everyone using this version there has been an update to firebase and other changes should be done
you can consult this issue for more details #294

@s2t2

s2t2 commented May 18, 2022

Copy link
Copy Markdown

The oauth2client package is deprecated in favor of google-auth, but we need pyrebase to offer a new version with the change.

https://github.com/googleapis/oauth2client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants