Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move to google-auth? #529

Closed
bnorquist opened this issue Apr 4, 2018 · 19 comments
Closed

move to google-auth? #529

bnorquist opened this issue Apr 4, 2018 · 19 comments

Comments

@bnorquist
Copy link

gspread does not seem to be compatible with credential objects generated by google.auth library. Since oauth2client has been deprecated is there a plan to move to the new library for auth?
The documentation for google.auth is already superior to that of oauth2client and works in a very similar manner.

@burnash
Copy link
Owner

burnash commented Apr 8, 2018

@bnorquist good idea. I'm open to moving away from oauth2client. If someone wants to take a crack at this, it'll be more than welcome.

@bnorquist
Copy link
Author

Sounds good, I might have some time in the next few weeks to work on it. If so I'll make a pr and update this thread.

@andrewjmetzger
Copy link

@bnorquist @burnash I'd love to try and help. Let me know what you need. :-)

@whatareyoutalkingaboutyousoundinsane
Copy link

whatareyoutalkingaboutyousoundinsane commented Apr 24, 2018

Hey, uh, no idea who yall are but, I'm out here tryna use google-auth with gspread (to read & write Google Sheets), and i'm having the
AttributeError: 'Credentials' object has no attribute 'access_token'
error.

Are yall the people who actually work on this library?? if so that's cool and also lmk if there's been progress on this cos i'm reallyyyy tryna get into this google sheets + python action rn thaaaanks (??)

@andrewjmetzger
Copy link

Hi @whatareyoutalkingaboutyousoundinsane:

Although your issue is out-of-scope and thus technically unsupported right now, I will do my best to respond, point-by-point:

I'm out here tryna use google-auth with gspread

Unfortunately, as this is an open issue (note the "open" status and "help wanted" label), it seems the google-auth library isn't supported in gspread yet.

AttributeError: 'Credentials' object has no attribute 'access_token'

This is most likely because google-auth is not supported for now. Until support is added to gspread, please have a look at these links, which may help you authenticate successfully:

Are yall the people who actually work on this library?? if so that's cool

Collectively, yes, "we" do all contribute to this project in one way or another. There are many ways to contribute, not all of which involve writing code (although many contributors do contribute code). As for the lead maintainer, that would be burnash, whose username is conveniently found at both the top of this page, and in the repository URL. If you're looking for a list of the most active contributors to this project, check out the Contributors to burnash/gspread` page.

If you're looking for a specific person to get support from, the best solution is to comment on an issue like you already have. It's bad form to @mention specific people in a GitHub issue; please refrain from doing so.

Make sure you also take a look at some guidelines for better communication. It's not reasonable to expect everyone to have a perfect knowledge of the English language, impeccable grammar, or a high degree of technical understanding, but if you have a problem you need to get solved, please do first put forth some effort. A good first step would be to read the 15 Rules of Communicating on GitHub by Ben Balter, as well as Wiredcraft's guide to writing good GitHub issues.

also lmk if there's been progress on this

You can subscribe to this issue to get emails (by default) or push notifications from your web browser of choice (optional) when there's a new comment or progress is otherwise made on this issue. Take a look at the issue's sidebar under the Notifications heading. If what you see looks like this, you're all set:
image

Otherwise, click the Subscribe button to begin receiving email notifications for this issue when it gets updated.

@lepture
Copy link
Contributor

lepture commented Jun 14, 2018

Just a little tip on how to use gspread with Authlib:

https://blog.authlib.org/2018/authlib-for-gspread

@liquidgenius
Copy link

I was unable to get the Authlib method to work. @lepture

FileNotFoundError: [Errno 2] No such file or directory: 'your-google-conf.json'

@lepture
Copy link
Contributor

lepture commented Sep 23, 2018

@liquidgenius you need to change your-google-conf.json with the right file path.

@pdpark
Copy link

pdpark commented Sep 25, 2018

FYI: Generated a new

Just a little tip on how to use gspread with Authlib:

https://blog.authlib.org/2018/authlib-for-gspread

This is great, thanks for posting here!

I can do this in Oauth2Client:

credentials = credentials.create_delegated(user_email)

From here: https://developers.google.com/admin-sdk/directory/v1/guides/delegation

Can this be done in Authlib?

Thanks

@pdpark
Copy link

pdpark commented Sep 25, 2018

I just discovered how to do it: the "subject" parameter. If I pass the email of the account I want to impersonate in the subject parameter, it works.

@mcarans
Copy link

mcarans commented Dec 6, 2018

pygsheets uses google-auth. Perhaps its code could provide inspiration: https://github.com/nithinmurali/pygsheets/blob/staging/pygsheets/authorization.py

@stcalica
Copy link

I'm giving it a quick shot right now. For the gspread Client class it checks for auth.access_token but google-auth would just have auth.token, I'll see if I can write some clean code to check which one exists and then have a token object to do the check for refreshing. I'm sure I might have to make more changes but that basic change should be easy enough.

@case
Copy link

case commented May 17, 2019

Fwiw, and as mentioned by @mcarans above, I recently switched to using nithinmurali/pygsheets and it worked almost seamlessly as a replacement for gspread. Same service account credentials json worked, etc.

@stcalica
Copy link

Haha yes I thought it'd be as simple as just updating how to get the token from the new google-auth Credentials object, but I see nope! It's a whole new process Google has made now.
I've forked and will chip away at it. I definitely see this as a larger refactor, and will definitely be looking at nithinmurali/pygsheets for inspiration.

I think the biggest challenge I'm thinking of right now is how to still provide backwards capability for the old oauth2 library.

@aiguofer
Copy link
Collaborator

aiguofer commented May 25, 2019

The new google-auth library has google.auth.transport.requests.AuthorizedSession which is basically a requests Session with attached Credentials. It will handle token refreshes on its own and will set the headers. It could make it very simple to integrate by setting the Client.session to a AuthorizedSession instantiated with the provided credentials. The potential issue here is I'm not sure how to handle the case where a user passes in their own session... what's the main purpose of this param (when would someone want to pass in their own session)?

In order to support backward compatibility with oauth2client, a simple wrapper that converts OAuth2Credentials to google.oauth2.credentials.Credentials and ServiceAccountCredentials to google.oauth2.service_account.Credentials seems like it would do the trick.

@aiguofer
Copy link
Collaborator

aiguofer commented May 26, 2019

So took a stab at this here. It's pretty easy to implement a conversion, but it does require adding google-auth as a dependency (is this really an issue though? I imagine most people will have that installed anyway). Using AuthorizeSession handles refreshing tokens and retrying automagically so login should not be needed, but if they pass their own session, login can still be called to refresh the token.

@artemrys
Copy link
Contributor

artemrys commented Dec 5, 2019

@aiguofer can you make a PR to get your change in? It looks good.

@aiguofer
Copy link
Collaborator

aiguofer commented Dec 5, 2019

Hey, yeah sorry! I don't know why I didn't do that earlier. Here's the PR: #711

@artemrys
Copy link
Contributor

@aiguofer Great, thanks. I have added a PR aiguofer#1 to your PR :)

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

No branches or pull requests