Ejemplo n.º 1
0
        public async Task <Option <GrantedToken> > GetTokenByAuthorizationCodeGrantType(
            AuthorizationCodeGrantTypeParameter authorizationCodeGrantTypeParameter,
            AuthenticationHeaderValue?authenticationHeaderValue,
            X509Certificate2?certificate,
            string issuerName,
            CancellationToken cancellationToken)
        {
            var validation = Validate(authorizationCodeGrantTypeParameter);

            if (validation is Option.Error e)
            {
                return(e.Details);
            }

            return(await _getTokenByAuthorizationCodeGrantTypeAction.Execute(
                       authorizationCodeGrantTypeParameter,
                       authenticationHeaderValue,
                       certificate,
                       issuerName,
                       cancellationToken).ConfigureAwait(false));
        }
        public async Task When_Client_Cannot_Be_Authenticated_Then_Error_Is_Returned()
        {
            InitializeFakeObjects();
            var authorizationCodeGrantTypeParameter = new AuthorizationCodeGrantTypeParameter
            {
                Code                = "abc",
                ClientAssertion     = "clientAssertion",
                ClientAssertionType = "clientAssertionType",
                ClientId            = "clientId",
                ClientSecret        = "clientSecret"
            };

            _clientStore.Setup(x => x.GetById(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((Client)null);

            var result = await _getTokenByAuthorizationCodeGrantTypeAction.Execute(
                authorizationCodeGrantTypeParameter,
                null,
                null,
                null,
                CancellationToken.None)
                         .ConfigureAwait(false) as Option <GrantedToken> .Error;

            Assert.Equal(ErrorCodes.InvalidClient, result !.Details.Title);
        }