public ApiTokenAuthenticationHandler(IOptionsMonitor <AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, IConfiguration configuration, JwtSecurityTokenHandler tokenHandler, IHttpClientFactory httpClientFactory, AuthCacheService authCache) : base(options, logger, encoder, clock) { CookieName ??= configuration[$"Api:{Utilities.CurrentRegion.ToRegionString()}:CookieName"]; CookieDomain ??= configuration[$"Api:{Utilities.CurrentRegion.ToRegionString()}:CookieDomain"]; loginPath ??= configuration[$"Api:{Utilities.CurrentRegion.ToRegionString()}:Login"]; websitePath ??= configuration[$"Api:{Utilities.CurrentRegion.ToRegionString()}:WebDomain"]; this.tokenHandler = tokenHandler; _authCache = authCache; httpClient = httpClientFactory.CreateClient(); }
public void CheckMethodShouldReturnDataIfUsernameIsValid() { var prefixKey = "AuthCache"; var service = new AuthCacheService(prefixKey); var newUser = new UserDTO { Id = Guid.NewGuid(), Username = "******", Role = UserRole.Admin }; service.SignIn(newUser); var memoryUserData = service.Check(newUser.Username); memoryUserData.Username.ShouldBe(newUser.Username); memoryUserData.Role.ToString().ShouldBe(newUser.Role.ToString()); memoryUserData.Id.ShouldBe(newUser.Id); }
public void MemoryCacheMustHaveDataAfterSignIn() { var prefixKey = "AuthCache"; var service = new AuthCacheService(prefixKey); var newUser = new UserDTO { Id = Guid.NewGuid(), Username = "******", Role = UserRole.Admin }; service.SignIn(newUser); var key = prefixKey + "_" + newUser.Username; MemoryCache.Default.Contains(key.ToLower()).ShouldBeTrue(); var memoryUserData = MemoryCache.Default[key.ToLower()] as UserDTO; memoryUserData.Username.ShouldBe(newUser.Username); memoryUserData.Role.ToString().ShouldBe(newUser.Role.ToString()); memoryUserData.Id.ToString().ShouldBe(newUser.Id.ToString()); }