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

Add support for Service Accounts #2

Open
joshcarty opened this issue Jan 10, 2018 · 3 comments
Open

Add support for Service Accounts #2

joshcarty opened this issue Jan 10, 2018 · 3 comments
Assignees

Comments

@joshcarty
Copy link
Owner

Google allow users to authenticate using Service Accounts. We should allow users to authenticate with Google Search Console using Service Account credentials.

@ghost
Copy link

ghost commented Apr 9, 2018

If this helps, there is a pretty simple flow to authenticate with service accounts:

from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
import os

# environment
path = '/Users/******/Documents/cronjobs/service.json'
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = path

# authenticaton
scope = ['https://www.googleapis.com/auth/webmasters']
creds = ServiceAccountCredentials.from_json_keyfile_name('service.json', scope)
searchconsole = build('webmasters', 'v3')

# select the site(s) of interest
sites = searchconsole.sites().list().execute()

For this to work, one must give permission to the service account email. Some of the steps can be seen in this video from Twilio. What's missing is the link between this authentication and the functionalities of your package. In your authentication example, the account is a <searchconsole.account.Account(client_id='*******')>, while creds from my example is a <oauth2client.service_account.ServiceAccountCredentials at 0x1141a9160>

@joshcarty
Copy link
Owner Author

Hey, thanks for this!

I've had a go at implementing support for service accounts using google.oauth2.service_account. I don't have access to an authorised service account at the moment but feel free to download the service-account branch and try it out:
pip install git+https://github.com/joshcarty/google-searchconsole@service-accounts

Let me know if you have any luck!

@joshcarty joshcarty self-assigned this Apr 10, 2018
@symbiotech
Copy link

@joshcarty I can confirm that your code changes are working properly with a real service account in production. By merging this branch to master and fixing the 2 minor conflicts other people can use it as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants