Skip to content
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

Getting gcloud auth login to work for python #232

Closed
msj121 opened this issue Jan 4, 2018 · 3 comments
Closed

Getting gcloud auth login to work for python #232

msj121 opened this issue Jan 4, 2018 · 3 comments
Assignees
Labels
🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@msj121
Copy link

msj121 commented Jan 4, 2018

I described the issue on https://stackoverflow.com/questions/48088841/gcloud-auth-login-saves-to-legacy-credentials-folder

I am running the following code from python library:

def get_gcloud_oauth2_creds():
  gcfp = '~/.config/gcloud/credentials'
  credfn = os.path.expanduser(gcfp)
  if not os.path.exists(credfn):
    msg = "[edx2bigquery] Authentication error!  You have specified USE_GCLOUD_AUTH in the configuration, but do not have gcloud authentication available.\n"
    msg += "               Please authenticate using 'gcloud auth login' before running this."
    print msg
    raise Exception(msg)
  gcloud_cred = json.loads(open(credfn).read())['data'][0]['credential']
  credentials = Credentials.new_from_json(json.dumps(gcloud_cred))
  return credentials

I always hit the error since my gcloud auth login is creating its files in ~/.config/gcloud/legacy_credentials, which does not seem to work for me. Any ideas how to use the legacy_credentials or preferably get gcloud auth login to work?

@theacodes
Copy link
Contributor

Hi @msj121, this library is for allowing applications to authenticate to Google and Google Cloud services. It is unrelated to the Cloud SDK's auth (except through a legacy mechanism).

I suggest that you use service accounts for your application, see https://cloud.google.com/docs/authentication/getting-started

@msj121
Copy link
Author

msj121 commented Jan 5, 2018

@jonparrott Thanks that link finally got me to the exact link I was looking for. I have been searching/working on this for a week with different python approaches and different key files, but that document contained the link to the right json file. So I tried a different approach to connecting with it instead and now it works.

@theacodes
Copy link
Contributor

Good deal!

@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Apr 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

3 participants