microsoft / BotFramework-Emulator

A desktop application that allows users to locally test and debug chat bots built with the Bot Framework SDK.
https://aka.ms/botemulator
MIT License
1.82k stars 756 forks source link

Token is not getting generated. #2431

Closed vinayburam closed 1 year ago

vinayburam commented 1 year ago

Hello team, I am trying to post message in teams using below code but getting few errors. I am new to this so seeking your help to address the issue.

When I used below line getting error

 authUrl = "https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token"

authMessage = "grant_type=client_credentials&client_id=" + msAppId + "&client_secret=" + urllib.parse.quote(msAppPass, safe="") + "&scope=https%3A%2F%2Fapi.botframework.com%2F.default" Error : authReply {'error': 'unauthorized_client', 'error_description': "AADSTS700016: Application with identifier '{id}' was not found in the directory 'Bot Framework'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.\r\nTrace ID: {trace-id}\r\nCorrelation ID: {cor-id}\r\nTimestamp: 2023-06-21 08:21:04Z", 'error_codes': [700016], 'timestamp': '2023-06-21 08:21:04Z', 'trace_id': {trace-id}, 'correlation_id': {cor-id}', 'error_uri': 'https://login.microsoftonline.com/error?code=700016'}

And When trying to generate token using Tenant ID getting 401 status while doing POST request

authUrl = "https://login.microsoftonline.com/{tenant-id}/oauth2/v2.0/token"

authMessage = "grant_type=client_credentials&client_id=" + msAppId + "&client_secret=" + urllib.parse.quote(msAppPass, safe="") + "&scope=https://graph.microsoft.com/.default"

 print('authMessage',authMessage)
logger.debug('postResponseToTeams: obtaining MS Bot Framework access token')
r = http.request('POST', authUrl, body=authMessage, headers=hed)
logger.debug(' postResponseToTeams: MS Bot Framework POST response status = ' + str(r.status))
authReply = json.loads(r.data.decode('ascii'))
print('authReply',authReply)
# logger.debug('postResponseToTeams: MS Bot Framework auth reply = ' + json.dumps(authReply))

########Error while POST request (401)###### logger.debug('postResponseToTeams: sending Lex response to MS Bot Framework') hed = {"Authorization" : "Bearer " + authReply["access_token"], "Content-Type": "application/json"} print("returnUrl",returnUrl)

returnUrl https://smba.trafficmanager.net/amer/v3/conversations/

r = http.request('POST', returnUrl, body=json.dumps(message), headers=hed)

Could you please have a look into issue and suggest

breakingram commented 1 year ago

Hi @vinayburam,

breakingram commented 1 year ago

Closing due to inactivity. @vinayburam, please re-open with steps to reproduce the issue. Thanks.