public FederatedSignoutAuthenticationHandlerProvider(
     Decorator <IAuthenticationHandlerProvider> decorator,
     IHttpContextAccessor httpContextAccessor)
 {
     _provider            = decorator.Instance;
     _httpContextAccessor = httpContextAccessor;
 }
Exemple #2
0
 public ClaimsUserSession(IHttpContextAccessor httpContextAccessor, IAuthenticationSchemeProvider schemes, IAuthenticationHandlerProvider handlers, ILogger <IUserSession> logger)
 {
     this.httpContextAccessor = httpContextAccessor;
     this.schemes             = schemes;
     this.handlers            = handlers;
     this.logger = logger;
 }
 public IdentityServerAuthenticationHandlerProvider(
     Decorator <IAuthenticationHandlerProvider> decorator,
     IHttpContextAccessor httpContextAccessor)
 {
     _provider            = decorator.Instance;
     _httpContextAccessor = httpContextAccessor;
 }
 public MetadataController(
     IOptions <AuthenticationOptions> authenticationOptions,
     IAuthenticationHandlerProvider authenticationHandlerProvider)
 {
     _authenticationOptions         = authenticationOptions.Value;
     _authenticationHandlerProvider = authenticationHandlerProvider;
 }
Exemple #5
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="schemes">The <see cref="IAuthenticationSchemeProvider"/>.</param>
 /// <param name="handlers">The <see cref="IAuthenticationHandlerProvider"/>.</param>
 /// <param name="transform">The <see cref="IClaimsTransformation"/>.</param>
 /// <param name="options">The <see cref="AuthenticationOptions"/>.</param>
 public AuthenticationService(IAuthenticationSchemeProvider schemes, IAuthenticationHandlerProvider handlers, IClaimsTransformation transform, IOptions <AuthenticationOptions> options)
 {
     Schemes   = schemes;
     Handlers  = handlers;
     Transform = transform;
     Options   = options.Value;
 }
        /// <summary>
        /// Invoke middleware actions
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <returns>Task</returns>
        public async Task InvokeAsync(HttpContext context, IAuthenticationHandlerProvider handlers)
        {
            context.Features.Set <IAuthenticationFeature>(new AuthenticationFeature {
                OriginalPath     = context.Request.Path,
                OriginalPathBase = context.Request.PathBase
            });

            foreach (var scheme in await Schemes.GetRequestHandlerSchemesAsync())
            {
                try
                {
                    if (await handlers.GetHandlerAsync(context, scheme.Name) is IAuthenticationRequestHandler handler && handler != null && await handler.HandleRequestAsync())
                    {
                        return;
                    }
                }
                catch { continue; }
            }

            var defaultAuthenticate = await Schemes.GetDefaultAuthenticateSchemeAsync();

            if (defaultAuthenticate != null)
            {
                var result = await context.AuthenticateAsync(defaultAuthenticate.Name);

                if (result?.Principal != null)
                {
                    context.User = result.Principal;
                }
            }

            await _next(context);
        }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FederatedSignoutAuthenticationHandlerProvider"/> class.
 /// </summary>
 /// <param name="decorator">The authentication handler provider decorator.</param>
 /// <param name="httpContextAccessor">The HTTP context accessor.</param>
 /// <exception cref="ArgumentNullException">httpContextAccessor</exception>
 public FederatedSignoutAuthenticationHandlerProvider(
     Decorator <IAuthenticationHandlerProvider> decorator,
     IHttpContextAccessor httpContextAccessor)
 {
     _provider            = decorator.Instance;
     _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
     _handlerMap          = new Dictionary <string, IAuthenticationHandler>();
 }
 public LinkBankAccountController(ILogger <HomeController> logger, IAuthenticationSchemeProvider schemes,
                                  IAuthenticationHandlerProvider handlerProvider, IAuthenticationService authenticationService)
 {
     _logger                = logger;
     _schemes               = schemes;
     _handlerProvider       = handlerProvider;
     _authenticationService = authenticationService;
 }
 public ExtendedUserSession(IHttpContextAccessor httpContextAccessor, IAuthenticationSchemeProvider schemes,
                            IAuthenticationHandlerProvider handlers, IdentityServerOptions options, ISystemClock clock,
                            ILogger <IUserSession> logger, IDistributedCache redisCache) : base(httpContextAccessor,
                                                                                                handlers, options, clock, logger)
 {
     _httpContextAccessor = httpContextAccessor;
     _logger = logger;
     _cache  = redisCache;
 }
        /// <summary>
        /// 执行中间件
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task Invoke(HttpContext context)
        {
            using (var serviceScope = _ServiceProvider.CreateScope()) //手动高亮
            {
                _DbCotext = serviceScope.ServiceProvider.GetService <Oauth2DbContext>();

                context.Features.Set <IAuthenticationFeature>(new AuthenticationFeature
                {
                    OriginalPath     = context.Request.Path,
                    OriginalPathBase = context.Request.PathBase
                });


                IAuthenticationHandlerProvider handlers = context.RequestServices.GetRequiredService <IAuthenticationHandlerProvider>();
                foreach (AuthenticationScheme scheme in await Schemes.GetRequestHandlerSchemesAsync())
                {
                    var handler = await handlers.GetHandlerAsync(context, scheme.Name) as IAuthenticationRequestHandler;

                    if (handler != null && await handler.HandleRequestAsync())
                    {
                        return;
                    }
                }

                AuthenticationScheme defaultAuthenticate = await Schemes.GetDefaultAuthenticateSchemeAsync();

                if (defaultAuthenticate != null)
                {
                    AuthenticateResult result = await context.AuthenticateAsync(defaultAuthenticate.Name);

                    if (result?.Principal != null)
                    {
                        context.User = result.Principal;
                    }
                }

                if (!context.Request.Path.Equals(_TokenOptions.Path, StringComparison.OrdinalIgnoreCase))
                {
                    await _Next(context);

                    return;
                }

                // Request must be POST with Content-Type: application/x-www-form-urlencoded
                if (!context.Request.Method.Equals("POST", StringComparison.OrdinalIgnoreCase) ||
                    !context.Request.HasFormContentType)
                {
                    await ReturnBadRequest(context);

                    return;
                }

                //返回Token
                await GenerateAuthorizedResult(context);
            }
        }
 public AuthenticationTestingController(IAuthenticationSchemeProvider schemes,
                                        IAuthenticationHandlerProvider handlers,
                                        IOptionsMonitor <CookieAuthenticationOptions> options,
                                        ISystemClock clock)
 {
     _schemes  = schemes;
     _handlers = handlers;
     _options  = options;
     _clock    = clock;
 }
