Search code examples
azureazure-active-directorybotframework

Azure Bot Returning "Failed to load resource: the server responded with a status of 502 (Bad Gateway)" error


We have created bot solution and published it in Azure. It was working fine locally. In Azure we are protecting the web app bot with another App service resource. Due to this we are getting "Failed to load resource:the server responded with a status of 502 (Bad Gateway)" error.

In the app service, under Authentication/Authorization tab, for "Action to take when request is not authenticated" dropdown if i select "Allow Anonymous request" option bot is working fine. If i select "Login with Azure Active directory" bot is not working.

Bot is not working even in Test in WebChat in azure site itself.

We are able to access bot default page after providing credentials.

Please let me know what is the step i am missing and let me know if you need any other information.

Code to connect bot.

    BotChat.App({
        botConnection: botConnection,
        user: { id: model.userId, Username: model.LoginUser},
        bot: { id: model.botId, name: model.botName },
        resize: 'window',
        speechOptions: speechOptions,
        locale: 'en',
        sendTypingIndicator: true
    }, document.getElementById('BotChatElement'));

    botConnection
        .postActivity({
            from: user,
            name: 'requestWelcomeDialog',
            type: 'event',
            value: ''
        })
        .subscribe(function (id) {
            console.log('"trigger requestWelcomeDialog" sent');
        });

Solution

  • The built-in authentication in Azure app service is not suitable here.

    You should follow this document to add authentication to your bot.

    Note: The redirect url should be https://token.botframework.com/.auth/web/redirect

    Here is an sample which uses bot authentication capabilities in Azure Bot service.