Пример #1
0
 public override void Init()
 {
     _userInfoService = new UserAuthService();
     //PostAuthenticateRequest += new EventHandler(MvcApplication_PostAuthenticateRequest);
     AuthenticateRequest += new EventHandler(MvcApplication_AuthenticateRequest);
     base.Init();
 }
Пример #2
0
 public JwtService(IUserRefreshTokenRepository refreshRepository, IProfileService profileService, IUserAuthService userService, IConfiguration configuration)
 {
     this.refreshRepository = refreshRepository;
     this.profileService    = profileService;
     this.userService       = userService;
     this.configuration     = configuration;
 }
Пример #3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public UserController(IUserRepository users, IUserAuthService authService, ILogger logger)
     : base(authService, logger)
 {
     _openId = new OpenIdRelyingParty();
     _logger = logger;
     _users = users;
 }
        public async Task When_CredentialsAreValid_Should_ReturnAuthenticationResult_With_SuccessCodeAndUser()
        {
            IUserAuthService service = await CreateMockService();

            var authenticationResult = await service.AuthenticateAsync(CorrectUsername, CorrectPassword);

            Assert.AreEqual(AuthenticationResultCode.Success, authenticationResult.Code);
            Assert.IsNotNull(authenticationResult.User);
        }
        public async Task When_PasswordMismatches_Should_ReturnAuthenticationResult_With_InvalidCredentialsCode()
        {
            IUserAuthService service = await CreateMockService();

            var authenticationResult = await service.AuthenticateAsync(CorrectUsername, IncorrectPassword);

            Assert.AreEqual(AuthenticationResultCode.InvalidCredentials, authenticationResult.Code);
            Assert.IsNull(authenticationResult.User);
        }
Пример #6
0
 public BasicAuthenticationHandler(
     IOptionsMonitor <AuthenticationSchemeOptions> options,
     ILoggerFactory logger,
     UrlEncoder encoder,
     ISystemClock clock,
     IUserAuthService authService)
     : base(options, logger, encoder, clock)
 {
     this.authService = authService;
 }
        public async Task Invoke(HttpContext context, IUserAuthService userService)
        {
            var accessToken  = context.Request.Headers["Authorization"].FirstOrDefault()?.Split(" ").Last();
            var refreshToken = context.Request.Headers["Refresh"].FirstOrDefault()?.Split(" ").Last();

            if (accessToken != null)
            {
                AttachUserToContext(context, userService, accessToken, refreshToken);
            }

            await _next(context);
        }
        private void AttachUserToContext(HttpContext context, IUserAuthService userService, string accessToken, string refreshToken)
        {
            try
            {
                var tokenHandler = new JwtSecurityTokenHandler();
                var key          = Encoding.ASCII.GetBytes(_appSettings.Secret);
                tokenHandler.ValidateToken(accessToken, new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false,
                    // set clockskew to zero so tokens expire exactly at token expiration time (instead of 5 minutes later)
                    ClockSkew = TimeSpan.Zero
                }, out SecurityToken validatedToken);

                var jwtToken = (JwtSecurityToken)validatedToken;
                var userId   = int.Parse(jwtToken.Claims.First(x => x.Type == "id").Value);

                // attach user to context on successful jwt validation
                context.Items["User"] = userService.GetById(userId);
            }
            catch
            {
                try
                {
                    var tokenHandler = new JwtSecurityTokenHandler();
                    var key          = Encoding.ASCII.GetBytes(_appSettings.Secret);
                    tokenHandler.ValidateToken(refreshToken, new TokenValidationParameters
                    {
                        ValidateIssuerSigningKey = true,
                        IssuerSigningKey         = new SymmetricSecurityKey(key),
                        ValidateIssuer           = false,
                        ValidateAudience         = false,
                        // set clockskew to zero so tokens expire exactly at token expiration time (instead of 5 minutes later)
                        ClockSkew = TimeSpan.Zero
                    }, out SecurityToken validatedToken);

                    var jwtToken = (JwtSecurityToken)validatedToken;
                    var userId   = int.Parse(jwtToken.Claims.First(x => x.Type == "id").Value);

                    // attach user to context on successful jwt validation
                    context.Items["User"] = userService.GetById(userId);
                }
                catch
                {
                    // do nothing if jwt validation fails
                    // user is not attached to context so request won't have access to secure routes
                }
            }
        }
 public UsersController(ILogger <UsersController> log,
                        IMapper mapper,
                        IUserData userData,
                        IUserService userService,
                        IUserAuthService userAuthService,
                        SmtpSettings smtpSettings)
 {
     _log             = log;
     _userData        = userData;
     _userService     = userService;
     _userAuthService = userAuthService;
     _mapper          = mapper;
     _smtpSettings    = smtpSettings;
 }
 public AuthorizationController(
     IUserAuthService authService,
     IMapper mapper,
     IConfiguration config,
     ITokenGeneratorService jwtTokenGenerator,
     IOptions <JwtTokenSecretKey> secret,
     IOptions <JwtTokenOptions> options,
     DashboardDbContext context,
     IOptions <MainUserData> optionsMainUser
     )
 {
     _authService       = authService;
     _mapper            = mapper;
     _config            = config;
     _jwtTokenGenerator = jwtTokenGenerator;
     _context           = context;
     _optionsMainUser   = optionsMainUser;
     _jwtTokenSecretKey = secret.Value.jwtTokenSecretKey;
     _issuer            = options.Value.issuer;
     _audience          = options.Value.audience;
 }
