Esempio n. 1
0
        public void Configure(IWebJobsBuilder builder)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Environment.CurrentDirectory)
                                .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                                .AddEnvironmentVariables()
                                .Build();

            var config =
                new PowerAppsAuthenticationSettings
            {
                ClientId     = configuration["clientId"],
                ClientSecret = configuration["secret"],
                DirectoryId  = configuration["directory"],
                ApiUrl       = configuration["powerappsApiUrl"],
                ResourceUrl  = configuration["powerappsUrl"],
            };

            builder.Services.AddPowerAppsWebApiConfiguration(config);
        }
Esempio n. 2
0
        public static IServiceCollection AddPowerAppsWebApiConfiguration(this IServiceCollection services, PowerAppsAuthenticationSettings authenticationSettings)
        {
            services
            .AddSingleton <PowerAppsAuthenticationSettings>(p => authenticationSettings)
            .AddTransient <AuthenticationMessageHandler>()
            .AddTransient <WebApiContext>()
            .AddTransient(typeof(GenericRepository <>))
            .AddHttpClient(
                "webapi",
                p =>
            {
                p.BaseAddress = new Uri(authenticationSettings.ApiUrl);
                p.Timeout     = new TimeSpan(0, 2, 0);
                p.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
                p.DefaultRequestHeaders.Add("OData-Version", "4.0");
            })
            .AddHttpMessageHandler <AuthenticationMessageHandler>();

            return(services);
        }