Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kong.client.authenticate should support nil values for consumer and credential #152

Closed
lvermeire opened this issue Jul 18, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@lvermeire
Copy link
Contributor

go-pdk/client/client.go

Lines 125 to 152 in 4deec45

// kong.Client.Authenticate() sets the authenticated consumer and/or credential
// for the current request. While both consumer and credential can be nil,
// it is required that at least one of them exists. Otherwise this function will throw an error.
func (c Client) Authenticate(consumer *entities.Consumer, credential *AuthenticatedCredential) error {
if consumer == nil {
return fmt.Errorf("Invalid consumer")
}
if credential == nil {
return fmt.Errorf("Invalid credential")
}
arg := &kong_plugin_protocol.AuthenticateArgs{
Consumer: &kong_plugin_protocol.Consumer{
Id: consumer.Id,
CreatedAt: int64(consumer.CreatedAt),
Username: consumer.Username,
CustomId: consumer.CustomId,
Tags: consumer.Tags,
},
Credential: &kong_plugin_protocol.AuthenticatedCredential{
Id: credential.Id,
ConsumerId: credential.ConsumerId,
},
}
err := c.Ask(`kong.client.authenticate`, arg, nil)
return err
}

The function kong.client.authenticate in the Kong PDK client module supports nil values for both consumer and credential:

While both consumer and credential can be nil, at least one of them must exist. Otherwise, this function will throw an error.

The current implementation of the go client does not allow either parameter to be nil, but it should.

@StarlightIbuki
Copy link
Contributor

Thanks for the report and the PR! We will be looking into it soon.

@gszr gszr added the bug Something isn't working label Feb 22, 2024
gszr pushed a commit to lvermeire/go-pdk that referenced this issue Feb 22, 2024
Either `consumer` or `credential` may be nil.

Fixes Kong#152
@gszr gszr closed this as completed in efa03e7 Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants