Exemple #1
0
        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();
        }
Exemple #2
0
        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());
        }
Exemple #3
0
        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 }));
        }
Exemple #4
0
        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);
        }