{"action":"created","issue":{"url":"https://api.github.com/repos/requests/requests-oauthlib/issues/247","repository_url":"https://api.github.com/repos/requests/requests-oauthlib","labels_url":"https://api.github.com/repos/requests/requests-oauthlib/issues/247/labels{/name}","comments_url":"https://api.github.com/repos/requests/requests-oauthlib/issues/247/comments","events_url":"https://api.github.com/repos/requests/requests-oauthlib/issues/247/events","html_url":"https://github.com/requests/requests-oauthlib/issues/247","id":167093840,"number":247,"title":"Support Google Service Account","user":{"login":"natoinet","id":594800,"avatar_url":"https://avatars.githubusercontent.com/u/594800?v=3","gravatar_id":"","url":"https://api.github.com/users/natoinet","html_url":"https://github.com/natoinet","followers_url":"https://api.github.com/users/natoinet/followers","following_url":"https://api.github.com/users/natoinet/following{/other_user}","gists_url":"https://api.github.com/users/natoinet/gists{/gist_id}","starred_url":"https://api.github.com/users/natoinet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natoinet/subscriptions","organizations_url":"https://api.github.com/users/natoinet/orgs","repos_url":"https://api.github.com/users/natoinet/repos","events_url":"https://api.github.com/users/natoinet/events{/privacy}","received_events_url":"https://api.github.com/users/natoinet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-22T17:29:11Z","updated_at":"2016-07-26T14:34:30Z","closed_at":null,"body":"Hello,\r\n\r\nI've had no problem connecting to Google APIs following your tutorial with web app credentials https://requests-oauthlib.readthedocs.io/en/latest/examples/google.html\r\n\r\nHowever, I don't want to have to authorize everytime through the browser so I actually need service credentials https://developers.google.com/api-client-library/python/auth/service-accounts\r\n\r\nI've been following #152, but when I do google.fetch_token(token_url), I always get an InvalidGrant Error:\r\n> oauthlib.oauth2.rfc6749.errors.InvalidGrantError: (invalid_grant) Invalid JWT: Failed audience check. The right audience is https://accounts.google.com/o/oauth2/token\r\n\r\nBut the value of aud is actually 'https://accounts.google.com/o/oauth2/token' \r\n\r\nAny idea?\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/requests/requests-oauthlib/issues/comments/235286907","html_url":"https://github.com/requests/requests-oauthlib/issues/247#issuecomment-235286907","issue_url":"https://api.github.com/repos/requests/requests-oauthlib/issues/247","id":235286907,"user":{"login":"natoinet","id":594800,"avatar_url":"https://avatars.githubusercontent.com/u/594800?v=3","gravatar_id":"","url":"https://api.github.com/users/natoinet","html_url":"https://github.com/natoinet","followers_url":"https://api.github.com/users/natoinet/followers","following_url":"https://api.github.com/users/natoinet/following{/other_user}","gists_url":"https://api.github.com/users/natoinet/gists{/gist_id}","starred_url":"https://api.github.com/users/natoinet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natoinet/subscriptions","organizations_url":"https://api.github.com/users/natoinet/orgs","repos_url":"https://api.github.com/users/natoinet/repos","events_url":"https://api.github.com/users/natoinet/events{/privacy}","received_events_url":"https://api.github.com/users/natoinet/received_events","type":"User","site_admin":false},"created_at":"2016-07-26T14:34:30Z","updated_at":"2016-07-26T14:34:30Z","body":"Here is exactly what I do:\r\n\r\n```\r\n>>> import json\r\n>>> json_file = json.load(open(\"google_service_privatekey.json\"))\r\n>>> client_id = json_file['client_id']\r\n>>> issuer = json_file['client_email']\r\n>>> aud = 'https://www.googleapis.com/oauth2/v4/token'\r\n>>> scope = 'https://www.googleapis.com/auth/tasks'\r\n>>> private_key_id = json_file['private_key_id']\r\n>>> private_key_pkcs8_pem = json_file['private_key']\r\n>>> client = ServiceApplicationClient(client_id, issuer=issuer, audience=aud, private_key=private_key_pkcs8_pem)\r\n>>> google = OAuth2Session(client_id, client=client)\r\n>>> google.fetch_token(token_url)\r\n>>> client.prepare_request_body()\r\n\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"/Users/antoinet/.virtualenvs/scraper/lib/python3.4/site-packages/requests_oauthlib/oauth2_session.py\", line 244, in fetch_token\r\n    self._client.parse_request_body_response(r.text, scope=self.scope)\r\n  File \"/Users/antoinet/.virtualenvs/scraper/lib/python3.4/site-packages/oauthlib/oauth2/rfc6749/clients/base.py\", line 409, in parse_request_body_response\r\n    self.token = parse_token_response(body, scope=scope)\r\n  File \"/Users/antoinet/.virtualenvs/scraper/lib/python3.4/site-packages/oauthlib/oauth2/rfc6749/parameters.py\", line 376, in parse_token_response\r\n    validate_token_parameters(params)\r\n  File \"/Users/antoinet/.virtualenvs/scraper/lib/python3.4/site-packages/oauthlib/oauth2/rfc6749/parameters.py\", line 383, in validate_token_parameters\r\n    raise_from_error(params.get('error'), params)\r\n  File \"/Users/antoinet/.virtualenvs/scraper/lib/python3.4/site-packages/oauthlib/oauth2/rfc6749/errors.py\", line 271, in raise_from_error\r\n    raise cls(**kwargs)\r\noauthlib.oauth2.rfc6749.errors.InvalidGrantError: (invalid_grant) Invalid JWT: Failed audience check. The right audience is https://www.googleapis.com/oauth2/v4/token\r\n\r\n```\r\n"}}
{"actor":{"display_login":"natoinet"}}