Exemplo n.º 1
0
        private void RegisterServices(IServiceCollection services)
        {
            // 1. Add CORE.
            services.AddSimpleIdServerUmaCore(null, UmaStores.GetResources())
            .AddSimpleIdentityServerCore(clients: OAuthStores.GetClients(), jsonWebKeys: OAuthStores.GetJsonWebKeys(_context), scopes: OAuthStores.GetScopes())
            .AddSimpleIdentityServerJwt()
            .AddTransient <IIdentityServerClientFactory, IdentityServerClientFactory>()
            .AddDefaultSimpleBus()
            .AddDefaultConcurrency()
            .AddDefaultTokenStore();

            // 3. Enable logging.
            services.AddSingleton(new AuthorizationServerOptions
            {
                OpenidWellKnownConfiguration = "http://localhost:60000/.well-known/openid-configuration"
            });
            services.AddLogging();
            services.AddTechnicalLogging();
            services.AddOAuthLogging();
            services.AddUmaLogging();
            // 4. Register the services.
            services.AddTransient <SimpleIdServer.Core.Services.IConfigurationService, DefaultConfigurationService>();
            // 5. Register other classes.
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddTransient <IUmaServerEventSource, UmaServerEventSource>();
            services.AddTransient <IIdentityServerClientFactory, FakeIdentityServerClientFactory>();
        }
Exemplo n.º 2
0
        public void ConfigureServices(IServiceCollection services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            // 1. Add the dependencies.
            // 2. Add authorization policies.
            services.AddAuthentication(
                opts =>
            {
                opts.DefaultAuthenticateScheme = DefaultSchema;
                opts.DefaultChallengeScheme    = DefaultSchema;
            })
            .AddUmaCustomAuth(o => { });
            services.AddAuthorization(
                opts =>
            {
                opts.AddAuthPolicies((OpenIdClaimTypes.Role, "administrator"), DefaultSchema)
                .AddPolicy(
                    "UmaProtection",
                    policy =>
                {
                    policy.AddAuthenticationSchemes(DefaultSchema);
                    policy.RequireAssertion(p => true);
                });
            });
            // 3. Add the dependencies needed to enable CORS
            services.AddCors(
                options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));

            services
            .AddControllersWithViews()
            .AddRazorRuntimeCompilation()
            .AddApplicationPart(typeof(CoreConstants).Assembly);
            services.AddRazorPages();
            services.AddSimpleAuth(
                new SimpleAuthOptions
            {
                Clients = sp => new InMemoryClientRepository(
                    new Mock <IHttpClientFactory>().Object,
                    sp.GetService <IScopeStore>(),
                    new Mock <ILogger <InMemoryClientRepository> >().Object,
                    OAuthStores.GetClients()),
                Scopes       = _ => new InMemoryScopeRepository(OAuthStores.GetScopes()),
                ResourceSets = _ => new InMemoryResourceSetRepository(UmaStores.GetResources())
            },
                new[] { DefaultSchema },
                assemblyTypes: typeof(IDefaultUi));

            // 3. Enable logging.
            services.AddLogging(l => l.AddXunit(_outputHelper));
            // 5. Register other classes.
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
        }