Skip to content

TurnContext.TurnState is missing ClaimsIdentity in streaming scenarios #4674

@stevengum

Description

@stevengum

Version

4.10.3

Describe the bug

The ClaimsIdentity is not populated in the TurnState for streaming scenarios.

To Reproduce

  1. Setup the 24.bot-authentication-msgraph sample
  2. Configure Direct Line ASE or Direct Line Speech for the bot
  3. Ping the bot via Web Chat
  4. Check bot's logs for error, Unable to get the bot AppId from the audience claim.

Expected behavior

The bot should have the ClaimsIdentity available for normal streaming scenarios.

Additional context

There exists a workaround for populating the ClaimsIdentity in a BotFrameworkHttpAdapterBase subclass, which adequately works for Direct Line ASE. However, this route does not support dynamic setting which means it will not work on a bot using multiple Bot Channels Registrations with Direct Line Speech. (e.g. multiple AAD AppIds)

The BotframeworkHttpAdapter should populate the ClaimsIdentity during a successful upgrade for Direct Line Speech.

Direct Line ASE/Single AAD AppId workaround:

    public class AdapterWithErrorHandler : BotFrameworkHttpAdapter
    {
        public AdapterWithErrorHandler(IConfiguration configuration, ILogger<BotFrameworkHttpAdapter> logger, ConversationState conversationState = null)
            : base(configuration, logger)
        {

            // For OAuth + Direct Line ASE scenarios, create and store a ClaimsIdentity with the AppId of the bot.
            var appId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;

            ClaimsIdentity = new ClaimsIdentity(new List<Claim>{
                new Claim(AuthenticationConstants.AudienceClaim, appId)
            });

Metadata

Metadata

Assignees

Labels

Area: AuthenticationThe issue is related to authenticating users (SSO, OAuth, etc.)Area: StreamingIssues related to streaming supportP1Painful if we don't fix, won't block releasingSize: SThe issue is simple and well understood, it will take a day or less to completebugIndicates an unexpected problem or an unintended behavior.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions