From 25fba648ea647b62f2a6edc54ae927c1ed381b45 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Fri, 13 Nov 2020 09:38:06 -0500 Subject: [PATCH] docs: Update oauth docs to include snippet to get email address of authenticated user (#1088) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1071 🦕 Note: I changed `scopes=['profile', 'email'],` to `scopes=['openid', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'],` in the examples because I received a warning that the scope has changed. > `Warning: Scope has changed from "email profile" to "https://www.googleapis.com/auth/userinfo.email openid https://www.googleapis.com/auth/userinfo.profile".`. --- docs/oauth.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/oauth.md b/docs/oauth.md index 8df25a53b61..c2d41f5c778 100644 --- a/docs/oauth.md +++ b/docs/oauth.md @@ -58,7 +58,7 @@ from google_auth_oauthlib.flow import Flow ... flow = Flow.from_client_secrets_file( 'path/to/client_secrets.json', - scopes=['profile', 'email'], + scopes=['openid', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'], redirect_uri='urn:ietf:wg:oauth:2.0:oob') ``` @@ -125,12 +125,18 @@ from googleapiclient.discovery import build flow = InstalledAppFlow.from_client_secrets_file( 'client_secrets.json', - scopes=['profile', 'email']) + scopes=['openid', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile']) flow.run_local_server() credentials = flow.credentials service = build('calendar', 'v3', credentials=credentials) + +# Optionally, view the email address of the authenticated user. +user_info_service = build('oauth2', 'v2', credentials=credentials) +user_info = user_info_service.userinfo().get().execute() +print(user_info['email']) + ``` ## Storage