docs: Update oauth docs to include snippet to get email address of authenticated user (#1088)
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".`.
diff --git a/docs/oauth.md b/docs/oauth.md
index 8df25a5..c2d41f5 100644
--- a/docs/oauth.md
+++ b/docs/oauth.md
@@ -58,7 +58,7 @@
...
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 @@
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