I want to recieve the user email using Google Actions as documented here but docs talks about EMAIL permission, but when I read the permission docs here I can't find any EMAIL permission. Any help? How can I receive the user email?
Ya, unfortunately the Assistant's SDK doesn't give you the email address. But if you implement account linking (like Ahmed mentioned) and use the Streamlined Flows, then you'll be getting the email provided to you; you just need to use the jsonwebtoken library and you can decode the assertion JWT and grab the email address.
That being said, this happens during "sign in" and token exchange... not during the actual action fulfillment. You'll need to issue a refresh token / access token :S
This is WORKING ,you can do this with account linking.
We have to enable the webhook first and we can see how to enable the webhook in the dialog flow fulfillment docs If we are going to use Google Assistant, then we have to enable the Google Assistant Integration in the integrations first. Then follow the steps mentioned below for the Account Linking in actions on google:-
Go to google cloud console
- goto API's and Services -> Credentials -> OAuth 2.0 client IDs -> Web client
- Note the client ID, client secret from there
- Download JSON - from json note down the project id, auth_uri, token_uri
- goto Authorised Redirect URIs
- White list our app's URL, in this URL fixed part is https://oauth-redirect.googleusercontent.com/r/[project-Id] (replace [project-Id] with your project id)
- Save the changes
Go to Actions on Google(https://console.actions.google.com) -> Account linking setup
- select Grant type = Authorisation code
Client info
- Fill up client id,client secrtet, auth_uri, token_uri
- Enter any random url as Authorization URL and token_uri such as https://example.com/auth and https://example.com/token
- Save
- It will show an error while running on the google assistant, but dont worry
Come back to the account linking section in the assistant settings and this time enter correct auth_uri as https://accounts.google.com/o/oauth2/auth and token_uri as https://accounts.google.com/o/oauth2/token
note that it is some sort of problem in from their side that not allows you to use this url in first hit and will keep saying "Generic URLs are not allowed. You must provide a valid token url specific to your Assistant app." so just give any random url in first hit and save, then comeback again it will allow you these urls :-)
Put the scopes as https://www.googleapis.com/auth/userinfo.profile and https://www.googleapis.com/auth/userinfo.email and weare good to go.
- Save the changes.
In the hosting server logs, we can see the access token value and through access token, we can get the details regarding the email address.
- Append the access token to this link "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" and we can get the required details in the resulting json page.
write this code
accessToken = req.get("originalRequest") .get("data") .get("user") .get("accessToken") r = requests.get(link) // make get request to link print("Email Id: " + r.json()["email"]) print("Name: " + r.json()["name"])
https://accounts.google.com/o/oauth2/auth
without any issue, then just go ahead and use this for the auth and token.The whole point of putting a url of googleapis is that , Google Account Linking does not allow google's owned auth server use, but by using some other auth url first and then coming back to https://accounts.google.com/o/oauth2/auth
somehow bypasses this issue and you can use the account linking easily –
Amoebocyte Ya, unfortunately the Assistant's SDK doesn't give you the email address. But if you implement account linking (like Ahmed mentioned) and use the Streamlined Flows, then you'll be getting the email provided to you; you just need to use the jsonwebtoken library and you can decode the assertion JWT and grab the email address.
That being said, this happens during "sign in" and token exchange... not during the actual action fulfillment. You'll need to issue a refresh token / access token :S
One approach is to go with account linking. I'm wondering what use cases you might have that won't necessarily work without email or account linking?
© 2022 - 2024 — McMap. All rights reserved.