Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Authenticating to Teams (400) Bad Request #186

Closed
alexixiv opened this issue Nov 4, 2019 · 7 comments
Closed

Error Authenticating to Teams (400) Bad Request #186

alexixiv opened this issue Nov 4, 2019 · 7 comments
Labels

Comments

@alexixiv
Copy link

alexixiv commented Nov 4, 2019

Expected Behavior

Bot launches without error.

Current Behavior

Error occurs "Error Authenticating to Teams... (400) Bad Request"

PoshBotErrorTeams

Possible Solution

I need to adjust my settings somewhere

Steps to Reproduce (for bugs)

I attempted to follow the steps in the documentation for setting up MS Teams PoshBot. I feel I followed all the steps correctly but I am not sure where to look to address this issue. If I had to make a guess at what is happening I would think my credentials in the backend configuration variables I put in are not correct. I have numbered the fields in the screen shot to indicate what step from the document I generated the corresponding value from:

  1. Generated from section titled "Determine Your Teams ID"

  2. Generated from the section titled "Service Bus", I used just the key which ends in =

  3. For this one I was not sure which one to use so I tried both the keys from section "Create a Bot in Bot Framework" and the App ID from App Studio.

  4. Generated from the section "Create a Bot in Bot Framework" but the steps were different as it redirected to azure portal, and I ended up created a key in the "Certificates and secrets" panel.

Context

This is my first time attempting to get this working for MS Teams. I am running Powershell ISE as admin and including "Set-ExecutionPolicy Unrestricted" just to get around any potential local permissions issues.

Your Environment

  • Module version used: 0.11.8
  • Operating System and PowerShell version: Windows 10, Powershell 5
@alexixiv
Copy link
Author

alexixiv commented Nov 8, 2019

I took another run at this starting from scratch and still hit the same error as above.

@brettmillerb
Copy link
Contributor

Hi @alexixiv you may have some issues with your config.

Import-Module PoshBot
$pbc = New-PoshBotConfiguration
$pbc.BotAdmins = @('<AAD-USER-PRINCIPAL-NAME>')

$backendConfig = @{
    Name                = 'TeamsBackend'
    BotName             = '<BOT-NAME>'
    TeamId              = '<TEAMS-ID>'
    ServiceBusNamespace = '<SERVICE-BUS-NAMESPACE-NAME>'
    QueueName           = 'messages'
    AccessKeyName       = 'receive'
    AccessKey           = '<SAS-KEY>' | ConvertTo-SecureString -AsPlainText -Force
    Credential          = [pscredential]::new(
        '<BOT-APP-ID>',
        ('<BOT-APP-PASSWORD>' | ConvertTo-SecureString -AsPlainText -Force)
    )
}
$backend = New-PoshBotTeamsBackend -Configuration $backendConfig

$bot = New-PoshBotInstance -Configuration $pbc -Backend $backend
$bot | Start-PoshBot -Verbose

Few things worth mentioning:

  • $pbc.botadmins This needs to be an AzureAD UPN of your user or someone who is going to manage poshbot, not your bot name.

  • BotName in the config is as defined in Azure Bot Service, not in App Studio. Try and keep them the same name to avoid confusion

  • Access key is the value you get running this from the docs.

    $key = az servicebus queue authorization-rule keys list --resource-group <RESOURCE-GROUP-NAME> \
      --namespace-name <NAMESPACE-NAME> --queue-name messages --name receive --query primaryKey --output tsv
    
  • The credentials you use are from the App Registration within the Azure Portal > Azure Active Directory > App Registration

image

@alexixiv
Copy link
Author

@brettmillerb , Thanks for the tips. I tried what you said. The two places that seemed like they needed corrections were the BotAdmins and the Bot App Password. The App ID seems correct, but I did go ahead and try the App ID found in the Azure portal as well, which still didnt work. I am getting the same error as before.

Any other suggestions... I very much want this to work.

@brettmillerb
Copy link
Contributor

@alexixiv The only other thing to check would be the Bot configuration in Azure Bot Service. Did you add the teams channel for your bot?

Open your bot in azure bot service and click on channels from the pane and add teams there.

Never seen a failure when starting the bot before like that.

@Kickbut101
Copy link

If it's anything like mine you setup the bot in azure framework to be single tenant. And this causes it to be screwy and give the 400 error. Make a new bot and set to be multi-tenant. That's what fixed it for me.

@alexixiv

@stale
Copy link

stale bot commented Jan 22, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 22, 2020
@stale stale bot closed this as completed Feb 5, 2020
@drenand
Copy link

drenand commented Oct 15, 2020

If it's anything like mine you setup the bot in azure framework to be single tenant. And this causes it to be screwy and give the 400 error. Make a new bot and set to be multi-tenant. That's what fixed it for me.

@alexixiv

+1 to this solution, finally solved this error for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants