question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

oauthclient.OAuth2Credentials does not implement create_scoped or create_scoped_required

See original GitHub issue

Right now, the gcloud-python API only authorize through service account. Can we add the user authorization using client_secret.json file?

https://developers.google.com/identity/protocols/OAuth2WebServer

from oauth2client import client
from oauth2client.file import Storage
from oauth2client import tools

FLOW = flow_from_clientsecrets('client_secret.json',
                               scope='https://www.googleapis.com/auth/bigquery')
storage = Storage('bigquery_credentials.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
    credentials = run(FLOW, storage)
http = httplib2.Http()
http = credentials.authorize(http)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
tuanavucommented, Jan 21, 2016

Hi @dhermes,

This one works perfectly:

from oauth2client.client import GoogleCredentials
from gcloud import bigquery

credentials = GoogleCredentials.get_application_default()
print credentials.to_json()

client = bigquery.Client(project='my-project-id',
                         credentials=credentials
                         )

However, I try this for the user authentication with client_secret.json, and bigquery_credentials.dat, but this one give me error:

import httplib2
from apiclient.discovery import build
from apiclient.errors import HttpError

from oauth2client import client
from oauth2client.file import Storage
from oauth2client import tools

from gcloud import bigquery

BIGQUERY_SCOPE = 'https://www.googleapis.com/auth/bigquery'

FLOW = client.flow_from_clientsecrets('client_secret.json', scope=BIGQUERY_SCOPE)
storage = Storage('bigquery_credentials.dat')
flags = tools.argparser.parse_args(args=[])
credentials = storage.get()
if credentials is None or credentials.invalid:
    credentials = tools.run_flow(FLOW, storage, flags)
http = httplib2.Http()
http = credentials.authorize(http)
# print credentials.to_json()
# print http.to_json()
client = bigquery.Client(project='my-project-id',
                         credentials=credentials
                         )

Error message:

Traceback (most recent call last):
  File "gcloud_test.py", line 36, in <module>
    credentials=credentials
  File "/usr/local/lib/python2.7/dist-packages/gcloud/client.py", line 182, in __init__
    Client.__init__(self, credentials=credentials, http=http)
  File "/usr/local/lib/python2.7/dist-packages/gcloud/client.py", line 127, in __init__
    credentials=credentials, http=http)
  File "/usr/local/lib/python2.7/dist-packages/gcloud/connection.py", line 78, in __init__
    credentials, self.SCOPE)
  File "/usr/local/lib/python2.7/dist-packages/gcloud/connection.py", line 118, in _create_scoped_credentials
    if credentials and credentials.create_scoped_required():
AttributeError: 'OAuth2Credentials' object has no attribute 'create_scoped_required'

How can I tune this to make the gcloud/connection.py works?

BTW, I cannot re-open this issue.

Thanks, Tuan

0reactions
dhermescommented, Jan 28, 2016

“Know” might be strong but AFAIK the only other things we use a credential for are getting access tokens for signing requests and providing a way to generate a signed URL (and neither GoogleCredentials nor OAuth2Credentials can do this since they don’t have a key to sign with).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Class ComputeEngineCredentials (1.7.0) | Java client library
OAuth2 credentials representing the built-in service account for a Google Compute Engine VM. Fetches access tokens from the Google Compute ...
Read more >
GoogleCredential.createScopedRequired - Java - Tabnine
Indicates whether the credential requires scopes to be specified by calling createScoped before use. Popular methods of GoogleCredential. createScoped. Beta For ...
Read more >
google-auth-library - npm
The basics of Google's OAuth2 implementation is explained on Google Authorization and Authentication documentation.
Read more >
Using OAuth 2.0 with the Google API Client Library for Java
Alternatively, if you are not using GoogleAuthorizationCodeFlow, you may use the lower-level classes: Use DataStore.get(String) to load the ...
Read more >
GoogleCredentials (Google Auth Library for Java - javadoc.io
boolean, createScopedRequired(). Indicates whether the credentials require scopes to be specified via a call to createScoped(java.util.Collection<java.lang.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found