public TokenExchangeSkillHandler(
            BotAdapter adapter,
            IBot bot,
            IConfiguration configuration,
            SkillConversationIdFactoryBase conversationIdFactory,
            SkillsConfiguration skillsConfig,
            SkillHttpClient skillClient,
            ICredentialProvider credentialProvider,
            AuthenticationConfiguration authConfig,
            IChannelProvider channelProvider           = null,
            ILogger <TokenExchangeSkillHandler> logger = null)
            : base(adapter, bot, conversationIdFactory, credentialProvider, authConfig, channelProvider, logger)
        {
            _adapter = adapter;
            _tokenExchangeProvider = adapter as IExtendedUserTokenProvider;
            if (_tokenExchangeProvider == null)
            {
                throw new ArgumentException($"{nameof(adapter)} does not support token exchange");
            }

            _configuration         = configuration;
            _skillsConfig          = skillsConfig;
            _skillClient           = skillClient;
            _conversationIdFactory = conversationIdFactory;
            _logger = logger ?? NullLogger <TokenExchangeSkillHandler> .Instance;
            _botId  = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
        }
示例#2
0
        public TokenExchangeSkillHandler(
            BotAdapter adapter,
            IBot bot,
            IConfiguration configuration,
            SkillConversationIdFactoryBase conversationIdFactory,
            SkillsConfiguration skillsConfig,
            SkillHttpClient skillClient,
            ICredentialProvider credentialProvider,
            AuthenticationConfiguration authConfig,
            ITokenExchangeConfig tokenExchangeConfig,
            IChannelProvider channelProvider = null,
            ILogger logger = null)
            : base(adapter, bot, conversationIdFactory, credentialProvider, authConfig, channelProvider, logger)
        {
            _adapter = adapter;
            _tokenExchangeProvider = adapter as IExtendedUserTokenProvider;
            _tokenExchangeConfig   = tokenExchangeConfig;
            _skillsConfig          = skillsConfig;
            _skillClient           = skillClient;
            _conversationIdFactory = conversationIdFactory;

            _botId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value;
        }
        private static Task <TokenResponse> GetUserTokenAsync(DialogContext dc, IExtendedUserTokenProvider tokenProvider, string connectionName, CancellationToken cancellationToken)
        {
            // When the Bot Service Auth flow completes, the action.State will contain a magic code used for verification.
            string state = null;

            if (dc.Context.Activity.Value is JObject valueAsObject)
            {
                state = valueAsObject.Value <string>("state");
            }

            string magicCode = null;

            if (!string.IsNullOrEmpty(state))
            {
                if (int.TryParse(state, out var parsed))
                {
                    magicCode = parsed.ToString(CultureInfo.InvariantCulture);
                }
            }

            // TODO: SSO and skills token exchange

            return(tokenProvider.GetUserTokenAsync(dc.Context, connectionName, magicCode, cancellationToken: cancellationToken));
        }
        private async Task <Activity> GetInvokeResponseWithSignInLinkAsync(DialogContext dc, string title, IExtendedUserTokenProvider tokenProvider, string connectionName, CancellationToken cancellationToken)
        {
            // Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions
            var signInLink = await tokenProvider.GetOauthSignInLinkAsync(dc.Context, connectionName, cancellationToken : cancellationToken).ConfigureAwait(false);

            var result = new MessagingExtensionResult
            {
                Type             = MessagingExtensionResultResponseType.auth.ToString(),
                SuggestedActions = new MessagingExtensionSuggestedAction
                {
                    Actions = new List <CardAction>
                    {
                        new CardAction
                        {
                            Type  = ActionTypes.OpenUrl,
                            Value = signInLink,
                            Title = title,
                        },
                    },
                },
            };

            return(CreateMessagingExtensionInvokeResponseActivity(dc, result));
        }