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

PLATFORM-9079 Switch response format in Pandora webhooks for Kratos #114

Merged
merged 1 commit into from
Mar 25, 2024
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
48 changes: 0 additions & 48 deletions selfservice/hook/web_hook.go
Original file line number Diff line number Diff line change
@@ -114,25 +114,6 @@ type (
Messages []errorMessage `json:"messages"`
}

// fandom-start - letter case workaround
detailedMessageFallback struct {
ID int
Text string
Type string
Context json.RawMessage
}

errorMessageFallback struct {
InstancePtr string
Message string
DetailedMessages []detailedMessageFallback
}

rawHookResponseFallback struct {
Messages []errorMessageFallback
}
// fandom-end - letter case workaround

httpConfig struct {
sum string
retries int
@@ -645,21 +626,12 @@ func (e *WebHook) parseWebhookResponse(resp *http.Response, id *identity.Identit
return nil
} else if resp.StatusCode >= http.StatusBadRequest {
var hookResponse rawHookResponse
var hookResponseFallback rawHookResponseFallback
if err = json.Unmarshal(body, &hookResponse); err != nil {
return errors.Wrap(err, "webhook response could not be unmarshalled properly from JSON")
}

// try to read another format is we could not read detailed messages
if len(hookResponse.Messages) != 0 && len(hookResponse.Messages[0].DetailedMessages) == 0 {
if err = json.Unmarshal(body, &hookResponseFallback); err != nil {
return errors.Wrap(err, "webhook response could not be unmarshalled properly from JSON")
}
}

var validationErrs []*schema.ValidationError

// fandom-start - letter case workaround
if len(hookResponse.Messages) != 0 && len(hookResponse.Messages[0].DetailedMessages) != 0 {
for _, msg := range hookResponse.Messages {
messages := text.Messages{}
@@ -679,27 +651,7 @@ func (e *WebHook) parseWebhookResponse(resp *http.Response, id *identity.Identit
}
validationErrs = append(validationErrs, schema.NewHookValidationError(msg.InstancePtr, "a webhook target returned an error", messages))
}
} else {
for _, msg := range hookResponseFallback.Messages {
messages := text.Messages{}
for _, detail := range msg.DetailedMessages {
var msgType text.UITextType
if detail.Type == "error" {
msgType = text.Error
} else {
msgType = text.Info
}
messages.Add(&text.Message{
ID: text.ID(detail.ID),
Text: detail.Text,
Type: msgType,
Context: detail.Context,
})
}
validationErrs = append(validationErrs, schema.NewHookValidationError(msg.InstancePtr, "a webhook target returned an error", messages))
}
}
// fandom-end

// fandom-start
validationErr := schema.NewValidationListError(validationErrs)