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

fix: used dashboard add consumer of jwt, would have an error when get the jwt token #768

Merged
merged 2 commits into from
Nov 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions api/internal/handler/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ func (h *Handler) Create(c droplet.Context) (interface{}, error) {
}
input.ID = input.Username

if _, ok := input.Plugins["jwt-auth"]; ok {
jwt := input.Plugins["jwt-auth"].(map[string]interface{})
jwt["exp"] = 86400
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add exp = 86400?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there is a problem with the default value setting of the current jsonschema, a temporary solution

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add issue for it


input.Plugins["jwt-auth"] = jwt
}

if err := h.consumerStore.Create(c.Context(), input); err != nil {
return handler.SpecCodeResponse(err), err
}
Expand All @@ -128,6 +135,13 @@ func (h *Handler) Update(c droplet.Context) (interface{}, error) {
}
input.Consumer.ID = input.Consumer.Username

if _, ok := input.Consumer.Plugins["jwt-auth"]; ok {
jwt := input.Consumer.Plugins["jwt-auth"].(map[string]interface{})
jwt["exp"] = 86400

input.Consumer.Plugins["jwt-auth"] = jwt
}

if err := h.consumerStore.Update(c.Context(), &input.Consumer, true); err != nil {
//if not exists, create
if err.Error() == fmt.Sprintf("key: %s is not found", input.Username) {
Expand Down