コード例 #1
0
        public async Task <ActionResult> Index(string code)
        {
            var request           = _dataProtector.Unprotect <AuthorizationRequest>(code);
            var client            = new SimpleIdentityServer.Core.Models.Client();
            var authenticatedUser = await this.GetAuthenticatedUser(Constants.CookieName);

            var actionResult = await _consentActions.DisplayConsent(request.ToParameter(),
                                                                    authenticatedUser);

            var result = this.CreateRedirectionFromActionResult(actionResult.ActionResult, request);

            if (result != null)
            {
                return(result);
            }

            var viewModel = new ConsentViewModel
            {
                ClientDisplayName        = client.ClientName,
                AllowedScopeDescriptions = actionResult.Scopes == null ? new List <string>() : actionResult.Scopes.Select(s => s.Description).ToList(),
                AllowedIndividualClaims  = actionResult.AllowedClaims == null ? new List <string>() : actionResult.AllowedClaims,
                LogoUri   = client.LogoUri,
                PolicyUri = client.PolicyUri,
                TosUri    = client.TosUri,
                Code      = code
            };

            return(View(viewModel));
        }
コード例 #2
0
        public async Task When_An_Exception_Is_Raised_While_Attempting_To_Create_A_Client_Then_Exception_Is_Thrown()  
        {
            // ARRANGE
            const string clientId = "client_id";
            const string code = "code";
            const string message = "message";
            var client = new SimpleIdentityServer.Core.Models.Client
            {
                ClientId = clientId
            };
            var parameter = new UpdateClientParameter
            {
                ClientId = clientId
            };
            InitializeFakeObjects();
            _clientRepositoryStub.Setup(c => c.GetClientByIdAsync(It.IsAny<string>()))
                .Returns(Task.FromResult(client));
            _generateClientFromRegistrationRequestStub.Setup(g => g.Execute(It.IsAny<UpdateClientParameter>()))
                .Callback(() =>
                {
                    throw new IdentityServerException(code, message);
                });

            // ACT & ASSERT
            var exception = await Assert.ThrowsAsync<IdentityServerManagerException>(() => _updateClientAction.Execute(parameter));
            Assert.True(exception.Code == code);
            Assert.True(exception.Message == message);
        }
コード例 #3
0
        public async Task When_Deleting_Existing_Client_Then_Operation_Is_Called()
        {
            // ARRANGE
            const string clientId = "client_id";
            var          client   = new SimpleIdentityServer.Core.Models.Client
            {
                ClientId = clientId
            };

            InitializeFakeObjects();
            _clientRepositoryStub.Setup(c => c.GetClientByIdAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(client));

            // ACT
            await _removeClientAction.Execute(clientId);

            // ASSERT
            _clientRepositoryStub.Verify(c => c.DeleteAsync(client));
        }
コード例 #4
0
        public async Task When_Getting_Client_Then_Information_Are_Returned()
        {
            // ARRANGE
            const string clientId = "clientId";
            var          client   = new SimpleIdentityServer.Core.Models.Client
            {
                ClientId = clientId
            };

            InitializeFakeObjects();
            _clientRepositoryStub.Setup(c => c.GetClientByIdAsync(It.IsAny <string>()))
            .Returns(Task.FromResult(client));

            // ACT
            var result = await _getClientAction.Execute(clientId);

            // ASSERTS
            Assert.NotNull(result);
            Assert.True(result.ClientId == clientId);
        }
コード例 #5
0
        public async Task When_Passing_Correct_Parameter_Then_Update_Operation_Is_Called()
        {
            // ARRANGE
            const string clientId = "client_id";
            var client = new SimpleIdentityServer.Core.Models.Client
            {
                ClientId = clientId
            };
            var parameter = new UpdateClientParameter
            {
                ClientId = clientId
            };
            InitializeFakeObjects();
            _clientRepositoryStub.Setup(c => c.GetClientByIdAsync(It.IsAny<string>()))
                .Returns(Task.FromResult(client));
            _generateClientFromRegistrationRequestStub.Setup(g => g.Execute(It.IsAny<UpdateClientParameter>()))
                .Returns(client);

            // ACT
            await _updateClientAction.Execute(parameter);

            // ASSERTS
            _clientRepositoryStub.Verify(c => c.UpdateAsync(client));
        }