Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/_static/js/authcodescripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function onloadoauthcode() {
const PARAMS = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
});
const AUTH_CODE = PARAMS.code;

document.querySelector('.auth-code').textContent = AUTH_CODE;

setupCopyButton(document.querySelector('.copy'), AUTH_CODE);
}

function setupCopyButton(button, text) {
button.addEventListener('click', () => {
navigator.clipboard.writeText(text);
button.textContent = "Verification Code Copied";
setTimeout(() => {
// Remove the aria-live label so that when the
// button text changes back to "Copy", it is
// not read out.
button.removeAttribute("aria-live");
button.textContent = "Copy";
}, 1000);

// Re-Add the aria-live attribute to enable speech for
// when button text changes next time.
setTimeout(() => {
button.setAttribute("aria-live", "assertive");
}, 2000);
});
}
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
# html_show_sphinx = True

html_js_files = [
"js/authcodescripts.js",
]

# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
# html_show_copyright = True

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Contents:
contributing.rst
changelog.md
privacy.rst
oauth.rst


Indices and tables
Expand Down
39 changes: 39 additions & 0 deletions docs/oauth.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.. image:: https://lh3.googleusercontent.com/KaU6SyiIpDKe4tyGPgt7yzGVTsfMqBvP9bL24o_4M58puYDO-nY8-BazrNk3RyhRFJA
:alt: gcloud CLI logo
:class: logo

Sign in to BigQuery
===================

You are seeing this page because you are attempting to access BigQuery via one
of several possible methods, including:

* the ``pandas_gbq`` library (https://github.com/googleapis/python-bigquery-pandas)

OR a ``pandas`` library helper function such as:

* ``pandas.DataFrame.to_gbq()``
* ``pandas.read_gbq()``

from this or another machine. If this is not the case, close this tab.

Enter the following verification code in the CommandLine Interface (CLI) on the
machine you want to log into. This is a credential **similar to your password**
and should not be shared with others.


.. raw:: html

<script type="text/javascript">
window.addEventListener( "load", onloadoauthcode )
</script>

<div>
<code class="auth-code"></code>
</div>
<br>
<button class="copy" aria-live="assertive">Copy</button>

.. hint::

You can close this tab when you’re done.
13 changes: 10 additions & 3 deletions pandas_gbq/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@


def get_credentials(
private_key=None, project_id=None, reauth=False, auth_local_webserver=True
private_key=None,
project_id=None,
reauth=False,
auth_local_webserver=True,
auth_redirect_uri=None,
client_id=None,
client_secret=None,
):
import pydata_google_auth

Expand All @@ -43,10 +49,11 @@ def get_credentials(

credentials, default_project_id = pydata_google_auth.default(
SCOPES,
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
client_id=client_id,
client_secret=client_secret,
credentials_cache=get_credentials_cache(reauth),
auth_local_webserver=auth_local_webserver,
redirect_uri=auth_redirect_uri,
)

project_id = project_id or default_project_id
Expand Down
18 changes: 18 additions & 0 deletions pandas_gbq/gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ def __init__(
location=None,
credentials=None,
use_bqstorage_api=False,
auth_redirect_uri=None,
client_id=None,
client_secret=None,
):
global context
from google.api_core.exceptions import GoogleAPIError
Expand All @@ -294,6 +297,10 @@ def __init__(
self.auth_local_webserver = auth_local_webserver
self.dialect = dialect
self.credentials = credentials
self.auth_redirect_uri = auth_redirect_uri
self.client_id = client_id
self.client_secret = client_secret

default_project = None

# Service account credentials have a project associated with them.
Expand All @@ -313,6 +320,9 @@ def __init__(
project_id=project_id,
reauth=reauth,
auth_local_webserver=auth_local_webserver,
auth_redirect_uri=auth_redirect_uri,
client_id=client_id,
client_secret=client_secret,
)

if self.project_id is None:
Expand Down Expand Up @@ -735,6 +745,9 @@ def read_gbq(
private_key=None,
progress_bar_type="tqdm",
dtypes=None,
auth_redirect_uri=None,
client_id=None,
client_secret=None,
):
r"""Load data from Google BigQuery using google-cloud-python

Expand Down Expand Up @@ -864,6 +877,8 @@ def read_gbq(
or
:func:`google.oauth2.service_account.Credentials.from_service_account_file`
instead.
# TODO: add parameters for auth_redirect_uri, client_id, client_secret


Returns
-------
Expand Down Expand Up @@ -912,6 +927,9 @@ def read_gbq(
credentials=credentials,
private_key=private_key,
use_bqstorage_api=use_bqstorage_api,
auth_redirect_uri=auth_redirect_uri,
client_id=client_id,
client_secret=client_secret,
)

if _is_query(query_or_table):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"numpy >=1.16.6",
"pandas >=1.1.4",
"pyarrow >=3.0.0",
"pydata-google-auth >=1.4.0",
"pydata-google-auth >=1.5.0",
# Note: google-api-core and google-auth are also included via transitive
# dependency on google-cloud-bigquery, but this library also uses them
# directly.
Expand Down
2 changes: 1 addition & 1 deletion testing/constraints-3.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ google-cloud-bigquery-storage==2.16.2
numpy==1.16.6
pandas==1.1.4
pyarrow==3.0.0
pydata-google-auth==1.4.0
pydata-google-auth==1.5.0
tqdm==4.23.0
protobuf==3.19.5