public AlerterSecurity(SecurityConfig securityConfig, ILogger <AlerterSecurity> logger)
        {
            this.securityConfig   = securityConfig;
            this.logger           = logger;
            AdditionalValidIssuer = $"https://sts.windows.net/{securityConfig.TenantId}/";
            IdentityProvider      = $"https://login.microsoftonline.com/{securityConfig.TenantId}/v2.0/";

            _configurationManager = new ConfigurationManager <OpenIdConnectConfiguration>(
                $"{IdentityProvider}.well-known/openid-configuration",
                new OpenIdConnectConfigurationRetriever(),
                new HttpDocumentRetriever {
                RequireHttps = true
            }
                );
        }
Esempio n. 2
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var securityConfig = new SecurityConfig
            {
                TenantId     = "ef660bca-495a-4ed8-88d3-38ce8741a9fa",
                AppId        = "cafcc835-bfd8-4aa5-9c34-c56ec57d590c",
                Audience     = "api://alerter-demo",
                ClientSecret = Environment.GetEnvironmentVariable("OAUTH_CLIENT_SECRET")
            };

            builder.Services.AddSingleton(securityConfig);
            builder.Services.AddSingleton <AlerterSecurity>();

            var clientApplication = ConfidentialClientApplicationBuilder
                                    .Create(securityConfig.AppId)
                                    .WithClientSecret(securityConfig.ClientSecret)
                                    .WithTenantId(securityConfig.TenantId)
                                    .Build();

            var graphServiceClient = new GraphServiceClient(new ClientCredentialProvider(clientApplication));

            builder.Services.AddSingleton <IGraphServiceClient>(graphServiceClient);
        }