public void Arrange() { _configuration = new EmployerAccountsConfiguration { SupportConsoleUsers = SupportConsoleUsers }; _mockAuthenticationService = new Mock <IAuthenticationService>(); AuthorizationContextTestsFixture = new AuthorizationContextTestsFixture(); MockIAuthorisationResourceRepository = new Mock <IAuthorisationResourceRepository>(); Options = new List <string>(); _userContext = new UserContext(_mockAuthenticationService.Object, _configuration); SutDefaultAuthorizationHandler = new DefaultAuthorizationHandler(MockIAuthorisationResourceRepository.Object, _userContext); _testAuthorizationResource = new AuthorizationResource { Name = "Test", Value = Guid.NewGuid().ToString() }; ResourceList = new List <AuthorizationResource> { _testAuthorizationResource }; MockIAuthorisationResourceRepository.Setup(x => x.Get(It.IsAny <ClaimsIdentity>())).Returns(ResourceList); AuthorizationContext = new AuthorizationContext(); }
public void Configuration(IAppBuilder app) { var proxy = new UWebSiteUrlProxy(); var config = new OAuthConstants(proxy); var authCore = new AuthorizationResource(config); // Enable Bearer Authentication app.UseOAuthBearerAuthentication(authCore.CreateOAuthBearerAuthenticationOptions()); }
public async Task <IActionResult> CreateToken([FromBody] AuthorizationResource authorization) { var user = await UserRepository.FindByName(authorization.UserName); if (user == null || user.PasswordHash != Hashing.HashPassword(authorization.Password)) { return(Unauthorized()); } var token = BuildToken(user); return(Ok(new { Token = token })); }
public async Task <bool> CreateResourceAsync(string realm, string resourceServerId, AuthorizationResource resource) { var response = await GetBaseUrl(realm) .AppendPathSegment($"/admin/realms/{realm}/clients/{resourceServerId}/authz/resource-server/resource") .PostJsonAsync(resource) .ConfigureAwait(false); return(response.IsSuccessStatusCode); }