Skip to content

Add get_user_credentials function to get your user credentials. #40

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

Merged
merged 9 commits into from
Jun 10, 2019

Conversation

tswast
Copy link
Contributor

@tswast tswast commented Apr 26, 2019

This function is intended to be used in interactive code examples, such
as from a Jupyter notebook or when developing scripts locally. It uses
the same client ID as the gcloud auth authentication-default login
command-line tool, so should work for most Google APIs.

Tested manually with the BigQuery API:

import os

import google_auth_oauthlib
from google.cloud import bigquery

credentials = google_auth_oauthlib.get_user_credentials(
    ["https://www.googleapis.com/auth/cloud-platform"]
)

client = bigquery.Client(
    credentials=credentials,
    project=os.environ["PROJECT_ID"],
)
df = client.query(
    """
    SELECT
      CONCAT(
        'https://stackoverflow.com/questions/',
        CAST(id as STRING)) as url,
      view_count
    FROM `bigquery-public-data.stackoverflow.posts_questions`
    WHERE tags like '%google-bigquery%'
    ORDER BY view_count DESC
    LIMIT 10
    """
).to_dataframe()
print(df)

Closes #39

This function is intended to be used in interactive code examples, such
as from a Jupyter notebook or when developing scripts locally. It uses
the same client ID as the `gcloud auth authentication-default login`
command-line tool, so should work for most Google APIs.

Tested manually with the BigQuery API:

```
import os

import google_auth_oauthlib
from google.cloud import bigquery

credentials = google_auth_oauthlib.get_user_credentials(
    ["https://www.googleapis.com/auth/cloud-platform"]
)

client = bigquery.Client(
    credentials=credentials,
    project=os.environ["PROJECT_ID"],
)
df = client.query(
    """
    SELECT
      CONCAT(
        'https://stackoverflow.com/questions/',
        CAST(id as STRING)) as url,
      view_count
    FROM `bigquery-public-data.stackoverflow.posts_questions`
    WHERE tags like '%google-bigquery%'
    ORDER BY view_count DESC
    LIMIT 10
    """
).to_dataframe()
print(df)
```
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 26, 2019
@tswast tswast requested a review from busunkim96 April 26, 2019 23:22
@tswast
Copy link
Contributor Author

tswast commented Apr 26, 2019

Some screenshots of this in action:

Screen Shot 2019-04-26 at 2 49 25 PM

Screen Shot 2019-04-26 at 2 53 43 PM

@busunkim96
Copy link
Contributor

LGTM, but I think it would be best to have a few more people set eyes on it.

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label May 3, 2019
@busunkim96
Copy link
Contributor

I see more interest in this in googleapis/google-auth-library-python#271, have you heard from anyone on this?

@theacodes
Copy link

theacodes commented Jun 4, 2019 via email

@tswast
Copy link
Contributor Author

tswast commented Jun 4, 2019

What if we make client ID and client secret required?

@theacodes
Copy link

theacodes commented Jun 4, 2019 via email

@busunkim96 busunkim96 added cla: yes This human has signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. 🚨 This issue needs some love. labels Jun 4, 2019
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Jun 4, 2019
@tswast
Copy link
Contributor Author

tswast commented Jun 4, 2019

@busunkim96 This PR is ready for another review.

Once this is merged, is autorelease configured for this repo?

@busunkim96
Copy link
Contributor

It'll be a manual release. (looks like this repo still needs to be moved off of Travis, in fact 😦)

Would you mind adding an example of how to use this in the comments like we have for flow.py?

example for flow

@tswast
Copy link
Contributor Author

tswast commented Jun 4, 2019

Would you mind adding an example of how to use this in the comments like we have for flow.py?

Great idea. Done! I've confirmed that it renders well in the docs.

@tswast tswast requested a review from busunkim96 June 10, 2019 20:01
@busunkim96 busunkim96 merged commit dd0a1a2 into googleapis:master Jun 10, 2019
@yoshi-automation yoshi-automation removed the 🚨 This issue needs some love. label Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: get_user_credentials method that runs the installed application flow
5 participants