Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var initialScopes = Configuration.GetValue <string>("DownstreamApi:Scopes")?.Split(' ');

            services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
            .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
            .EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
            .AddMicrosoftGraph(Configuration.GetSection("DownstreamApi"))
            .AddInMemoryTokenCaches();

            var glasswallSettings = new GlasswallSettings();

            Configuration.GetSection("Glasswall").Bind(glasswallSettings);
            services.AddSingleton(glasswallSettings);

            services.AddControllersWithViews(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            });
            services.AddRazorPages()
            .AddMicrosoftIdentityUI();
        }
Example #2
0
 public HomeController(ILogger <HomeController> logger,
                       GraphServiceClient graphServiceClient,
                       GlasswallSettings glasswallSettings)
 {
     _logger             = logger;
     _graphServiceClient = graphServiceClient;
     _glasswallSettings  = glasswallSettings;
 }
Example #3
0
        public static void AddGlasswall(this IServiceCollection services, IConfigurationSection glasswallSection)
        {
            var glasswallSettings = new GlasswallSettings();

            glasswallSection.Bind(glasswallSettings);
            services.AddSingleton(glasswallSettings);

            services.AddRefitClient <IGlasswallClient>()
            .ConfigureHttpClient(c =>
            {
                c.BaseAddress = new Uri(glasswallSettings.BaseUrl);
                c.DefaultRequestHeaders.TryAddWithoutValidation("x-api-key", glasswallSettings.ApiKey);
            });

            services.AddScoped <IFileRebuilder, FileRebuilder>();
        }