I'm working on a console application to automatically interact with an API that needs and OAuth authorized user with a specific set of claims. If I use a browser to log in with a username and password everything works fine, but if I try to connect with a HttpClient I get the error:
"No user found matching username:"
var handler = new HttpClientHandler() { AllowAutoRedirect = true };
var client = new HttpClient(handler);
TokenResponse tokenResponse = client.RequestPasswordTokenAsync(new PasswordTokenRequest
{
Address = "https://localhost:44328/connect/token",
ClientId = "clientid",
ClientSecret = "secret",
Scope = "api1 roles",
UserName = "username",
Password = "password"
}).Result;
I'm using Duende.IdentityModel for the RequestPasswordTokenAsync. The message appears in the server log., followed by this line: User authentication failed:
invalid_username_or_password, details: { "ClientId":"clientid", "ClientName":"clientname", "GrantType":"password", "Scopes":"api1 roles", "AuthorizationCode":null, "RefreshToken":null, "UserName":"username", "AuthenticationContextReferenceClasses":null, "Tenant":null, "IdP":null, "Raw":{"grant_type":"password","username":"username","password":"REDACTED","scope":"api1 roles"},"$type":"TokenRequestValidationLog"}
Why do the credentials work in browser but not when called by the client?