How to revoke access token in Action on Google SDK
See original GitHub issueHi, I want to revoke a token in a specific action returning a 401 error to the request (https://developers.google.com/actions/identity/oauth2-implicit-flow#revoke_tokens). I have not found how to do it with the “action-on-google” SDK and I have tried to do it by adding a middleware in my app, checking if the action of the request is the expected action and finally sending a response with status 401 and the payload JSON. My code:
const app = express();
const assistant = dialogflow(); // Integration with dialogflow
...
app.use((req, res, next) => {
console.log('Middleware!');
if(req.body.queryResult.action === EXPECTED_ACTION) {
const response = {
"payload": {
"google": {
"expectUserResponse": false,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Good bye and have a nice day!"
}
}
]
},
"userStorage": "{\"data\":{}}"
}
}
};
res.status(401).send(response);
return;
}
next();
});
app.use(bodyParser.json(), assistant);
Doing the res.status(401).send(response);
the Google Assistant revokes the token but the app crashes and it does not show the SimpleResponse. If I change the status to 200 (success) the Google Assistant shows the SimpleResponse but it does not revokes the token.
Is there any method in “actions-on-google-nodejs” SDK to revoke the token or send a 401 error with a message?
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:8 (2 by maintainers)
Top GitHub Comments
The UnauthorizedError exception does not seem to clear the access token anymore. However, It worked before.
I have the same problem, the application crashes when I return code 401. Would anyone have a solution to post a message before leaving?