Beispiel #1
0
        public JwtFactory(IJwtTokenHandler jwtTokenHandler, IOptions <JwtIssuerOptions> jwtIssuerOptions)
        {
            if (jwtIssuerOptions == null)
            {
                throw new ArgumentNullException(nameof(jwtIssuerOptions));
            }

            _jwtTokenHandler  = jwtTokenHandler ?? throw new ArgumentNullException(nameof(jwtTokenHandler));
            _jwtIssuerOptions = jwtIssuerOptions.Value;

            if (_jwtIssuerOptions.ValidFor <= TimeSpan.Zero)
            {
                throw new ArgumentException("Must be a non-zero TimeSpan.", nameof(JwtIssuerOptions.ValidFor));
            }

            if (_jwtIssuerOptions.SigningCredentials == null)
            {
                throw new ArgumentNullException(nameof(JwtIssuerOptions.SigningCredentials));
            }

            if (_jwtIssuerOptions.JtiGenerator == null)
            {
                throw new ArgumentNullException(nameof(JwtIssuerOptions.JtiGenerator));
            }
        }
Beispiel #2
0
 public RequestValidator(IDeviceManagement deviceManagement, IUserManagement userManagement, IVehicleManagement vehicleManagement, IJwtTokenHandler tokenHandler)
 {
     _deviceManagement  = deviceManagement;
     _userManagement    = userManagement;
     _vehicleManagement = vehicleManagement;
     _tokenHandler      = tokenHandler;
 }
Beispiel #3
0
 public AuthController(IJwtTokenHandler jwtTokenHandler, IRefreshTokenManager refreshTokenManager, ILogger <AuthController> logger, IMapper mapper) : base(logger)
 {
     _refreshTokenManager = refreshTokenManager;
     _jwtTokenHandler     = jwtTokenHandler;
     _logger = logger;
     _mapper = mapper;
 }
 public AuthenticationService(IUserServiceClient serviceClient,
                              IJwtTokenHandler jwtTokenHandler, JwtTokenSettings jwtTokenSettings)
 {
     _serviceClient    = serviceClient;
     _jwtTokenHandler  = jwtTokenHandler;
     _jwtTokenSettings = jwtTokenSettings;
 }
Beispiel #5
0
        public JwtFactory(IJwtTokenHandler jwtTokenHandler, IOptions <JwtIssuerOptions> jwtOptions)
        {
            _jwtTokenHandler = jwtTokenHandler;
            _jwtOptions      = jwtOptions.Value;

            ThrowIfInvalidOptions(_jwtOptions);
        }
Beispiel #6
0
 public JwtFactory(IJwtTokenHandler jwtTokenHandler, JwtIssuerOptions jwtOptions, UserManager userManager, IUnitOfWorkManager unitOfWorkManager)
 {
     _jwtTokenHandler   = jwtTokenHandler;
     _jwtOptions        = jwtOptions;
     _userManager       = userManager;
     _unitOfWorkManager = unitOfWorkManager;
 }
 public AuthenticationService(IJwtTokenHandler jwtTokenHandler,
                              IEncrypter encrypter,
                              IUserRepository userRepository)
 {
     _jwtTokenHandler = jwtTokenHandler;
     _encrypter       = encrypter;
     _userRepository  = userRepository;
 }
Beispiel #8
0
 public UsersController(UserManager <IdentityUser> userManager, IJwtTokenHandler jwtTokenHandler, IRefreshTokenManager refreshTokenManager, ILogger <UsersController> logger, IMapper mapper) : base(logger)
 {
     _jwtTokenHandler      = jwtTokenHandler;
     _logger               = logger;
     _userManager          = userManager;
     _mapper               = mapper;
     _refreshTokenMananger = refreshTokenManager;
 }
Beispiel #9
0
 public ServiceAuthenticatorHost(IJwtTokenHandler jwtTokenHandler,
                                 JwtTokenSettings jwtTokenSettings,
                                 ServiceSettings serviceSettings)
 {
     _jwtTokenHandler  = jwtTokenHandler;
     _jwtTokenSettings = jwtTokenSettings;
     _serviceSettings  = serviceSettings;
 }
Beispiel #10
0
 public JwtFactory(IJwtTokenHandler jwtTokenHandler, IOptions <JwtIssuerOptions> jwtOptions,
                   UserManager <AppUser> userManager, RoleManager <AppRole> roleManager)
 {
     this.jwtTokenHandler = jwtTokenHandler;
     this.userManager     = userManager;
     this.roleManager     = roleManager;
     this.jwtOptions      = jwtOptions.Value;
     ThrowIfInvalidOptions(this.jwtOptions);
 }
Beispiel #11
0
 public JwtFactory(
     IOptions <JwtIssuerOptions> jwtOptions,
     IJwtTokenHandler jwtHandler
     )
 {
     _jwtOptions     = jwtOptions.Value;
     this.jwtHandler = jwtHandler;
     ThrowIfInvalidOptions(_jwtOptions);
 }
