microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.5k stars 2.44k forks source link

ERROR: ChatConnector: receive - no security token sent. #1505

Closed dhirajsharma072 closed 7 years ago

dhirajsharma072 commented 8 years ago

I am using Node.js and my bot framework version is 3.3.3. I have already configured "Skype" channel and its working fine. However in case of "Facebook Messenger" I am getting error "No security token sent". I am using ngrok . Here is my configuration of chatBot

var server = restify.createServer();
server.use(restify.CORS());
server.use(restify.queryParser());
server.listen(process.env.port || process.env.PORT || 4000, function () {
    console.log('%s listening to %s', server.name, server.url);
});
// Create chat bot
var connector = new builder.ChatConnector({
    appId: _config.ms.appId,
    appPassword: _config.ms.password
});

var bot = new builder.UniversalBot(connector);

server.post('/', connector.listen());

server.get('/', function (req, res) {
if (req.query.hub.verify_token === _config.ms.messengerSecret) {
        res.write(req.query.hub.challenge);
        res.end();
    } else {
        res.send('Error, wrong validation token');
    }
});

I have attached screenshots of configuration of webhooks(facebook app) and messaging end point(botframwork botframework_message_endpoint vchat

Please let me know the solution of it. Thanks!

willportnoy commented 8 years ago

It looks like your settings are leading the code to this "else" branch: https://github.com/Microsoft/BotBuilder/blob/9a1d8e78b9fe1d81bd9b481d2743006a6032f7b9/Node/core/src/bots/ChatConnector.ts#L182

Does it work without ngrok?

dhirajsharma072 commented 8 years ago

@willportnoy Thanks for your response. When I test using bot framework it says accepted but when I try to send message with messenger I get this "ERROR: ChatConnector: receive - no security token sent.". I am using mac os and node.js so I am not able to use emulator.

dhirajsharma072 commented 8 years ago

@willportnoy I have seen Facebook messenger document,there is sample app, using this app I am able to send and receive message to my page. So do I need to implement it by own? Please let me know. Thanks!

dhirajsharma072 commented 8 years ago

In ChatConnector.js following code is used for fetching token.

    var token;
    var isEmulator = req.body['channelId'] === 'emulator';
    if (req.headers && req.headers.hasOwnProperty('authorization')) {
        var auth = req.headers['authorization'].trim().split(' ');
             if (auth.length == 2 && auth[0].toLowerCase() == 'bearer') {
                  token = auth[1];
              }
     }

But I am getting req.headers look like this

     { host: 'c5dcbaa5.ngrok.io',
        accept: '*/*',
        'accept-encoding': 'deflate, gzip',
        'content-type': 'application/json',
        'x-hub-signature': 'sha1=****************86e8c84c',
        'content-length': '265',
        'x-forwarded-proto': 'https',
        'x-forwarded-for': '***. ***. ***. 136' }

It does not contain "authorization" attribute in req.headers.

dhirajsharma072 commented 8 years ago

In case of Skype channel I'm getting req.headers look like this:

{ authorization: 'Bearer *.......LysN17so7Q', 'user-agent': 'BF-Skype (Microsoft-BotFramework/3.1 +https://botframework.com/ua)', contextid: 'tcid=*****7312, server=****_0961', 'x-correlating-operationid': 'M2z4l1yniiM=.dAA=.****.aDANpOAw0gE=._**=.****_iL2PIYY6LSK7cD*****kzISie0=', 'content-type': 'application/json; charset=utf-8', host: 'f830c68f.ngrok.io', 'content-length': '729', 'x-forwarded-proto': 'https', 'x-forwarded-for': '__. _. \ .180' }

It works fine. It also has authorization attribute in req.headers.

tomlm commented 7 years ago

Is this issue still happening?

dhirajsharma072 commented 7 years ago

Thanks for your response Tom! Yes,I am getting same error.

On Fri, Nov 4, 2016 at 6:24 AM, Tom Laird-McConnell < notifications@github.com> wrote:

Is this issue still happening?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Microsoft/BotBuilder/issues/1505#issuecomment-258292448, or mute the thread https://github.com/notifications/unsubscribe-auth/AGnkEQtS4WX5HXofNsvnyddhXyyJ9NJPks5q6l80gaJpZM4KfsN9 .

shanepeckham commented 7 years ago

I am also getting this error

chrimc62 commented 7 years ago

@tomlm do you need more information to track this down?

dandriscoll commented 7 years ago

Hi @dhirajsharma072 and @shanepeckham, can you send a conversation ID and channel ID where you are seeing this problem and we can investigate?

piyush-avantsoft commented 7 years ago

I am also getting same error when I post anything from postman to my bot application.

dandriscoll commented 7 years ago

Hi @piyush-dholariya, can you send a conversation ID and channel ID where you're seeing this problem?

dandriscoll commented 7 years ago

Closing due to age. Please feel free to at-mention or file a new issue and we will take a closer look.

piyush-avantsoft commented 7 years ago

@dandriscoll #1856 & #1903 can you give answer of these questions? I have post them separately.

dandriscoll commented 7 years ago

Hi @piyush-dholariya, I've taken a look but I don't know the answer to either. The people assigned to each issue are the right ones to weigh in -- I'll send them a followup email to remind them.

picatextra commented 7 years ago

It happened for me when setup webhook after credentials

stujo commented 7 years ago

I was able to fix this error by providing the APP_ID and PASSWORD in the emulator.

This may be obvious but the docs say this isn't typically required for local connections:

https://github.com/Microsoft/BotFramework-Emulator/wiki/Getting-Started#connect-to-a-bot-running-on-localhost

I will submit a pull request to fix the docs

Edit: Sorry can't fix as this is a wiki page:

ERROR: ChatConnector: receive - no security token sent.

juharris commented 7 years ago

I'm trying to set up a bot with a Microsoft Teams channel and I get ERROR: ChatConnector: receive - no security token sent. when a message is sent in a channel mentioning the bot but replies to individual messages do work are fine and the bot replies as expected.

Here's my app.js:

require('dotenv-extended').load();

var builder = require('botbuilder');
var restify = require('restify');

var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
    console.log('%s listening to %s', server.name, server.url);
});