Пример #11
0
 public LoginCommandHandler(IAuthTokenGenerator authTokenGenerator, IRoleService roleService, IUserAuthService userAuthService)
 {
     _authTokenGenerator = authTokenGenerator;
     _roleService        = roleService;
     _userAuthService    = userAuthService;
 }
Пример #12
0
 public UsersController(IUserAuthService _userAuthService)
 {
     this._userAuthService = _userAuthService;
 }
Пример #13
0
 public AccountController(IAuthManager authRepository, IUserAuthService userAuthService, IErrorMessageService errorMessageService)
 {
     _errorMessageService = errorMessageService;
     _userAuthService     = userAuthService;
     _authManager         = authRepository;
 }
 public LogAdminRequestFilter(IUserAuthService userAuthService)
 {
     this.userAuthService = userAuthService;
 }
 public GamDroidDbService(gamdroidContext context, IUserAuthService userAuthService)
 {
     _context         = context;
     _userAuthService = userAuthService;
 }
 public UserController(IUserAuthService userAuthService, IUserQueryProcessor userQueryProcessor)
 {
     _userAuthService    = userAuthService;
     _userQueryProcessor = userQueryProcessor;
 }
Пример #17
0
 public AuthenticationService(IUserAuthService userAuthService, NavigationManager navigationManager)
 {
     _userAuthService   = userAuthService;
     _navigationManager = navigationManager;
 }
Пример #18
0
 public AuthController(IUserAuthService userAuthService, IMapper mapper, IOptions <AppSettings> appSettings)
 {
     _mapper          = mapper;
     _userAuthService = userAuthService;
     _appSettings     = appSettings.Value;
 }
Пример #19
0
 public UserAuthController(ILoginInfo loginInfo, IUserAuthService UserAuthService)
 {
     _service = UserAuthService;
 }
Пример #20
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="userAuthService"></param>
 protected BaseController(IUserAuthService userAuthService,ILogger logger)
 {
     UserAuthService = userAuthService;
     Logger = logger;
 }
 public AuthController(IUserAuthService authService)
 {
     this._authService = authService;
 }
Пример #22
0
 public UsersController(IUserAuthService userAuthService, IImageFileReader imageFileReader, IImageDataHelper imageDataHelper)
 {
     _userAuthService = userAuthService;
     _imageFileReader = imageFileReader;
     _imageDataHelper = imageDataHelper;
 }
Пример #23
0
 public UserController(IssuesDBContext db, IUserAuthService userAuth, IMapper mapper)
 {
     this.db       = db;
     this.userAuth = userAuth;
     this.mapper   = mapper;
 }
Пример #24
0
 public UserService(IUserAuthService userAuthService)
 {
     _userAuthService = userAuthService;
 }
Пример #25
0
 public UserAuthController(IUserAuthService userAuthService)
 {
     _userAuthService = userAuthService;
 }
Пример #26
0
 public LoginController(IUserAuthService userAuthService, IUsersService userService)
 {
     _userAuthService = userAuthService;
     _usersService    = userService;
 }
Пример #27
0
 public AuthManager(IUserAuthService userAuthService, ITokenHelper tokenHelper)
 {
     _userAuthService = userAuthService;
     _tokenHelper     = tokenHelper;
 }
Пример #28
0
 public UserAuthsController(IUserAuthService userAuthService, IAuthService authService)
 {
     _userAuthService = userAuthService;
     _authService     = authService;
 }
Пример #29
0
 public AuthController(JwtTokenGenerator jwtTokenGenerator, IUserAuthService userAuthService)
 {
     _jwtTokenGenerator = jwtTokenGenerator;
     _userAuthService   = userAuthService;
 }
Пример #30
0
 public AuthController(IJwtService jwt, IUserAuthService service)
 {
     jwtService  = jwt;
     userService = service;
 }
Пример #31
0
 public BlueprintController(IBlueprintRepository blueprints,IUserAuthService authService,ILogger logger)
     : base(authService,logger)
 {
     _blueprints = blueprints;
 }
Пример #32
0
 public ScheduledActionsController(IPlantScheduledActionService scheduledActionService, IUserAuthService userAuthService)
 {
     _scheduledActionService = scheduledActionService;
     _userAuthService        = userAuthService;
 }
Пример #33
0
 public ChangePasswordHandler(IBudgetDbContext context, IUserAuthService userAuthService, IPasswordService passService)
 {
     _context         = context;
     _userAuthService = userAuthService;
     _passService     = passService;
 }
Пример #34
0
 public UsersController(IUsersService usersService, IUserAuthService usersAuthService)
 {
     _usersService     = usersService;
     _usersAuthService = usersAuthService;
 }