Esempio n. 1
0
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            bool allowAnonymous = context.ActionDescriptor.EndpointMetadata
                                  .Any(em => em.GetType() == typeof(AllowAnonymousAttribute));

            if (allowAnonymous) // skip authorization if allow anonymous attribute is used
            {
                return;
            }

            JwtLogic jwtLogic      = (JwtLogic)context.HttpContext.RequestServices.GetService(typeof(JwtLogic));
            string   authorization = context.HttpContext.Request.Headers[RequestHeaders.Authorization];

            if (string.IsNullOrEmpty(authorization))
            {
                context.Result = new UnauthorizedResult();
                base.OnActionExecuting(context);
                return;
            }

            string jwt = authorization.Replace("Bearer ", "");

            var role = jwtLogic.GetClaim <AccountRole>(jwt, JwtClaim.AccountRole);

            if (!_requiredRoles.Contains(role))
            {
                context.Result = new UnauthorizedResult();
            }

            base.OnActionExecuting(context);
        }
Esempio n. 2
0
        public MockedJwtLogic()
        {
            var mockedRefreshTokenDal = new MockedRefreshTokenDal();
            var jwtConfig             = new MockedJwtConfig().JwtConfig;

            JwtLogic = new JwtLogic(mockedRefreshTokenDal.Mock, jwtConfig);
        }
 public AuthenticationController(AuthenticationLogic authorizationLogic, LogLogic logLogic, JwtLogic jwtLogic,
                                 ControllerHelper controllerHelper)
 {
     _authorizationLogic = authorizationLogic;
     _logLogic           = logLogic;
     _jwtLogic           = jwtLogic;
     _controllerHelper   = controllerHelper;
 }
Esempio n. 4
0
 public ControllerHelper(JwtLogic jwtLogic)
 {
     _jwtLogic = jwtLogic;
 }
Esempio n. 5
0
 public JwtLogicTest()
 {
     _jwtLogic = new JwtLogic();
 }
Esempio n. 6
0
        public MockedJwtLogic()
        {
            var jwtLogic = new JwtLogic();

            JwtLogic = jwtLogic;
        }
Esempio n. 7
0
 public JwtLogicTest()
 {
     _jwtLogic = new MockedJwtLogic().JwtLogic;
 }