Forum Discussion

shivanandan17's avatar
shivanandan17
Copper Contributor
Sep 11, 2025

Microsoft Teams Bot OAuth login shows blank screen and closes without signing in

I’m building a Microsoft Teams bot using Azure AD OAuth (SSO) with Bot Framework. When I click Sign in, the OAuth popup in Teams shows a blank screen for a moment, then closes automatically without signing me in.

What I’ve Done

  • Added redirect URI in Azure App Registration:
    https://token.botframework.com/.auth/web/redirect
  • Enabled Access tokens and ID tokens in App Registration → Authentication.
  • Configured OAuth connection in Bot Channels Registration (ConnectionName matches my bot code).
  • Verified client ID, client secret, and tenant ID are correct.

Code

bot.js

require("dotenv").config();
const { TeamsActivityHandler } = require("botbuilder");
const { Client } = require("@microsoft/microsoft-graph-client");
const { DialogSet, DialogTurnStatus, OAuthPrompt, WaterfallDialog } = require("botbuilder-dialogs");
require("isomorphic-fetch");

const OAUTH_PROMPT = "OAuthPrompt";
const MAIN_DIALOG = "MainDialog";

class BotActivityHandler extends TeamsActivityHandler {
    constructor(conversationState, userState) {
        super();

        this.conversationState = conversationState;
        this.userState = userState;

        this.dialogState = this.conversationState.createProperty("DialogState");
        this.dialogs = new DialogSet(this.dialogState);

        // OAuthPrompt for Teams SSO
        this.dialogs.add(
            new OAuthPrompt(OAUTH_PROMPT, {
                connectionName: process.env.CONNECTION_NAME,
                text: "Please sign in to continue",
                title: "Sign In",
                timeout: 300000,
            })
        );

        this.dialogs.add(
            new WaterfallDialog(MAIN_DIALOG, [
                this.promptStep.bind(this),
                this.handleFileStep.bind(this),
            ])
        );

        this.onMessage(async (context, next) => {
            const text = (context.activity.text || "").trim().toLowerCase();
            const dialogCtx = await this.dialogs.createContext(context);

            if (text.startsWith("/")) {
                // ...handle commands...
            } else {
                const results = await dialogCtx.continueDialog();
                if (results.status === DialogTurnStatus.empty) {
                    if (context.activity.attachments?.length > 0) {
                        await dialogCtx.beginDialog(MAIN_DIALOG, {
                            file: context.activity.attachments[0],
                        });
                    } else {
                        await context.sendActivity("Upload a file or type /help.");
                    }
                }
            }
            await next();
        });
    }

    async promptStep(stepContext) {
        return await stepContext.beginDialog(OAUTH_PROMPT);
    }

    async handleFileStep(stepContext) {
        const tokenResponse = stepContext.result;
        if (!tokenResponse?.token) {
            await stepContext.context.sendActivity("Please sign in to access files.");
            return await stepContext.endDialog();
        }
        const token = tokenResponse.token;
        // Use token with Microsoft Graph API
        // ...
        return await stepContext.endDialog();
    }
}

module.exports.BotActivityHandler = BotActivityHandler;

Problem

  • OAuth popup appears, then closes without completing login.
  • No token is returned to the bot.

Questions

  1. Why does the OAuth popup in Teams close immediately without signing in?
  2. Where can I see detailed error logs for OAuth failures?
    • Azure AD sign-in logs?
    • Application Insights (do I need to configure Instrumentation Key in Bot Service)?

Environment

  • Bot Framework v4 (Node.js)
  • Azure Bot Service
  • Microsoft Teams channel
  • Azure AD v2 OAuth

Resources