var connector = new builder.ChatConnector({
    appId: process.env.MICROSOFT_APP_ID,
    appPassword: process.env.MICROSOFT_APP_PASSWORD
});

server.post('/api/messages', connector.listen());

var bot = new builder.UniversalBot(connector, function (session) {
    session.send("Hi");
});

The bot does reply to the Teams channel but the message is always "Sorry, there was a problem encountered with your request"

The logs show HTML for a 401 error page. It says:

Most likely causes:
   The authenticated user does not have access to a resource needed to process the request.
...
Detailed Error Information:
    ...
    Requested URL      https://MaDinnerBot:80/app.js
    Physical Path      D:\home\site\wwwroot\app.js
...

Is there somewhere where I should be setting a token? I did get a token when adding the bot to Teams but I'm not sure where to put it. Thanks.

willportnoy commented 7 years ago

@juharris please open a top level issue for your question, and feel free to reference this closed issue.

bhanu2507 commented 7 years ago

I am facing exactly the same problem...outside of skype channel..I am not able to get the token. Did you find a solution for the problem?

juharris commented 7 years ago

@bhanu2507 are you asking me? You can see my referenced issue above. I just set up a Linux server and ngrok manually and it worked. Though my colleague made a bot last week and it worked fine doing things the automatic way with an Azure App.

alundiak commented 6 years ago

node v8.8.1, npm v5.4.2.

I can confirm, that using emulator I also have ERROR: ChatConnector: receive - no security token sent. - I typed messages but they didn't go through. And time ago all was good.

And I also solved it using APP_ID and APP_PASSWORD in emulator, as @stujo mentioned above. Which is odd, because it's not required locally.

My new dependencies:

"botbuilder": "^3.12.0",
"restify": "^6.3.4"

Interesting, that a few month ago I did not have this issue. My dependencies were:

"botbuilder": "^3.11.0",
"restify": "^6.2.3"

and btw, after updating to latest version, my 2 bots codebases now have another warning in logs:

The Bot State API is deprecated. Please refer to https://aka.ms/I6swrh for details on how to replace with your own storage.

cext001 commented 6 years ago

I am also getting the same issue. This is really frustrating

chakrihacker commented 6 years ago

Any updates??

rkbala commented 5 years ago

Guys, just make the appID and appPassword as null if you don't want to use the same as part of testing from emulator. (Emulator local testing does not need appid and apppassword)

//use this for testing in local and if you don't have appid and app password

var appId = null; var appPassword = null;

This will resolve this error. Thanks.