-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(basic-auth) use dao transformations with basic auth credentials
Also removes the need to use custom dao. This works as a showcase for dao-transformations. Fix Kong#4893.
- Loading branch information
Showing
5 changed files
with
62 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
local typedefs = require "kong.db.schema.typedefs" | ||
local crypto = require "kong.plugins.basic-auth.crypto" | ||
|
||
|
||
return { | ||
basicauth_credentials = { | ||
dao = "kong.plugins.basic-auth.basicauth_credentials", | ||
name = "basicauth_credentials", | ||
primary_key = { "id" }, | ||
cache_key = { "username" }, | ||
endpoint_key = "username", | ||
-- Passwords are hashed on insertion, so the exported passwords would be encrypted. | ||
-- Importing them back would require "plain" unencrypted passwords instead | ||
-- Passwords are hashed, so the exported passwords would contain the hashes. | ||
-- Importing them back would require "plain" non-hashed passwords instead. | ||
db_export = false, | ||
admin_api_name = "basic-auths", | ||
admin_api_nested_name = "basic-auth", | ||
fields = { | ||
{ id = typedefs.uuid }, | ||
{ created_at = typedefs.auto_timestamp_s }, | ||
{ consumer = { type = "foreign", reference = "consumers", required = true, on_delete = "cascade", }, }, | ||
{ consumer = { type = "foreign", reference = "consumers", required = true, on_delete = "cascade" }, }, | ||
{ username = { type = "string", required = true, unique = true }, }, | ||
{ password = { type = "string", required = true }, }, | ||
{ tags = typedefs.tags }, | ||
}, | ||
transformations = { | ||
{ | ||
input = { "password" }, | ||
needs = { "consumer.id" }, | ||
on_write = function(password, consumer_id) | ||
return { password = crypto.hash(consumer_id, password) } | ||
end, | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters