microsoft / botframework-sdk

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

404 not found when testing the AADv2 Auth Sample #5464

Closed muhualing closed 5 years ago

muhualing commented 5 years ago

when I tested the auth bot sample, I met 404not found error

SDK Platform: Nodejs SDK Version: 3.16.0 Active Channels: Teams Deployment Environment: Azure Bot Service

Error: GET to 'https://api.botframework.com/api/usertoken/GetToken?userId=29%3A1R5vQA_0_OF8C4zi2Sy5uQs77pFKXs6Jxx1-UW7fABq7XqkNQ_CrL-lstObXd3RL6MVj_UZIC1PQ3fZGh-YdNFA&connectionName=ConnectionNameV2' failed: [404] Not Found

mycode:

connector.getUserToken(session.message.address, connectionName, undefined, (err, result) => {
    if (result) {
        // If there is already a token, the bot can use it directly
        session.send('You are already signed in with token: ' + result.token);
    } else {
        // If there not is already a token, the bot can send an OAuthCard to have the user log in
        if (!session.userData.activeSignIn) {
            session.send("Hello! Let's get you signed in!");
            builder.OAuthCard.create(connector, session, connectionName, "Please sign in", "Sign in", (createSignInErr, signInMessage) =>
            {
                if (signInMessage) {
                    session.send(signInMessage);
                    session.userData.activeSignIn = true;
                } else {
                    session.send("Something went wrong trying to sign you in.");
                }     
            });
        } else {
            // Some clients require a 6 digit code validation so we can check that here
            session.send("Let's see if that code works...");
            connector.getUserToken(session.message.address, connectionName, session.message.text, (err2, tokenResponse) => {
                if (tokenResponse) {
                    session.send('It worked! You are now signed in with token: ' + tokenResponse.token);
                    session.userData.activeSignIn = false;
                } else {
                    session.send("Hmm, that code wasn't right");
                }
            });
        }
    }
});

The Client id in the OAuth connection is my bot's AppId, the Client secret is my bot's password, and the Tenant ID is the bot's domain. The connection name is also right(the one in Azure) image

jwiley84 commented 5 years ago

That is a older sample. Let me see if I can figure out what's going on

jwiley84 commented 5 years ago

Have you tested your connection in the app portal?

image

muhualing commented 5 years ago

Have you tested your connection in the app portal?

image

Sure, I tested it and I can get a token.

jwiley84 commented 5 years ago

Good! It means your OAuth is set up right. Investigating!

jwiley84 commented 5 years ago

Just to toss it out there: I believe the issue is the channel. Teams takes some special handling. Can you test your oauth in another channel?

CoHealer commented 5 years ago

@muhualing , can you please acknowledge? Otherwise we'll have to close the issue.Thanks.

sgellock commented 5 years ago

should this have lived in the samples repo?

jwiley84 commented 5 years ago

This belongs in either v3 or sevices repo.

CoHealer commented 5 years ago

@muhualing I'm closing this for lack of response. If you still need assistance please re-open.