Accessing User Access Token in Bot Framework Python SDK for Teams Bot
A Teams Bot application has been developed using the Bot Framework Python SDK (v4.14.4), where BotFrameworkAdapter
and an extended ActivityHandler
class have been properly initialized. The bot is functioning correctly, allowing chat interactions and responses.
The goal is to retrieve the user access token from the incoming request (the token included in the header when a user sends a message) to make an external API call. However, only the TurnContext
object is available in the on_turn
or on_message_activity
methods of the ActivityHandler
.
In the app.py
file, the routing method for /api/messages
is as follows:
# Using FastAPI
# bot_framework_adapter and activity_handler are initialized at the global level
async def messages(req: Request) -> Response:
# .. some other logic
auth_token = req.headers.get("Authorization", "")
response = await bot_framework_adapter.process_activity(activity, auth_token, activity_handler.on_turn)
Is it possible to access/reconstruct this auth_token
within the ActivityHandler
methods (maybe using the TurnContext
object), or is there a recommended workaround for making an external API call with the same user authorization?
Thanks in advance.