Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Add get_user_credentials function to get your user credentials.#40

Merged
busunkim96 merged 9 commits intogoogleapis:masterfrom
tswast:issue39-get_user_credentials
Jun 10, 2019
Merged

Add get_user_credentials function to get your user credentials.#40
busunkim96 merged 9 commits intogoogleapis:masterfrom
tswast:issue39-get_user_credentials

Conversation

@tswast
Copy link
Copy Markdown
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
Comment thread google_auth_oauthlib/interactive.py Outdated
@tswast
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@theacodes
Copy link
Copy Markdown

theacodes commented Jun 4, 2019 via email

@tswast
Copy link
Copy Markdown
Contributor Author

tswast commented Jun 4, 2019

What if we make client ID and client secret required?

@theacodes
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

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