Skip to content

Instantly share code, notes, and snippets.

@pawelgagorowski
Last active October 9, 2019 06:36
Show Gist options
  • Save pawelgagorowski/626090da6bf2d8a7ed646435df04d929 to your computer and use it in GitHub Desktop.
Save pawelgagorowski/626090da6bf2d8a7ed646435df04d929 to your computer and use it in GitHub Desktop.
error 401 - no authorization
'use strict';
const AWS = require('aws-sdk');
AWS.config.update({ region: 'us-east-1' })
const { dialogflow, SignIn } = require('actions-on-google');
const app = dialogflow();
const request = require('request-promise')
const rp = require('request-promise');
// Start SignIn Intention is assigned to the 'sign in' Training phrase
app.intent('Start SignIn', (conv) => {
conv.ask(new SignIn('To get your account details'));
});
// Get SignIn Intention is assigned to the 'Google Assistant Sign In' action
app.intent('Get SignIn', (conv, params, signin) => {
// tutaj występuje Error 401 - brak autoryzacji
if (signin.status === 'OK') {
const accessToken = conv.body.originalDetectIntentRequest.payload.user.accessToken;
const options = {
method: 'GET',
uri: 'https://dev-6cnet9rr.eu.auth0.com/userinfo',
headers: {
authorization: 'Bearer ' + accessToken
}
}
return rp(options).then(function (body) {
let data = JSON.parse(body);
conv.ask(`I got your account details, ${data.name}. What do you want to do next?`);
}).catch(function(err) {
conv.ask(`Sorry, but I could not sign you in.`);
})
} else {
conv.ask(`Sorry, but there was an error, and I could not sign you in.`);
}
});
app.intent('Default Welcome Intent', conv => {
conv.ask("Hello from Welcome Intent, udalo sie");
});
@himangipatel
Copy link

did you get any solution? I am facing the same issue

@pawelgagorowski
Copy link
Author

hi there, first of all, the code is ok - it was somewhere in the action's configuration - don't know where exactly.
Maybe simply an action can not tolerate changing the configuration while the application is running - what I can advise you is to create a new action and carefully enter the data. Let me know if that helped..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment