Skip to content

Commit 25fba64

Browse files
authored
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".`.
1 parent 260cea7 commit 25fba64

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

docs/oauth.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ from google_auth_oauthlib.flow import Flow
5858
...
5959
flow = Flow.from_client_secrets_file(
6060
'path/to/client_secrets.json',
61-
scopes=['profile', 'email'],
61+
scopes=['openid', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'],
6262
redirect_uri='urn:ietf:wg:oauth:2.0:oob')
6363
```
6464

@@ -125,12 +125,18 @@ from googleapiclient.discovery import build
125125

126126
flow = InstalledAppFlow.from_client_secrets_file(
127127
'client_secrets.json',
128-
scopes=['profile', 'email'])
128+
scopes=['openid', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'])
129129

130130
flow.run_local_server()
131131
credentials = flow.credentials
132132

133133
service = build('calendar', 'v3', credentials=credentials)
134+
135+
# Optionally, view the email address of the authenticated user.
136+
user_info_service = build('oauth2', 'v2', credentials=credentials)
137+
user_info = user_info_service.userinfo().get().execute()
138+
print(user_info['email'])
139+
134140
```
135141

136142
## Storage

0 commit comments

Comments
 (0)