Skip to content

Use OAuth to authenticate against BigQuery #42

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

Closed
YannBrrd opened this issue Nov 14, 2019 · 16 comments
Closed

Use OAuth to authenticate against BigQuery #42

YannBrrd opened this issue Nov 14, 2019 · 16 comments
Labels
api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API. status: will not fix Invalid (untrue/unsound/erroneous), inconsistent with product, not on roadmap. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@YannBrrd
Copy link

Hi,

Is it possible to use OAuth to authentitcate against BigQuery, using end user identity ?

Thanks.
Yann

@tswast tswast added the type: question Request for information or clarification. Not an issue. label Nov 14, 2019
@tswast
Copy link
Collaborator

tswast commented Nov 14, 2019

With "default credentials", you can use https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login, but you'll need to provide a project ID in the connection string.

Note: You'll encounter a warning from the google-auth library when using this method. It can safely be ignored, but if you want to avoid it, it's possible to create a key file associated with your user credentials. I started a PR to make such a utility to do this in pydata/pydata-google-auth#28 (Once you create a key file, set the GOOGLE_APPLICATION_DEFAULT environment variable)

@tswast
Copy link
Collaborator

tswast commented Nov 14, 2019

Obviously, this use case could be better. We should consider using the pydata-google-auth package here which will fall back to browser login when no other credentials are found.

@YannBrrd
Copy link
Author

OK. I'll dig this thanks.

In facrt, I'm targeting an update in SuperSet, using OAuth, and providing list of BgTable tables available for the connected user in a complete organisation.

Seems a bit tricky for me, but I sense there is a way.

@tswast
Copy link
Collaborator

tswast commented Nov 14, 2019

For a shared SuperSet instance, it's a little trickier than I described. #28 is an attempt at implementing it, but it used super-user permissions with service account, which isn't ideal.

Does SuperSet have a means of providing a connection string per user?

@YannBrrd
Copy link
Author

Need to check where the create_engine is called. I guess it would be better if they did...

@choprashweta
Copy link

Can there be support to directly pass a credentials object here - https://github.com/mxmzdlv/pybigquery/blob/master/pybigquery/sqlalchemy_bigquery.py#L327, directly using the credentials object returned by the OAuth authentication process to generate the client. Alternatively if the provided credentials path would accept not just service account credentials but also OAuth2 Client credentials that would work too.

@vinceatbluelabs
Copy link
Contributor

Hi @tswast--if you can provide direction on what would be a reasonable path to allow this, @choprashweta or I can prepare a PR.

@tswast
Copy link
Collaborator

tswast commented Aug 26, 2020

The fact that the connection args have to be parsed from a URL string makes this a little more difficult. The closest comparison I can think of is how the Simba ODBC driver is configured. It has an optional refresh_token argument for OAuth authentication.

If specified in the URL, the refresh_token can be passed to the google.oauth2.credentials.Credentials constructor. No access token is necessary.

credentials = google.oauth2.credentials.Credentials(None, refresh_token=refresh_token)

@tswast
Copy link
Collaborator

tswast commented Feb 2, 2021

To support non-"offline" credentials, it may also be desirable to add an access_token parameter. Though note that any access_token will expire within an hour.

@codegeekjk
Copy link

codegeekjk commented Feb 9, 2021

@YannBrrd @tswast are any workaround available for superset ? superset is using this library for connecting to Bigquery.
Currently we want impersonate user via Superset so only users which have access to particular dataset can query it.

We are using service account json for connection and in current scenario user can query all the available datasets.

@codegeekjk
Copy link

anyone can provide me some pointers for the implementation so i can work on this.

@tswast tswast added the api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API. label Mar 23, 2021
@jaythacker
Copy link

has anyone worked on this? or if anyone can provide any direction, I can look into that.

@tswast
Copy link
Collaborator

tswast commented Aug 3, 2021

Adding access_token and refresh_token as URL parameters to the connection string is the most important thing to support this use case.

#42 (comment)

A credentials object would be the most robust implementation, and I'd love to support that if possible. Perhaps worth filing a separate issue for that.

@lucidsushi
Copy link

has anyone tried using domain-wide-delegation so that the service account impersonates the user and only uses the user's permission scope when it comes to accessing BigQuery?

@meredithslota meredithslota added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: question Request for information or clarification. Not an issue. labels Apr 4, 2023
@chalmerlowe
Copy link
Collaborator

Due to conflicting priorities, closing as Won't Fix.

@chalmerlowe chalmerlowe added the status: will not fix Invalid (untrue/unsound/erroneous), inconsistent with product, not on roadmap. label Apr 14, 2023
@muhajirakbarhsb
Copy link

is anyone now can use acces_token and refresh token in sqlalchemy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API. status: will not fix Invalid (untrue/unsound/erroneous), inconsistent with product, not on roadmap. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants