Ejemplo n.º 1
0
        /// <summary>
        /// Enumerate the Linked Account status for a given UserId and return status information.
        /// </summary>
        /// <param name="userId">User Id value.</param>
        /// <param name="credentialProvider">The credential provider value.</param>
        /// <returns>Array of TokenStatus.</returns>
        public async Task <TokenStatus[]> GetTokenStatusAsync(string userId, ICredentialProvider credentialProvider)
        {
            // The BotFramework Adapter, Bot ApplicationID and Bot Secret is required to access the Token APIs
            // These must match the Bot making use of the Linked Accounts feature.
            var adapter        = new BotFrameworkAdapter(credentialProvider);
            var botAppId       = ((ConfigurationCredentialProvider)credentialProvider).AppId;
            var botAppPassword = ((ConfigurationCredentialProvider)credentialProvider).Password;

            TokenStatus[] tokenStatuses = null;

            using (var context = new TurnContext(adapter, new Microsoft.Bot.Schema.Activity {
            }))
            {
                var connectorClient = new ConnectorClient(new Uri(TokenServiceUrl), botAppId, botAppPassword);
                context.TurnState.Add <IConnectorClient>(connectorClient);
                // Add BotIdentity
                context.TurnState.Add <IIdentity>(BotAdapter.BotIdentityKey, new ClaimsIdentity(new List <Claim>
                {
                    new Claim(AuthenticationConstants.AudienceClaim, botAppId),
                }));

                // Retrieve the Token Status
                tokenStatuses = await adapter.GetTokenStatusAsync(context, userId);
            }

            return(tokenStatuses);
        }