public async Task When_Client_Cannot_Be_Authenticated_Then_Error_Is_Returned() { InitializeFakeObjects(); const string clientAssertion = "clientAssertion"; const string clientAssertionType = "clientAssertionType"; const string clientId = "clientId"; const string clientSecret = "clientSecret"; var resourceOwnerGrantTypeParameter = new ResourceOwnerGrantTypeParameter { ClientAssertion = clientAssertion, ClientAssertionType = clientAssertionType, ClientId = clientId, ClientSecret = clientSecret }; var authenticationHeader = new AuthenticationHeaderValue( "Basic", $"{clientId}:{clientSecret}".Base64Encode()); var result = await _getTokenByResourceOwnerCredentialsGrantTypeAction.Execute( resourceOwnerGrantTypeParameter, authenticationHeader, null, null, CancellationToken.None) .ConfigureAwait(false) as Option <GrantedToken> .Error; Assert.Equal(ErrorCodes.InvalidClient, result.Details.Title); Assert.Equal(string.Format(SharedStrings.TheClientDoesntExist), result.Details.Detail); }
public async Task <Option <GrantedToken> > GetTokenByResourceOwnerCredentialsGrantType( ResourceOwnerGrantTypeParameter resourceOwnerGrantTypeParameter, AuthenticationHeaderValue?authenticationHeaderValue, X509Certificate2?certificate, string issuerName, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(resourceOwnerGrantTypeParameter.UserName)) { return(new ErrorDetails { Status = HttpStatusCode.BadRequest, Title = ErrorCodes.InvalidRequest, Detail = string.Format(Strings.MissingParameter, StandardTokenRequestParameterNames.UserName) }); } if (string.IsNullOrWhiteSpace(resourceOwnerGrantTypeParameter.Password)) { return(new ErrorDetails { Status = HttpStatusCode.BadRequest, Title = ErrorCodes.InvalidRequest, Detail = string.Format( Strings.MissingParameter, StandardTokenRequestParameterNames.PasswordName) }); } if (string.IsNullOrWhiteSpace(resourceOwnerGrantTypeParameter.Scope)) { return(new ErrorDetails { Status = HttpStatusCode.BadRequest, Title = ErrorCodes.InvalidRequest, Detail = string.Format(Strings.MissingParameter, StandardTokenRequestParameterNames.ScopeName) }); } return(await _getTokenByResourceOwnerCredentialsGrantType.Execute( resourceOwnerGrantTypeParameter, authenticationHeaderValue, certificate, issuerName, cancellationToken).ConfigureAwait(false)); }