botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

ERROR ChatConnector: receive - invalid token. Check bots app ID & Password

Open raphael2711 opened this issue 10 years ago • 9 comments

After migration my bot from V1 to V3 i get the Error "invalid token. Check bots app ID & Password"

I already create new Application ID and Password and register a new bot on the Bot Framwork webpage. It works with the bot framework channel emulator V3.x

I used then new connection settings for V3

var connector = new builder.ChatConnector({
    appId: "appid",
    appPassword:  "password"
});
var bot = new builder.UniversalBot(connector);

I re-generated the password but I get the same error.

raphael2711 avatar Jul 15 '16 19:07 raphael2711

Did you notice that there are now 3 settings in web.config?


    <add key="BotId" value="xxxx" />
    <add key="MicrosoftAppID" value="yyyyy" />
    <add key="MicrosoftAppPassword" value="zzzzzzz" />

lokijota avatar Jul 16 '16 01:07 lokijota

i don't have a web.config i used the node.js api and start my bot locally.

raphael2711 avatar Jul 16 '16 03:07 raphael2711

I found the problem by myself , there was a timing problem into the jwt and chatconnector lib.

In ChatConnector .js i add a ( +100) . I hope that anybody fix this problem correctly in the future.

if (token) { req.body['useAuth'] = true; this.ensureCachedKeys(function (err, keys) { if (!err) { var decoded = jwt.decode(token, { complete: true });

                var now = (new Date().getTime() / 1000)+ 100;

raphael2711 avatar Jul 17 '16 16:07 raphael2711

Thanks for noting this. We have some fixes in the works that will address this.

dandriscoll avatar Jul 17 '16 19:07 dandriscoll

#742

brentzucker avatar Jul 18 '16 18:07 brentzucker

@dandriscoll @Stevenic Please note that is issue is also happening on the CallConnector

ejadib avatar Mar 03 '17 20:03 ejadib

Hi @ejadib, we've found the bug and will be fixing it soon. Thanks for raising this.

dandriscoll avatar Mar 08 '17 18:03 dandriscoll

Has this been resolved? Just today I noticed my bot was no longer working via Twilio (web chat is fine).

DavidJBarnes avatar May 09 '17 04:05 DavidJBarnes

@dandriscoll I have this problem in the last version of the BotConnector framework:

// Restify embedded server
    var restify = require('restify');
    // Microsoft Bot Framework
    var BotBuilder = require('botbuilder');

    var Config = require('../../config/luis');
    // Dialog Intent and Entity objects
    var Intent = require('../../dialog/intent');
    var IntentFactory = require('../../dialog/intentfactory');
    var Entity = require('../../dialog/entity');

    var inMemoryStorage = new BotBuilder.MemoryBotStorage();
    var connector = new BotBuilder.ChatConnector({
        appId: Config[ Config['env'] ].MS_appId, 
        appPassword: Config[ Config['env'] ].MS_appPass 
    });
    var bot = new BotBuilder.UniversalBot(connector, function (session, args) {
        session.send("started up the boiler plate...");
        if (!session.userData.notes) {
            session.userData.notes = {};
            console.log("initializing userData.notes in default message handler");
        }
    }).set('storage', inMemoryStorage); // Register in memory storage

    // Add global LUIS recognizer to bot
    bot.recognizer(new BotBuilder.LuisRecognizer(Config[Config['env']].model));

    // Joke Intent
    bot.dialog(Intent.Type.JokeIntent, [
        function (session, args, next) {
            var randomMessage = Util.randomElement( Config.locale['en']['JOKES'] );
            session.send(randomMessage);
        }
    ]).triggerAction({
        matches: Intent.Type.JokeIntent
    }).cancelAction('CancelIntent', "Ok.", {
        matches: /^(cancel|nevermind)/i
    });
     var port = process.env.port || 3978;
	var server = restify.createServer();
    server.post('/bot/api/messages', connector.listen());
    server.listen(port, function () {
	    console.log('%s listening to %s', server.name, server.url);
    });

and when I connect to the Bot Emulator I get the ERROR: ChatConnector: receive - invalid token. Requested by unexpected app ID..

I'm pretty sure that my MS appID and appPassword are ok. I have migrated to the latest Bot Frameworks, since I have create a new Bot from scratch few days ago, and tried this simple example.

loretoparisi avatar Dec 12 '17 11:12 loretoparisi