Bot framework cannot find auth token.

%3CLINGO-SUB%20id%3D%22lingo-sub-1917267%22%20slang%3D%22en-US%22%3EBot%20framework%20cannot%20find%20auth%20token.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1917267%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-python%22%3E%3CCODE%3E2020-11-20T10%3A33%3A55.530099%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20await%20context.send_activity(Activity(type%3DActivityTypes.typing))%0A%0A2020-11-20T10%3A33%3A55.530099%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fbotbuilder%2Fcore%2Fturn_context.py%22%2C%20line%20174%2C%20in%20send_activity%0A%0A2020-11-20T10%3A33%3A55.530099%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20result%20%3D%20await%20self.send_activities(%5Bactivity_or_text%5D)%0A%0A2020-11-20T10%3A33%3A55.530100%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fbotbuilder%2Fcore%2Fturn_context.py%22%2C%20line%20226%2C%20in%20send_activities%0A%0A2020-11-20T10%3A33%3A55.530100%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20return%20await%20self._emit(self._on_send_activities%2C%20output%2C%20logic())%0A%0A2020-11-20T10%3A33%3A55.530100%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fbotbuilder%2Fcore%2Fturn_context.py%22%2C%20line%20304%2C%20in%20_emit%0A%0A2020-11-20T10%3A33%3A55.530100%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20return%20await%20logic%0A%0A2020-11-20T10%3A33%3A55.530101%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fbotbuilder%2Fcore%2Fturn_context.py%22%2C%20line%20221%2C%20in%20logic%0A%0A2020-11-20T10%3A33%3A55.530101%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20responses%20%3D%20await%20self.adapter.send_activities(self%2C%20output)%0A%0A2020-11-20T10%3A33%3A55.530101%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fbotbuilder%2Fcore%2Fbot_framework_adapter.py%22%2C%20line%20729%2C%20in%20send_activities%0A%0A2020-11-20T10%3A33%3A55.530101%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20raise%20error%0A%0A2020-11-20T10%3A33%3A55.530102%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fbotbuilder%2Fcore%2Fbot_framework_adapter.py%22%2C%20line%20714%2C%20in%20send_activities%0A%0A2020-11-20T10%3A33%3A55.530102%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20response%20%3D%20await%20client.conversations.reply_to_activity(%0A%0A2020-11-20T10%3A33%3A55.530102%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fbotframework%2Fconnector%2Faio%2Foperations_async%2F_conversations_operations_async.py%22%2C%20line%20528%2C%20in%20reply_to_activity%0A%0A2020-11-20T10%3A33%3A55.530103%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20response%20%3D%20await%20self._client.async_send(%0A%0A2020-11-20T10%3A33%3A55.530103%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fmsrest%2Fasync_client.py%22%2C%20line%20115%2C%20in%20async_send%0A%0A2020-11-20T10%3A33%3A55.530103%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20pipeline_response%20%3D%20await%20self.config.pipeline.run(request%2C%20**kwargs)%0A%0A2020-11-20T10%3A33%3A55.530103%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fmsrest%2Fpipeline%2Fasync_abc.py%22%2C%20line%20159%2C%20in%20run%0A%0A2020-11-20T10%3A33%3A55.530103%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20return%20await%20first_node.send(pipeline_request%2C%20**kwargs)%20%20%23%20type%3A%20ignore%0A%0A2020-11-20T10%3A33%3A55.530108%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fmsrest%2Fpipeline%2Fasync_abc.py%22%2C%20line%2079%2C%20in%20send%0A%0A2020-11-20T10%3A33%3A55.530108%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20response%20%3D%20await%20self.next.send(request%2C%20**kwargs)%20%20%23%20type%3A%20ignore%0A%0A2020-11-20T10%3A33%3A55.530108%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fmsrest%2Fpipeline%2Fasync_requests.py%22%2C%20line%2099%2C%20in%20send%0A%0A2020-11-20T10%3A33%3A55.530109%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20self._creds.signed_session(session)%0A%0A2020-11-20T10%3A33%3A55.530109%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fbotframework%2Fconnector%2Fauth%2Fapp_credentials.py%22%2C%20line%2098%2C%20in%20signed_session%0A%0A2020-11-20T10%3A33%3A55.530109%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20auth_token%20%3D%20self.get_access_token()%0A%0A2020-11-20T10%3A33%3A55.530109%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20File%20%22%2Fapp%2F.heroku%2Fpython%2Flib%2Fpython3.8%2Fsite-packages%2Fbotframework%2Fconnector%2Fauth%2Fmicrosoft_app_credentials.py%22%2C%20line%2065%2C%20in%20get_access_token%0A%0A2020-11-20T10%3A33%3A55.530109%2B00%3A00%20app%5Bweb.1%5D%3A%20%20%20%20%20return%20auth_token%5B%22access_token%22%5D%0A%0A2020-11-20T10%3A33%3A55.530110%2B00%3A00%20app%5Bweb.1%5D%3A%20KeyError%3A%20'access_token'%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20worked%20before%2C%20I%20didn't%20change%20code%20but%20anyway%20it's%20framework-side%20I%20think.%20Of%20course%2C%20I%20have%20a%20token%20from%20the%20auth%20header.%20It%20looks%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-python%22%3E%3CCODE%3EBearer%20eyJ...6wQ%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20Im%20putting%20in%20adapter%20process%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-python%22%3E%3CCODE%3Eloop.run_until_complete(loop.create_task(ADAPTER.process_activity(activity%2C%20auth_header%2C%20api_handler)))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EActivity%20is%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-python%22%3E%3CCODE%3Eactivity%20%3D%20Activity().deserialize(body)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20api_handler%20is%20my%20function%20that%20handle%20new%20messages.%20Problem%20occurs%20when%20I%20try%20to%20send%20activity%20via%20TurnContext.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1917267%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMicrosoft%20Teams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1922995%22%20slang%3D%22en-US%22%3ERe%3A%20Bot%20framework%20cannot%20find%20auth%20token.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1922995%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F845237%22%20target%3D%22_blank%22%3E%40norxnd%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EWe%20are%20not%20able%20to%20repro%20the%20issue%20at%20our%20end%2C%20Are%20you%20trying%20to%20send%20message%20to%20user%20using%20with%20authentication%3F%20If%20yes%20could%20you%20please%20check%20this%26nbsp%3B%3C%2FSPAN%3E%3CA%20tabindex%3D%22-1%22%20title%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fbotbuilder-samples%2Ftree%2Fmain%2Fsamples%2Fcsharp_dotnetcore%2F18.bot-authentication%22%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FBotBuilder-Samples%2Ftree%2Fmain%2Fsamples%2Fcsharp_dotnetcore%2F18.bot-authentication%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%20aria-disabled%3D%22false%22%3Esample%3C%2FA%3E%3CSPAN%3E.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1923193%22%20slang%3D%22en-US%22%3ERe%3A%20Bot%20framework%20cannot%20find%20auth%20token.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1923193%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F749860%22%20target%3D%22_blank%22%3E%40Varaprasad-MSFT%3C%2FA%3E%26nbsp%3B%20First%2C%20this%20sample%20is%20for%20Csharp%20dotnet%20core%20but%20Im%20using%20Python.%20Second%20idk.%20Are%20you%20trying%20to%20send%20message%20to%20user%20using%20with%20authentication%3F%20I%20have%20token%20from%20header%20and%20Im%20putting%20it%20into%20Adapter%20and%20then%20sending%20activity%20via%3C%2FP%3E%3CPRE%3ETURN%20CONTEXT%20GIVEN%20BY%20ADAPTER.send_activity()%3C%2FPRE%3E%3CP%3EI%20didn't%20change%20this%20part%20of%20the%20code%20and%20it%20stopped%20working%20on%20Friday.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

 

2020-11-20T10:33:55.530099+00:00 app[web.1]:     await context.send_activity(Activity(type=ActivityTypes.typing))

2020-11-20T10:33:55.530099+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 174, in send_activity

2020-11-20T10:33:55.530099+00:00 app[web.1]:     result = await self.send_activities([activity_or_text])

2020-11-20T10:33:55.530100+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 226, in send_activities

2020-11-20T10:33:55.530100+00:00 app[web.1]:     return await self._emit(self._on_send_activities, output, logic())

2020-11-20T10:33:55.530100+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 304, in _emit

2020-11-20T10:33:55.530100+00:00 app[web.1]:     return await logic

2020-11-20T10:33:55.530101+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/botbuilder/core/turn_context.py", line 221, in logic

2020-11-20T10:33:55.530101+00:00 app[web.1]:     responses = await self.adapter.send_activities(self, output)

2020-11-20T10:33:55.530101+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/botbuilder/core/bot_framework_adapter.py", line 729, in send_activities

2020-11-20T10:33:55.530101+00:00 app[web.1]:     raise error

2020-11-20T10:33:55.530102+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/botbuilder/core/bot_framework_adapter.py", line 714, in send_activities

2020-11-20T10:33:55.530102+00:00 app[web.1]:     response = await client.conversations.reply_to_activity(

2020-11-20T10:33:55.530102+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/botframework/connector/aio/operations_async/_conversations_operations_async.py", line 528, in reply_to_activity

2020-11-20T10:33:55.530103+00:00 app[web.1]:     response = await self._client.async_send(

2020-11-20T10:33:55.530103+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/msrest/async_client.py", line 115, in async_send

2020-11-20T10:33:55.530103+00:00 app[web.1]:     pipeline_response = await self.config.pipeline.run(request, **kwargs)

2020-11-20T10:33:55.530103+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/msrest/pipeline/async_abc.py", line 159, in run

2020-11-20T10:33:55.530103+00:00 app[web.1]:     return await first_node.send(pipeline_request, **kwargs)  # type: ignore

2020-11-20T10:33:55.530108+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/msrest/pipeline/async_abc.py", line 79, in send

2020-11-20T10:33:55.530108+00:00 app[web.1]:     response = await self.next.send(request, **kwargs)  # type: ignore

2020-11-20T10:33:55.530108+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/msrest/pipeline/async_requests.py", line 99, in send

2020-11-20T10:33:55.530109+00:00 app[web.1]:     self._creds.signed_session(session)

2020-11-20T10:33:55.530109+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/botframework/connector/auth/app_credentials.py", line 98, in signed_session

2020-11-20T10:33:55.530109+00:00 app[web.1]:     auth_token = self.get_access_token()

2020-11-20T10:33:55.530109+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/botframework/connector/auth/microsoft_app_credentials.py", line 65, in get_access_token

2020-11-20T10:33:55.530109+00:00 app[web.1]:     return auth_token["access_token"]

2020-11-20T10:33:55.530110+00:00 app[web.1]: KeyError: 'access_token'

 

It worked before, I didn't change code but anyway it's framework-side I think. Of course, I have a token from the auth header. It looks like this:

 

Bearer eyJ...6wQ

 

And Im putting in adapter process:

 

loop.run_until_complete(loop.create_task(ADAPTER.process_activity(activity, auth_header, api_handler)))

 

Activity is:

 

activity = Activity().deserialize(body)

 

And api_handler is my function that handle new messages. Problem occurs when I try to send activity via TurnContext.

3 Replies

@norxnd 

 

We are not able to repro the issue at our end, Are you trying to send message to user using with authentication? If yes could you please check this sample.

@Varaprasad-MSFT  First, this sample is for Csharp dotnet core but Im using Python. Second idk. Are you trying to send message to user using with authentication? I have token from header and Im putting it into Adapter and then sending activity via

TURN CONTEXT GIVEN BY ADAPTER.send_activity()

I didn't change this part of the code and it stopped working on Friday.

Here is the Sample in Python, please have a look for reference and let us know if you need any help.