Exemple #12
0
 public ProfileController(ILogger <HomeController> logger, IAuthenticationSchemeProvider schemes,
                          IAuthenticationHandlerProvider handlerProvider, IAuthenticationService authenticationService,
                          IHttpClientFactory clientFactory)
 {
     _logger                = logger;
     _schemes               = schemes;
     _handlerProvider       = handlerProvider;
     _authenticationService = authenticationService;
     _clientFactory         = clientFactory;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="next"></param>
 /// <param name="tenantConfiguration"></param>
 /// <param name="hostingEnvironment"></param>
 /// <param name="handlerProvider"></param>
 public AuthContextMiddleware(
     RequestDelegate next,
     ITenantConfiguration tenantConfiguration,
     IHostingEnvironment hostingEnvironment,
     IAuthenticationHandlerProvider handlerProvider)
 {
     _next = next;
     _tenantConfiguration = tenantConfiguration;
     _hostingEnvironment  = hostingEnvironment;
     _handlerProvider     = handlerProvider;
 }
Exemple #14
0
 public AccountController(UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, ILoggerFactory loggerFactory, IIdentityServerInteractionService interactionService, ApplicationDbContext dbContext, IStringLocalizerFactory localizerFactory, IDistributedCache distributedCache, ISmsSender smsSender, IAuthenticationHandlerProvider authenticationHandlerProvider)
 {
     _userManager                   = userManager;
     _signInManager                 = signInManager;
     _logger                        = loggerFactory.CreateLogger <AccountController>();
     _interactionService            = interactionService;
     _dbContext                     = dbContext;
     _localizerFactory              = localizerFactory;
     _distributedCache              = distributedCache;
     _smsSender                     = smsSender;
     _authenticationHandlerProvider = authenticationHandlerProvider;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultUserSession"/> class.
 /// </summary>
 /// <param name="httpContextAccessor">The HTTP context accessor.</param>
 /// <param name="handlers">The handlers.</param>
 /// <param name="options">The options.</param>
 /// <param name="clock">The clock.</param>
 /// <param name="logger">The logger.</param>
 public DefaultUserSession(
     IHttpContextAccessor httpContextAccessor,
     IAuthenticationHandlerProvider handlers,
     IdentityServerOptions options,
     ISystemClock clock,
     ILogger <IUserSession> logger)
 {
     HttpContextAccessor = httpContextAccessor;
     Handlers            = handlers;
     Options             = options;
     Clock  = clock;
     Logger = logger;
 }
Exemple #16
0
 public IdentityServerAuthenticationService(
     IAuthenticationSchemeProvider schemes,
     IAuthenticationHandlerProvider handlers,
     IClaimsTransformation transform,
     IdentityServerOptions options,
     IUserSession session,
     ILogger <IdentityServerAuthenticationService> logger)
     : base(schemes, handlers, transform)
 {
     _options = options;
     _session = session;
     _logger  = logger;
 }
Exemple #17
0
 public DefaultUserSession(
     IHttpContextAccessor httpContextAccessor,
     IAuthenticationSchemeProvider schemes,
     IAuthenticationHandlerProvider handlers,
     IdentityServerOptions options,
     ILogger <IUserSession> logger)
 {
     _httpContextAccessor = httpContextAccessor;
     _schemes             = schemes;
     _handlers            = handlers;
     _options             = options;
     _logger = logger;
 }
Exemple #18
0
 /// <summary>
 /// Creates a new instance of <see cref="SharedUserSession"/>.
 /// </summary>
 /// <param name="httpContextAccessor">The http context accessor.</param>
 /// <param name="schemes">The schemes provider.</param>
 /// <param name="handlers">The authentication handler provider.</param>
 /// <param name="options">The anonymous options.</param>
 /// <param name="clock">The system of clock.</param>
 public SharedUserSession(
     IHttpContextAccessor httpContextAccessor,
     IAuthenticationSchemeProvider schemes,
     IAuthenticationHandlerProvider handlers,
     AnonymousIdentityServerOptions options,
     ISystemClock clock)
 {
     _schemes                = schemes;
     _handlers               = handlers;
     _options                = options;
     _clock                  = clock;
     _httpContextAccessor    = httpContextAccessor;
     _checkSessionCookieName = _options.CheckSharedSessionCookieName;
 }
 public IdentityServerAuthenticationService(
     Decorator <IAuthenticationService> decorator,
     IAuthenticationSchemeProvider schemes,
     IAuthenticationHandlerProvider handlers,
     IClaimsTransformation transform,
     IdentityServerOptions options,
     IUserSession session,
     ILogger <IdentityServerAuthenticationService> logger)
 {
     _inner   = decorator.Instance;
     _schemes = schemes;
     _options = options;
     _session = session;
     _logger  = logger;
 }
Exemple #20
0
        /// <summary>
        /// Authtication中间件解析
        /// 处理流程如下:
        /// 先获取IAuthenticationHandlerProvider对象用于获取所有注册的认证处理器
        /// 然后根据IAuthenticationSchemeProvider获取所有注册的认证处理器对应的名称。处理器,以及显示名称
        /// AuthenticationScheme :HandlerType ,DisplayName,Name(Authenticationscheme)
        /// 然后根据IAuthenticationSchemeProvider中获取的认证处理器。通过名称逐个获取HandlerType进行检查,如果该处理器是实现了IAuthenticationRequestHandler的处理器。
        /// 则让该处理器尝试接管该请求。一旦实现了IAuthenticationRequestHandler的处理器的HandleRequestAsync()方法返回true。则会导致认证过程结束。
        /// 如果没有,则获取默认认证模式的处理器。让其接管认证请求。并设置HttpContext.User属性值。至此。认证结束。
        /// </summary>
        static async void Scheme()
        {
            var services = new ServiceCollection();

            //AddAuthentication
            //services.TryAddScoped<IAuthenticationHandlerProvider, AuthenticationHandlerProvider>();
            //services.TryAddSingleton<IAuthenticationSchemeProvider, AuthenticationSchemeProvider>();
            services.AddAuthentication("cookie")
            .AddCookie("cookie")
            .AddCookie("auth1")
            ;
            IServiceProvider serviceProvider = services.BuildServiceProvider();
            IAuthenticationSchemeProvider  schemeProvider  = serviceProvider.GetService <IAuthenticationSchemeProvider>();
            IAuthenticationHandlerProvider handlerProvider = serviceProvider.GetService <IAuthenticationHandlerProvider>();
            var sechemes = await schemeProvider.GetAllSchemesAsync();

            foreach (var item in sechemes)
            {
                Console.WriteLine(item.DisplayName + "\t" + item.Name + "\t" + item.HandlerType.FullName);
            }
        }
        public async Task Invoke(HttpContext context)
        {
            context.Features.Set <IAuthenticationFeature>(new AuthenticationFeature
            {
                OriginalPath     = context.Request.Path,
                OriginalPathBase = context.Request.PathBase
            });

            IAuthenticationHandlerProvider handlers = context.RequestServices.GetRequiredService <IAuthenticationHandlerProvider>();

            foreach (AuthenticationScheme scheme in await _authenticationSchemeProvider.GetRequestHandlerSchemesAsync())
            {
                if (await handlers.GetHandlerAsync(context, scheme.Name) is IAuthenticationRequestHandler handler &&
                    await handler.HandleRequestAsync())
                {
                    return;
                }
            }

            AuthenticationScheme defaultAuthenticate = await _authenticationSchemeProvider.GetDefaultAuthenticateSchemeAsync();

            if (defaultAuthenticate != null)
            {
                AuthenticateResult result = await context.AuthenticateAsync(defaultAuthenticate.Name);

                if (result?.Principal != null)
                {
                    context.User = result.Principal;
                }
            }

            try
            {
                await _next(context);
            }
            finally
            {
                //
            }
        }
 public AccountController(
     IIdentityServerInteractionService interaction,
     IClientStore clientStore,
     IAuthenticationSchemeProvider schemeProvider,
     IEventService events,
     UserManager <IdentityUser> userManager,
     SignInManager <IdentityUser> signInManager,
     IEmailSender emailSender,
     IProfilesApi profilesApi,
     IDefaultClientProvider defaultClientProvider,
     IAuthenticationHandlerProvider handlerProvider)
 {
     this.userManager           = userManager;
     this.signInManager         = signInManager;
     this.emailSender           = emailSender;
     this.profilesApi           = profilesApi;
     this.defaultClientProvider = defaultClientProvider;
     this.interaction           = interaction;
     this.clientStore           = clientStore;
     this.schemeProvider        = schemeProvider;
     this.events          = events;
     this.handlerProvider = handlerProvider;
 }
Exemple #23
0
        public async Task Invoke(HttpContext context)
        {
            context.Features.Set <IAuthenticationFeature>((IAuthenticationFeature) new AuthenticationFeature()
            {
                OriginalPath     = context.Request.Path,
                OriginalPathBase = context.Request.PathBase
            });
            IAuthenticationHandlerProvider handlers = context.RequestServices.GetRequiredService <IAuthenticationHandlerProvider>();

            foreach (AuthenticationScheme authenticationScheme in await this.Schemes.GetRequestHandlerSchemesAsync())
            {
                IAuthenticationRequestHandler handlerAsync = await handlers.GetHandlerAsync(context, authenticationScheme.Name) as IAuthenticationRequestHandler;

                bool flag = handlerAsync != null;
                if (flag)
                {
                    flag = await handlerAsync.HandleRequestAsync();
                }
                if (flag)
                {
                    return;
                }
            }
            AuthenticationScheme authenticateSchemeAsync = await this.Schemes.GetDefaultAuthenticateSchemeAsync();

            if (authenticateSchemeAsync != null)
            {
                AuthenticateResult authenticateResult = await context.AuthenticateAsync(authenticateSchemeAsync.Name);

                if (authenticateResult?.Principal != null)
                {
                    context.User = authenticateResult.Principal;
                }
            }
            await this._next(context);
        }
 public AuthenticationServiceWithFallback(IAuthenticationSchemeProvider schemes, IAuthenticationHandlerProvider handlers, IClaimsTransformation transform) : base(schemes, handlers, transform)
 {
 }
Exemple #25
0
 public AuthenticationHandlersMiddleware(RequestDelegate next, IAuthenticationSchemeProvider schemes, IAuthenticationHandlerProvider handlers)
 {
     _next     = next;
     _schemes  = schemes;
     _handlers = handlers;
 }
Exemple #26
0
 public MultiTenantAuthenticationService(IAuthenticationSchemeProvider schemes, IAuthenticationHandlerProvider handlers, IClaimsTransformation transform) : base(schemes, handlers, transform)
 {
 }
Exemple #27
0
 public AuthorizeAttributeTrackingFilter(IAuthenticationHandlerProvider authenticationHandlerProvider)
 {
     _authenticationHandlerProvider = authenticationHandlerProvider;
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="schemes">The <see cref="IAuthenticationSchemeProvider"/>.</param>
 /// <param name="handlers">The <see cref="IAuthenticationRequestHandler"/>.</param>
 /// <param name="transform">The <see cref="IClaimsTransformation"/>.</param>
 public AuthenticationService(IAuthenticationSchemeProvider schemes, IAuthenticationHandlerProvider handlers, IClaimsTransformation transform)
 {
     Schemes   = schemes;
     Handlers  = handlers;
     Transform = transform;
 }
Exemple #29
0
 public override Task OnActivateAsync()
 {
     this.Handlers = base.ServiceProvider.GetRequiredService <IAuthenticationHandlerProvider>();
     return(base.OnActivateAsync());
 }
        public AuthenticationService(IUserAccessor userAccessor, IAuthenticationSchemeProvider schemes, IAuthenticationHandlerProvider handlers, IClaimsTransformation transform, IOptions <AuthenticationOptions> options, ILogger <AuthenticationService> logger)
            : base(schemes, handlers, transform, options)
        {
            _logger = logger;

            var accessorType = userAccessor.GetType();

            if (!typeof(DefaultUserAccessor).IsAssignableFrom(accessorType))
            {
                throw new InvalidOperationException("Feed.Web.Services.AuthenticationService::ctr() -- Unsuported IUserAccessor implementation: " + accessorType);
            }

            _userAccessor = (DefaultUserAccessor)userAccessor;
        }