Beispiel #12
0
 public JwtFactory(
     IJwtTokenHandler jwtTokenHandler,
     IConfiguration configuration
     )
 {
     _configuration  = configuration;
     _jwtTokenHelper = new JwtTokenHelper();
     _jwtOptions     = new JwtOptions();
 }
Beispiel #13
0
 public UserManagement(IUnitOfWork unitOfWork, IRepository <UserType> repository, IRepository <User> userRepository, IMapper mapper, IJwtTokenHandler jwtTokenHandler, ICryptographyHandler cryptographyHandler, IErrorMapper errorMapper)
 {
     _unitOfWork          = unitOfWork;
     _repository          = repository;
     _userRepository      = userRepository;
     _mapper              = mapper;
     _jwtTokenHandler     = jwtTokenHandler;
     _cryptographyHandler = cryptographyHandler;
     _errorMapper         = errorMapper;
 }
 public AuthenticationService(ILogger <AuthenticationService> logger,
                              IUserRepository userRepository, IUserSessionRepository userSessionRepository,
                              IJwtTokenHandler jwtTokenHandler, IEncrypter encrypter)
 {
     _logger                = logger.CheckIfNotEmpty();
     _userRepository        = userRepository.CheckIfNotEmpty();
     _userSessionRepository = userSessionRepository.CheckIfNotEmpty();
     _encrypter             = encrypter.CheckIfNotEmpty();
     _jwtTokenHandler       = jwtTokenHandler.CheckIfNotEmpty();
 }
 public JwtFactory(IJwtTokenHandler jwtTokenHandler,
                   UserManager <User> userManager,
                   ISystemClock systemClock,
                   JwtSettings jwtSettings)
 {
     _jwtTokenHandler = jwtTokenHandler;
     _userManager     = userManager;
     _systemClock     = systemClock;
     ThrowIfInvalidOptions(jwtSettings);
     _jwtSettings = jwtSettings;
 }
        public AuthenticationModule(IServiceAuthenticatorHost serviceAuthenticatorHost,
                                    IAuthenticationService authenticationService,
                                    IUserService userService,
                                    IJwtTokenHandler jwtTokenHandler,
                                    ICommandHandler <SignIn> signInHandler,
                                    ICommandHandler <RefreshUserSession> refreshSessionHandler)
            : base(requireAuthentication: false)
        {
            _authenticationService = authenticationService;
            _userService           = userService;
            _jwtTokenHandler       = jwtTokenHandler;

            Post("authenticate", args =>
            {
                var credentials = BindRequest <Credentials>();
                var token       = serviceAuthenticatorHost.CreateToken(credentials);
                if (token.HasNoValue)
                {
                    return(HttpStatusCode.Unauthorized);
                }

                return(token.Value);
            });

            Post("sign-in", async args =>
            {
                var command = BindRequest <SignIn>();
                await signInHandler.HandleAsync(command);
                var session = await HandleSessionAsync(command.SessionId);
                if (session.HasNoValue)
                {
                    return(HttpStatusCode.Unauthorized);
                }

                return(session.Value);
            });

            Post("sessions", async args =>
            {
                var command = BindRequest <RefreshUserSession>();
                await refreshSessionHandler.HandleAsync(command);
                var session = await HandleSessionAsync(command.NewSessionId);
                if (session.HasNoValue)
                {
                    return(HttpStatusCode.Forbidden);
                }

                return(session.Value);
            });
        }
 public UserAppService(IUserRepository userRepository,
                       IJwtTokenHandler jwtTokenHandler,
                       IHashString hashString,
                       IMediatorHandler bus,
                       IMapper mapper,
                       ICacheManager cache)
 {
     _userRepository  = userRepository;
     _jwtTokenHandler = jwtTokenHandler;
     _hashString      = hashString;
     _bus             = bus;
     _mapper          = mapper;
     _cache           = cache;
 }
        public AuthenticationModule(IServiceAuthenticatorHost serviceAuthenticatorHost,
                                    IJwtTokenHandler jwtTokenHandler) : base(requireAuthentication: false)
        {
            Post("authenticate", args =>
            {
                var credentials = BindRequest <Credentials>();
                var token       = serviceAuthenticatorHost.CreateToken(credentials);
                if (token.HasNoValue)
                {
                    return(HttpStatusCode.Unauthorized);
                }

                return(token.Value);
            });
        }
        public JwtTokenFactory(
            IConfiguration config,
            IJwtTokenHandler jwtTokenHandler,
            ISettings settings)
        {
            _jwtTokenHandler = jwtTokenHandler ?? throw new ArgumentNullException(nameof(jwtTokenHandler));
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            _jwtIssuerOptions = settings.JwtIssuerOptions;
            _jwtOptions       = settings.JwtOptions;

            ThrowIfInvalidOptions(_jwtIssuerOptions);
        }
