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

Create consumer in real-time #21

Closed
akira28 opened this issue Jul 28, 2021 · 6 comments
Closed

Create consumer in real-time #21

akira28 opened this issue Jul 28, 2021 · 6 comments

Comments

@akira28
Copy link

akira28 commented Jul 28, 2021

I'm building a custom authentication plugin based on api keys, and I was wondering if there's a way to create consumers once I get an 'OK' from my internal authentication system. This would allow me avoiding syncing Kong db with my auth system.

One idea was to use the kong.db and create consumers manually, but there's no api for db on kong-js-pdk.
A possible solution would be to add a postgreSQL client like https://node-postgres.com/ to my plugin and do queries directly.

Is there a more elegant solution for this?

Thanks

@fffonion
Copy link
Contributor

fffonion commented Jul 29, 2021

@akira28 I don't immeditately see a way to do it without touching DB directly (or admin API), and that could be ugly. However
i can see this usage being common, actually plugins like openid, oauth2 has the same requirement. But instead of actually create a consumer
you can use kong.client.authenticate(consumer, credential) to tell Kong the credential it mapped to. And plugins like rate-limit also honors
credential without the need to lookup consumer. But don't set consumer, since it's not a consumer mapped anyway.

@akira28
Copy link
Author

akira28 commented Jul 30, 2021

ah, nice to know. But how can I create the 'credential' object? And can I call kong.client.authenticate(undefined, credential) (undefined consumer)?

@fffonion
Copy link
Contributor

Yes you can. On Lua PDK I think credential is just an table of { id = "the credential value" }, it would work with
proper Js syntax, though i didn't try for myself.

@akira28
Copy link
Author

akira28 commented Jul 30, 2021

by 'the credential value' you mean the 'api key'?

@fffonion
Copy link
Contributor

credential in this context means an abitrary identitifer that your internal auth system returns, that can uniquely
identifier a user.

@akira28
Copy link
Author

akira28 commented Jul 30, 2021

cool, perfect! This simplify things A LOT!
Thanks

@akira28 akira28 closed this as completed Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants