示例#1
0
        public IdentityServerAuthenticationMiddleware(RequestDelegate next, IApplicationBuilder app, CombinedAuthenticationOptions options, ILogger <IdentityServerAuthenticationMiddleware> logger)
        {
            _next    = next;
            _options = options;
            _logger  = logger;

            // building pipeline for introspection middleware
            if (options.IntrospectionOptions != null)
            {
                var introspectionBuilder = app.New();
                introspectionBuilder.UseOAuth2IntrospectionAuthentication(options.IntrospectionOptions);
                introspectionBuilder.Run(ctx => next(ctx));
                _introspectionNext = introspectionBuilder.Build();
            }

            // building pipeline for JWT bearer middleware
            if (options.JwtBearerOptions != null)
            {
                var jwtBuilder = app.New();
                jwtBuilder.UseJwtBearerAuthentication(options.JwtBearerOptions);
                jwtBuilder.Run(ctx => next(ctx));
                _jwtNext = jwtBuilder.Build();
            }

            // building pipeline for no token
            var nopBuilder = app.New();
            var nopOptions = new NopAuthenticationOptions
            {
                AuthenticationScheme = options.AuthenticationScheme
            };

            nopBuilder.UseMiddleware <NopAuthenticationMiddleware>(Options.Create(nopOptions));
            nopBuilder.Run(ctx => next(ctx));
            _nopNext = nopBuilder.Build();
        }
        public IdentityServerAuthenticationMiddleware(RequestDelegate next, IApplicationBuilder app, CombinedAuthenticationOptions options, ILogger<IdentityServerAuthenticationMiddleware> logger)
        {
            _next = next;
            _options = options;
            _logger = logger;

            // building pipeline for introspection middleware
            if (options.IntrospectionOptions != null)
            {
                var introspectionBuilder = app.New();
                introspectionBuilder.UseOAuth2IntrospectionAuthentication(options.IntrospectionOptions);
                introspectionBuilder.Run(ctx => next(ctx));
                _introspectionNext = introspectionBuilder.Build();
            }

            // building pipeline for JWT bearer middleware
            if (options.JwtBearerOptions != null)
            {
                var jwtBuilder = app.New();
                jwtBuilder.UseJwtBearerAuthentication(options.JwtBearerOptions);
                jwtBuilder.Run(ctx => next(ctx));
                _jwtNext = jwtBuilder.Build();
            }

            // building pipeline for no token
            var nopBuilder = app.New();
            var nopOptions = new NopAuthenticationOptions
            {
                AuthenticationScheme = options.AuthenticationScheme
            };

            nopBuilder.UseMiddleware<NopAuthenticationMiddleware>(nopOptions);
            nopBuilder.Run(ctx => next(ctx));
            _nopNext = nopBuilder.Build();
        }