コード例 #1
0
        public UmaIntrospectionMiddleware(
            RequestDelegate next,
            IApplicationBuilder app,
            IOptions <TOptions> options)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _next    = next;
            _app     = app;
            _options = options.Value;
            // Register dependencies
            var serviceCollection = new ServiceCollection();

            RegisterDependencies(serviceCollection, _options);
            _serviceProvider = serviceCollection.BuildServiceProvider();
            // Create empty middleware
            var nullAuthenticationBuilder = app.New();
            var nullAuthenticationOptions = new NullAuthenticationOptions
            {
                AutomaticAuthenticate = true,
                AutomaticChallenge    = true
            };

            nullAuthenticationBuilder.UseMiddleware <NullAuthenticationMiddleware>(Options.Create(nullAuthenticationOptions));
            nullAuthenticationBuilder.Run(ctx => next(ctx));
            _nullAuthenticationNext = nullAuthenticationBuilder.Build();
        }
コード例 #2
0
        public static IApplicationBuilder UseAuthenticationWithUmaIntrospection(this IApplicationBuilder app, UmaIntrospectionOptions umaIntrospectionOptions)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (umaIntrospectionOptions == null)
            {
                throw new ArgumentNullException(nameof(umaIntrospectionOptions));
            }

            return(app.UseMiddleware <UmaIntrospectionMiddleware <UmaIntrospectionOptions> >(app, Options.Create(umaIntrospectionOptions)));
        }
コード例 #3
0
        private static void RegisterDependencies(IServiceCollection serviceCollection, UmaIntrospectionOptions options)
        {
            if (options.IdentityServerUmaClientFactory != null)
            {
                serviceCollection.AddSingleton(options.IdentityServerUmaClientFactory);
            }
            else
            {
                serviceCollection.AddTransient <IIdentityServerUmaClientFactory, IdentityServerUmaClientFactory>();
            }

            if (options.IdentityServerUmaManagerClientFactory != null)
            {
                serviceCollection.AddSingleton(options.IdentityServerUmaManagerClientFactory);
            }
            else
            {
                serviceCollection.AddTransient <IIdentityServerUmaManagerClientFactory, IdentityServerUmaManagerClientFactory>();
            }

            if (options.IdentityServerClientFactory != null)
            {
                serviceCollection.AddSingleton(options.IdentityServerClientFactory);
            }
            else
            {
                serviceCollection.AddTransient <IIdentityServerClientFactory, IdentityServerClientFactory>();
            }
        }