I am doing some work in background tasks and have userid (that was extracted from activity.from.id) and connectionname available with me.
How do I get the user token from bot service? - turncontext is not available.
I am doing some work in background tasks and have userid (that was extracted from activity.from.id) and connectionname available with me.
How do I get the user token from bot service? - turncontext is not available.
Remember that Bot Framework REST API calls must be authorized, so in addition to the user ID and the connection name you will also need your bot's app credentials. If you have all of these, you can get a user token like this:
private async Task<string> GetUserTokenAsync(string userId, string connectionName, AppCredentials appCredentials)
{
var client = new OAuthClient(new Uri(OAuthClientConfig.OAuthEndpoint), appCredentials);
var response = await client.UserToken.GetTokenAsync(userId, connectionName);
return response.Token;
}
This is somewhat drawn from code that can be found in BotFrameworkAdapter.cs, but modified to not need a turn context.