예제 #1
0
        public async Task <Option <GrantedToken> > GetTokenByRefreshTokenGrantType(
            RefreshTokenGrantTypeParameter refreshTokenGrantTypeParameter,
            AuthenticationHeaderValue?authenticationHeaderValue,
            X509Certificate2?certificate,
            string issuerName,
            CancellationToken cancellationToken)
        {
            // Read this RFC for more information
            if (string.IsNullOrWhiteSpace(refreshTokenGrantTypeParameter.RefreshToken))
            {
                return(new ErrorDetails
                {
                    Status = HttpStatusCode.BadRequest,
                    Title = ErrorCodes.InvalidRequest,
                    Detail = string.Format(
                        Strings.MissingParameter,
                        StandardTokenRequestParameterNames.RefreshToken)
                });
            }

            return(await _getTokenByRefreshTokenGrantTypeAction.Execute(
                       refreshTokenGrantTypeParameter,
                       authenticationHeaderValue,
                       certificate,
                       issuerName,
                       cancellationToken).ConfigureAwait(false));
        }
        public async Task When_Client_Cannot_Be_Authenticated_Then_Error_Is_Returned()
        {
            var parameter = new RefreshTokenGrantTypeParameter();

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

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

            Assert.Equal(ErrorCodes.InvalidClient, result.Details.Title);
            Assert.Equal(SharedStrings.TheClientDoesntExist, result.Details.Detail);
        }