コード例 #1
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            bool result = true;

            if (!context.HttpContext.Request.Headers.TryGetValue("Authorization", out var JWTTokenValue))
            {
                context.ModelState.AddModelError("Unauthorized", "Authorization value false");
                result = false;
            }

            if (result)
            {
                try
                {
                    IJWTTokenManager jwtTokenManger = context.HttpContext.RequestServices.GetRequiredService <IJWTTokenManager>();
                    var claimPrinciple = jwtTokenManger.VerifyToken(JWTTokenValue);
                }
                catch (Exception ex)
                {
                    context.ModelState.AddModelError("Unathorized", ex.Message);
                    result = false;
                }
            }

            if (!result)
            {
                context.Result = new UnauthorizedObjectResult(context.ModelState);
            }
        }
 public BasicAuthorization()
 {
     tokenManager = new JWTTokenManager();
 }
コード例 #3
0
 public AuthenticateController(ITokenManager tokenManager, IJWTTokenManager jwtTokenManager)
 {
     this.tokenManager    = tokenManager;
     this.jwtTokenManager = jwtTokenManager;
 }
 public JWTTokenAuthentication()
 {
     tokenManager = new JWTTokenManager();
 }
コード例 #5
0
 public UserService(IUserInformationRepository userInformationRepository, IJWTTokenManager jwtTokenManager)
 {
     _userInformationRepo = userInformationRepository;
     _jwtTokenManager     = jwtTokenManager;
 }