Exemplo n.º 1
0
        /// <summary>
        /// Authenticate the request and add the service url in the activities to <see cref="MicrosoftAppCredentials.TrustedHostNames"/>.
        /// </summary>
        /// <param name="request">The incoming request.</param>
        /// <param name="activities">The incoming activities.</param>
        /// <param name="assembly">The assembly that should be resolved. <see cref="ResolveAssembly"/> for more information.</param>
        /// <param name="token">The cancellation token</param>
        /// <returns> The <see cref="BotServiceScope"/> that should be disposed when bot service operation is done for the request.</returns>
        public static async Task <BotServiceScope> AuthenticateAsync(HttpRequestMessage request, IEnumerable <Activity> activities, Assembly assembly = null, CancellationToken token = default(CancellationToken))
        {
            if (await Authenticator.TryAuthenticateAsync(request, activities, token))
            {
                var resolveAssembly = assembly ?? Assembly.GetCallingAssembly();
                return(new BotServiceScope(ResolveAssembly.Create(resolveAssembly)));
            }

            throw new UnauthorizedAccessException("Bot authentication failed!");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize bot service by updating the <see cref="Conversation.Container"/> with <see cref="AzureModule"/>.
        /// </summary>
        /// <param name="assembly"> The assembly that should be resolved.</param>
        /// <returns> The <see cref="BotServiceScope"/> that should be disposed when bot service operation is done for the request.</returns>
        public static BotServiceScope Initialize(Assembly assembly = null)
        {
            var resolveAssembly = assembly ?? Assembly.GetCallingAssembly();

            // update the container with azure module components
            var builder = new ContainerBuilder();

            builder.RegisterModule(new AzureModule(resolveAssembly));
            builder.Update(Conversation.Container);

            return(new BotServiceScope(ResolveAssembly.Create(resolveAssembly)));
        }