Beispiel #20
0
        public AuthenticationModule(ICommandDispatcher commandDispatcher,
                                    IValidatorResolver validatorResolver,
                                    IIdentityProvider identityProvider,
                                    IUserStorage userStorage,
                                    IOperationStorage operationStorage,
                                    IJwtTokenHandler jwtTokenHandler,
                                    JwtTokenSettings jwtTokenSettings)
            : base(commandDispatcher, validatorResolver, identityProvider, modulePath: "")
        {
            Post("sign-in", async(ctx, p) => await For <SignIn>()
                 .Set(c =>
            {
                c.IpAddress = Request.UserHostAddress;
                c.UserAgent = Request.Headers.UserAgent;
            })
                 .SetResourceId(c => c.SessionId)
                 .OnSuccess(async c =>
            {
                var operation = await operationStorage.GetUpdatedAsync(c.Request.Id);
                if (operation.HasNoValue || !operation.Value.Success)
                {
                    return(HttpStatusCode.Unauthorized);
                }

                var session = await userStorage.GetSessionAsync(c.SessionId);
                if (session.HasNoValue)
                {
                    return(HttpStatusCode.Unauthorized);
                }

                return(new
                {
                    token = jwtTokenHandler.Create(session.Value.UserId),
                    sessionId = session.Value.Id,
                    sessionKey = session.Value.Key,
                    expiry = DateTime.UtcNow.AddDays(jwtTokenSettings.ExpiryDays).ToTimestamp()
                });
            })
                 .DispatchAsync());

            Post("sign-up", async args => await For <SignUp>()
                 .OnSuccessAccepted("account")
                 .DispatchAsync());

            Post("sign-out", async args => await For <SignOut>()
                 .OnSuccess(HttpStatusCode.NoContent)
                 .DispatchAsync());
        }
        public AuthenticationModule(IJwtTokenHandler jwtTokenHandler)
            : base("auth", requireAuthentication: false)
        {
            Post("", async args =>
            {
                var request = this.BindRequest <SignIn>();
                var token   = jwtTokenHandler.Create("user1", "admin");
                await Task.CompletedTask;

                return(new
                {
                    token = token.Value.Token,
                    expires = token.Value.Expires
                });
            });
        }
Beispiel #22
0
        private static StatelessAuthenticationConfiguration Configuration(IJwtTokenHandler jwtTokenHandler)
        => new StatelessAuthenticationConfiguration(ctx =>
        {
            var authToken = jwtTokenHandler.GetFromAuthorizationHeader(ctx.Request.Headers.Authorization);
            if (authToken.HasNoValue)
            {
                return(null);
            }
            var jwt = jwtTokenHandler.Parse(authToken.Value);
            if (jwt.HasNoValue)
            {
                return(null);
            }
            var token = jwt.Value;

            return(jwt.HasValue ? new CollectivelyIdentity(token.Subject,
                                                           token.Role, token.State, token.Claims) : null);
        });
 public JwtTokenValidator(IJwtTokenHandler jwtTokenHandler) => _jwtTokenHandler = jwtTokenHandler;
Beispiel #24
0
 public static void SetupTokenAuthentication(this IPipelines pipelines, IJwtTokenHandler jwtTokenHandler)
 => StatelessAuthentication.Enable(pipelines, Configuration(jwtTokenHandler));
 internal JwtTokenValidator(IJwtTokenHandler jwtTokenHandler)
 {
     this.jwtTokenHandler = jwtTokenHandler;
 }
 public JwtTokenValidator(IJwtTokenHandler jwtTokenHandler)
 {
     this.jwtTokenHandler = jwtTokenHandler;
 }
 public LoginController(UserManager <EWUser> userManager, SignInManager <EWUser> signInManager, IJwtTokenHandler jwtTokenHandler)
 {
     _userManager     = userManager;
     _signInManager   = signInManager;
     _jwtTokenHandler = jwtTokenHandler;
 }
Beispiel #28
0
 public TokenController(IJwtTokenHandler jwtTokenHandler, IConfiguration configuration)
 {
     _jwtTokenHandler = jwtTokenHandler;
     _configuration   = configuration;
 }
 internal JwtFactory(IJwtTokenHandler jwtTokenHandler, IOptions <JwtOptions> jwtOptions)
 {
     this.jwtTokenHandler = jwtTokenHandler;
     this.jwtOptions      = jwtOptions.Value;
     ThrowIfInvalidOptions(this.jwtOptions);
 }
Beispiel #30
0
 public JwtFactory(IJwtTokenHandler jwtTokenHandler, IOptions <JwtIssuerOptions> jwtOptions)
 {
     _jwtTokenHandler = jwtTokenHandler;
     _jwtOptions      = jwtOptions.Value;
 }