Skip to content

ProtocolException at AuthenticateWithPasswordAsync #2373

@tlencse

Description

@tlencse

Confirm you've already contributed to this project or that you sponsor it

  • I confirm I'm a sponsor or a contributor

Version

6.4.0

Question

Hi Kevin,

I am in a project and I use OpenIddict password authentication scheme in it. It calls OpenIddict.Client.OpenIddictClientService.AuthenticateWithPasswordAsync(PasswordAuthenticationRequest request). When I provide the right password, everything is fine, I get the tokens. But when I provide a wrong password (or anything else is wrong), I get a ProtocolException with ID2162.

I tried to run the openiddict-samples-dev\samples\Imynusoph\Imynusoph, which produced the same symptoms. Works fine with the right password, and gives a ProtocolException. However it is a little bit different, the ID this time is ID2147.

This is the config of the openiddict client:


var services = new ServiceCollection();

// Register the OpenIddict client services.
services.AddOpenIddict()

// Register the OpenIddict client components.
.AddClient(options =>
{
	// Allow grant_type=password and grant_type=refresh_token to be negotiated.
	options.AllowPasswordFlow()
			.AllowRefreshTokenFlow();

	// Disable token storage, which is not necessary for non-interactive flows like
	// grant_type=password, grant_type=client_credentials or grant_type=refresh_token.
	options.DisableTokenStorage();

	// Register the System.Net.Http integration and use the identity of the current
	// assembly as a more specific user agent, which can be useful when dealing with
	// providers that use the user agent as a way to throttle requests (e.g Reddit).
	options.UseSystemNetHttp()
		   .SetProductInformation(Assembly.GetEntryAssembly()!);

	// Add a client registration without a client identifier/secret attached.
	//TODO: Issuer uri should come from configuration
	options.AddRegistration(new OpenIddictClientRegistration
	{
		Issuer = new Uri(config.GetValue<string>("ServerEndPoints:AuthServer") ?? 
		throw new ConfigurationErrorsException("AuthServer endpoint is not defined in appsettings.json")
		, UriKind.Absolute)
	});


	var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
	Console.WriteLine("Environment: {0}", environment);

});

The server side is basically the same as the example. This code runs when the authentication is not successful:

...
else //provider auth was not successful
{
	if (user is null) // not found in the db
	{
		//no luck, we return an error
		var properties = new AuthenticationProperties(new Dictionary<string, string?>
		{
			[OpenIddictServerAspNetCoreConstants.Properties.Error] = Errors.InvalidGrant,
			[OpenIddictServerAspNetCoreConstants.Properties.ErrorDescription] = "A felhasználónév vagy jelszó helytelen."
		});
		return Results.Forbid(properties);
	}
}

Can you help me how to start debugging this?

Thanks a lot,
Tamás

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions