public AuthenticationRequestHandlerWrapper(IAuthenticationRequestHandler inner, IHttpContextAccessor httpContextAccessor)
        {
            _inner   = inner;
            _context = httpContextAccessor.HttpContext;

            var factory = (ILoggerFactory)_context.RequestServices.GetService(typeof(ILoggerFactory));

            _logger = factory?.CreateLogger(GetType());
        }
Esempio n. 2
0
 public OAuthRevokeTokenContext(HttpContext context,
                                AuthenticationScheme scheme, OAuthSignOutOptions options,
                                AuthenticationProperties properties, AuthenticationToken token,
                                IAuthenticationRequestHandler oauthHandler)
     : base(context, scheme, options, properties)
 {
     Token        = token;
     OAuthHandler = oauthHandler;
 }
Esempio n. 3
0
        public OAuthSignOutContext(HttpContext context,
                                   AuthenticationScheme scheme, OAuthSignOutOptions options,
                                   AuthenticationProperties properties,
                                   IAuthenticationRequestHandler oauthHandler,
                                   AuthenticationTicket authTicket)
            : base(context, scheme, options, properties)
        {
            Principal = authTicket?.Principal ?? context?.User;
            Ticket    = authTicket;

            OAuthHandler = oauthHandler;
        }
Esempio n. 4
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);
        }
 internal static IAuthenticationRequestHandler GetInstance(TraktClient client)
 => s_requestHandler ?? (s_requestHandler = new AuthenticationRequestHandler(client));
Esempio n. 6
0
        protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, DefaultRequirement requirement)
        {
            AuthorizationFilterContext authorizationFilterContext = context.Resource as AuthorizationFilterContext;
            HttpContext httpContext = authorizationFilterContext.HttpContext;
            IAuthenticationHandlerProvider handlers = httpContext.RequestServices.GetRequiredService <IAuthenticationHandlerProvider>();

            foreach (AuthenticationScheme scheme in await _schemes.GetRequestHandlerSchemesAsync())
            {
                IAuthenticationRequestHandler handler = await handlers.GetHandlerAsync(httpContext, scheme.Name) as IAuthenticationRequestHandler;

                if (handler != null && await handler.HandleRequestAsync())
                {
                    context.Fail();
                    return;
                }
            }
            AuthenticationScheme defaultAuthenticate = await _schemes.GetDefaultAuthenticateSchemeAsync();

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

                if (result?.Principal != null)
                {
                    if (long.Parse(result.Principal.Claims.SingleOrDefault(s => s.Type == "exp").Value) < DateTime.Now.ToIntS())
                    {
                        authorizationFilterContext.Result = new JsonResult(new MessageResult
                        {
                            Msg    = ConifgMessage.TIMEOUT,
                            Status = false
                        })
                        {
                            StatusCode = 401
                        };
                    }
                    else
                    {
                        httpContext.User = result.Principal;
                        if (requirement.Validation != null)
                        {
                            AuthResult validMsg = requirement.Validation(httpContext);
                            if (!validMsg.IsValid)
                            {
                                authorizationFilterContext.Result = new JsonResult(new MessageResult
                                {
                                    Msg    = validMsg.Msg,
                                    Status = false
                                })
                                {
                                    StatusCode = 401
                                };
                            }
                        }
                    }
                }
                else
                {
                    authorizationFilterContext.Result = new JsonResult(new MessageResult
                    {
                        Msg    = ConifgMessage.NOTRIGHT,
                        Status = false
                    })
                    {
                        StatusCode = 401
                    };
                }
            }
            else
            {
                context.Fail();
                return;
            }
            context.Succeed(requirement);
        }