Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddMemoryCache();
            services.AddDbContext <DatabaseContext>(options => options.UseInMemoryDatabase("database"));
            services.AddScoped <ServicePrincipalRepository>();

            services.AddSingleton <TokenService>();
            services.AddSingleton <TokenCacheproviderFactory>();
            services.AddSingleton <TicketStoreService>();

            services.AddScoped <GraphService>();
            services.AddHttpClient <AzureManagementService>()
            .AddPolicyHandler(AzureManagementService.CreateHttpClientPolicy());

            services.AddAuthentication(sharedOptions =>
            {
                sharedOptions.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                sharedOptions.DefaultScheme             = CookieAuthenticationDefaults.AuthenticationScheme;
                sharedOptions.DefaultChallengeScheme    = OpenIdConnectDefaults.AuthenticationScheme;
            })
            .AddAzureAd(options => Configuration.Bind("AzureAd", options));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Exemplo n.º 2
0
 public ServicePrincipalController(
     TokenService tokenService,
     GraphService graphService,
     IOptions <AzureAdOptions> adOptions,
     IOptions <OpenIdConnectOptions> oidcOptions,
     AzureManagementService azureManagementService,
     ServicePrincipalRepository repository)
 {
     _tokenService           = tokenService;
     _graphService           = graphService;
     _adOptions              = adOptions.Value;
     _oidcOptions            = oidcOptions.Value;
     _azureManagementService = azureManagementService;
     _repository             = repository;
 }