protected override void Arrange() { _apiClientIdentity = new ApiClientIdentity { Key = "MyKey" }; var apiClientIdentityProvider = Stub <IApiClientIdentityProvider>(); A.CallTo(() => apiClientIdentityProvider.GetApiClientIdentity("MyKey")) .Returns(_apiClientIdentity); var apiClientSecret = new ApiClientSecret { Secret = "MySecret" }; var apiClientSecretProvider = Stub <IApiClientSecretProvider>(); A.CallTo(() => apiClientSecretProvider.GetSecret("MyKey")) .Returns(apiClientSecret); var secretVerifier = Stub <ISecretVerifier>(); A.CallTo(() => secretVerifier.VerifySecret("MyKey", "MySecret", apiClientSecret)) .Returns(true); _apiClientAuthenticator = new ApiClientAuthenticator(apiClientIdentityProvider, apiClientSecretProvider, secretVerifier); }
protected override Task ArrangeAsync() { _suppliedClient = new ApiClient { ApiClientId = 1 }; // Scope the request to something not in list above _requestedScope = "9a9"; _accessTokenClientRepo = Stub <IAccessTokenClientRepo>(); _apiClientAuthenticator = A.Fake <IApiClientAuthenticator>(); A.CallTo(() => _apiClientAuthenticator.TryAuthenticateAsync(A <string> ._, A <string> ._)) .Returns( Task.FromResult( new ApiClientAuthenticator.AuthenticationResult { IsAuthenticated = true, ApiClientIdentity = new ApiClientIdentity { Key = "clientId" } })); _controller = ControllerHelper.CreateTokenController(_apiClientAuthenticator, _accessTokenClientRepo); return(Task.CompletedTask); }
protected override void Arrange() { _clientAppRepo = MockRepository.GenerateStub <IClientAppRepo>(); _tokenRequest = new TokenRequest { Client_id = ClientId, Client_secret = ClientSecret }; _apiClientAuthenticator = MockRepository.GenerateStub <IApiClientAuthenticator>(); ApiClientIdentity apiClientIdentity; _apiClientAuthenticator .Expect(aca => aca.TryAuthenticate(null, null, out apiClientIdentity)) .IgnoreArguments() .Do( new ApiClientAuthenticatorDelegates.TryAuthenticateDelegate( (string key, string password, out ApiClientIdentity identity) => { identity = null; return(false); })); _clientCredentialsTokenRequestHandler = new ClientCredentialsTokenRequestHandler(_clientAppRepo, _apiClientAuthenticator); }
protected override void Arrange() { _clientAppRepo = A.Fake <IClientAppRepo>(); _accessTokenClientRepo = A.Fake <IAccessTokenClientRepo>(); _apiClientAuthenticator = A.Fake <IApiClientAuthenticator>(); _tokenRequest = new TokenRequest { Client_id = ClientId, Client_secret = ClientSecret, Grant_type = "client_credentials" }; _apiClientAuthenticator = A.Fake <IApiClientAuthenticator>(); A.CallTo(() => _apiClientAuthenticator.TryAuthenticateAsync(A <string> ._, A <string> ._)) .Returns( Task.FromResult <ApiClientAuthenticator.AuthenticationResult>( new ApiClientAuthenticator.AuthenticationResult { IsAuthenticated = true, ApiClientIdentity = new ApiClientIdentity { Key = ClientId, } })); }
protected override Task ArrangeAsync() { // Scope the request to something not in list above _requestedScope = "1000"; _suppliedAccessToken = Guid.NewGuid(); _accessTokenClientRepo = Stub <IAccessTokenClientRepo>(); _suppliedClient = new ApiClient { ApiClientId = 1 }; _apiClientAuthenticator = A.Fake <IApiClientAuthenticator>(); A.CallTo(() => _apiClientAuthenticator.TryAuthenticateAsync(A <string> ._, A <string> ._)) .Returns( Task.FromResult( new ApiClientAuthenticator.AuthenticationResult { IsAuthenticated = true, ApiClientIdentity = new ApiClientIdentity { Key = "clientId", EducationOrganizationIds = new List <int>() { 997, 998, 999 }, ApiClientId = _suppliedClient.ApiClientId } })); _controller = ControllerHelper.CreateTokenController(_apiClientAuthenticator, _accessTokenClientRepo); return(Task.CompletedTask); }
protected override void Arrange() { _apiClientIdentity = new ApiClientIdentity { Key = "MyKey" }; var apiClientIdentityProvider = mocks.Stub <IApiClientIdentityProvider>(); apiClientIdentityProvider.Stub(x => x.GetApiClientIdentity("MyKey")) .Return(_apiClientIdentity); var apiClientSecret = new ApiClientSecret { Secret = "MySecret" }; var apiClientSecretProvider = mocks.Stub <IApiClientSecretProvider>(); apiClientSecretProvider.Expect(x => x.GetSecret("MyKey")) .Return(apiClientSecret); var secretVerifier = mocks.Stub <ISecretVerifier>(); secretVerifier.Expect(x => x.VerifySecret("MyKey", "MySecret", apiClientSecret)) .Return(true); _apiClientAuthenticator = new ApiClientAuthenticator(apiClientIdentityProvider, apiClientSecretProvider, secretVerifier); }
public ClientCredentialsTokenRequestProvider( IApiClientAuthenticator apiClientAuthenticator, IAccessTokenClientRepo accessTokenClientRepo) { _apiClientAuthenticator = apiClientAuthenticator; _accessTokenClientRepo = accessTokenClientRepo; }
protected override Task ArrangeAsync() { _suppliedClient = new ApiClient { ApiClientId = 1 }; _suppliedAccessToken = Guid.NewGuid(); _accessTokenClientRepo = Stub <IAccessTokenClientRepo>(); _apiClientAuthenticator = Stub <IApiClientAuthenticator>(); A.CallTo(() => _accessTokenClientRepo.AddClientAccessTokenAsync(A <int> ._, A <string> ._)) .Returns( new ClientAccessToken(new TimeSpan(0, 10, 0)) { ApiClient = _suppliedClient, Id = _suppliedAccessToken }); A.CallTo(() => _apiClientAuthenticator.TryAuthenticateAsync(A <string> ._, A <string> ._)) .Returns( Task.FromResult( new ApiClientAuthenticator.AuthenticationResult { IsAuthenticated = true, ApiClientIdentity = new ApiClientIdentity { Key = "clientId" } })); _controller = ControllerHelper.CreateTokenController(_apiClientAuthenticator, _accessTokenClientRepo); return(Task.CompletedTask); }
protected override Task ArrangeAsync() { _accessTokenClientRepo = Stub <IAccessTokenClientRepo>(); _apiClientAuthenticator = Stub <IApiClientAuthenticator>(); _controller = ControllerHelper.CreateTokenController(_apiClientAuthenticator, _accessTokenClientRepo); return(Task.CompletedTask); }
protected override void Arrange() { var apiClientIdentityProvider = Stub <IApiClientIdentityProvider>(); var apiClientSecretProvider = Stub <IApiClientSecretProvider>(); A.CallTo(() => apiClientSecretProvider.GetSecret("MyInvalidKey")).Throws(new ArgumentException()); var secretVerifier = Stub <ISecretVerifier>(); _apiClientAuthenticator = new ApiClientAuthenticator(apiClientIdentityProvider, apiClientSecretProvider, secretVerifier); }
protected override void Arrange() { var apiClientIdentityProvider = mocks.Stub <IApiClientIdentityProvider>(); var apiClientSecretProvider = mocks.Stub <IApiClientSecretProvider>(); apiClientSecretProvider.Expect(x => x.GetSecret("MyInvalidKey")) .Throw(new ArgumentException()); var secretVerifier = mocks.Stub <ISecretVerifier>(); _apiClientAuthenticator = new ApiClientAuthenticator(apiClientIdentityProvider, apiClientSecretProvider, secretVerifier); }
protected override Task ArrangeAsync() { _suppliedClient = new ApiClient { ApiClientId = 1 }; _apiClientAuthenticator = Stub <IApiClientAuthenticator>(); var ApplicationEducationOrganizations = new List <int>() { 997, 998, 999 }; // Scope the request to the first associated EdOrg _requestedScope = ApplicationEducationOrganizations .First() .ToString(); _suppliedAccessToken = Guid.NewGuid(); _accessTokenClientRepo = Stub <IAccessTokenClientRepo>(); A.CallTo(() => _accessTokenClientRepo.AddClientAccessTokenAsync(A <int> ._, A <string> ._)) .Returns( new ClientAccessToken(new TimeSpan(0, 10, 0)) { ApiClient = _suppliedClient, Id = _suppliedAccessToken }); A.CallTo(() => _apiClientAuthenticator.TryAuthenticateAsync(A <string> ._, A <string> ._)) .Returns( Task.FromResult( new ApiClientAuthenticator.AuthenticationResult { IsAuthenticated = true, ApiClientIdentity = new ApiClientIdentity { Key = "clientId", EducationOrganizationIds = ApplicationEducationOrganizations, ApiClientId = _suppliedClient.ApiClientId, } })); _controller = ControllerHelper.CreateTokenController(_apiClientAuthenticator, _accessTokenClientRepo); return(Task.CompletedTask); }
protected override Task ArrangeAsync() { _suppliedClient = new ApiClient { ApiClientId = 1 }; _suppliedAccessToken = Guid.NewGuid(); _accessTokenClientRepo = Stub <IAccessTokenClientRepo>(); _apiClientAuthenticator = Stub <IApiClientAuthenticator>(); _controller = ControllerHelper.CreateTokenController(_apiClientAuthenticator, _accessTokenClientRepo); return(Task.CompletedTask); }
protected override Task ArrangeAsync() { _accessTokenClientRepo = Stub <IAccessTokenClientRepo>(); _apiClientAuthenticator = Stub <IApiClientAuthenticator>(); A.CallTo(() => _apiClientAuthenticator.TryAuthenticateAsync(A <string> ._, A <string> ._)) .Returns( Task.FromResult( new ApiClientAuthenticator.AuthenticationResult { IsAuthenticated = false })); _controller = ControllerHelper.CreateTokenController(_apiClientAuthenticator, _accessTokenClientRepo); return(Task.CompletedTask); }
protected override void Arrange() { var apiClient = new ApiClient { ApiClientId = 0 }; _accessTokenClientRepo = A.Fake <IAccessTokenClientRepo>(); _apiClientAuthenticator = A.Fake <IApiClientAuthenticator>(); A.CallTo(() => _accessTokenClientRepo.AddClientAccessToken(A <int> ._, A <string> ._)) .Returns(new ClientAccessToken { ApiClient = new ApiClient() }); _tokenRequest = new TokenRequest { Client_id = ClientId, Client_secret = ClientSecret, Grant_type = "client_credentials" }; var clientSecret = new ApiClientSecret { IsHashed = true, Secret = ClientSecret }; A.CallTo(() => _apiClientAuthenticator.TryAuthenticateAsync(A <string> ._, A <string> ._)) .Returns( Task.FromResult <ApiClientAuthenticator.AuthenticationResult>( new ApiClientAuthenticator.AuthenticationResult { IsAuthenticated = true, ApiClientIdentity = new ApiClientIdentity { Key = ClientId, EducationOrganizationIds = new List <int>() { 997, 998, 999 } } })); }
public static TokenController CreateTokenController( IClientAppRepo clientAppRepo, IApiClientAuthenticator apiClientAuthenticator, IAccessTokenClientRepo accessTokenClientRepo) { var tokenRequestProvider = new ClientCredentialsTokenRequestProvider(clientAppRepo, apiClientAuthenticator, accessTokenClientRepo); var controller = new TokenController(tokenRequestProvider); var request = A.Fake <HttpRequest>(); request.Method = "Post"; request.Scheme = "http"; A.CallTo(() => request.Host).Returns(new HostString("localhost", 80)); request.PathBase = "/"; request.RouteValues = new RouteValueDictionary { { "controller", "authorize" } }; var httpContext = A.Fake <HttpContext>(); A.CallTo(() => httpContext.Request).Returns(request); var controllerContext = new ControllerContext() { HttpContext = httpContext, }; var routeData = A.Fake <RouteData>(); RouteValueDictionary dictionary = new RouteValueDictionary { { "controller", "authorize" } }; controllerContext.RouteData = new RouteData(dictionary); controller.ControllerContext = controllerContext; return(controller); }
protected override void Arrange() { var apiClient = new ApiClient { ApiClientId = 0 }; _clientAppRepo = mocks.Stub <IClientAppRepo>(); _clientAppRepo.Expect(c => c.GetClient(Arg <string> .Is.Anything)) .Return(apiClient); _clientAppRepo.Expect(c => c.AddClientAccessToken(0)) .Return(new ClientAccessToken()); _tokenRequest = new TokenRequest { Client_id = ClientId, Client_secret = ClientSecret }; _apiClientAuthenticator = _apiClientAuthenticatorHelper.Mock(mocks); _clientCredentialsTokenRequestHandler = new ClientCredentialsTokenRequestHandler(_clientAppRepo, _apiClientAuthenticator); }
public ClientCredentialsTokenRequestHandler(IClientAppRepo clientAppRepo, IApiClientAuthenticator apiClientAuthenticator) { _clientAppRepo = clientAppRepo; _apiClientAuthenticator = apiClientAuthenticator; }