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

feat: login failed webhook #4101

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions driver/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const (
ViperKeySelfServiceLoginRequestLifespan = "selfservice.flows.login.lifespan"
ViperKeySelfServiceLoginAfter = "selfservice.flows.login.after"
ViperKeySelfServiceLoginBeforeHooks = "selfservice.flows.login.before.hooks"
ViperKeySelfServiceLoginFailedHooks = "selfservice.flows.login.failed.hooks"
ViperKeySelfServiceErrorUI = "selfservice.flows.error.ui_url"
ViperKeySelfServiceLogoutBrowserDefaultReturnTo = "selfservice.flows.logout.after." + DefaultBrowserReturnURL
ViperKeySelfServiceSettingsURL = "selfservice.flows.settings.ui_url"
Expand Down Expand Up @@ -702,6 +703,10 @@ func (p *Config) SelfServiceFlowLoginBeforeHooks(ctx context.Context) []SelfServ
return p.selfServiceHooks(ctx, ViperKeySelfServiceLoginBeforeHooks)
}

func (p *Config) SelfServiceFlowLoginFailedHooks(ctx context.Context) []SelfServiceHook {
return p.selfServiceHooks(ctx, ViperKeySelfServiceLoginFailedHooks)
}

func (p *Config) SelfServiceFlowRecoveryBeforeHooks(ctx context.Context) []SelfServiceHook {
return p.selfServiceHooks(ctx, ViperKeySelfServiceRecoveryBeforeHooks)
}
Expand Down
11 changes: 11 additions & 0 deletions driver/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,17 @@ func TestViperProvider(t *testing.T) {
// assert.JSONEq(t, `{"allow_user_defined_redirect":false,"default_redirect_url":"http://test.kratos.ory.sh:4000/"}`, string(hook.Config))
})

t.Run("hook=failed", func(t *testing.T) {
expHooks := []config.SelfServiceHook{
{Name: "web_hook", Config: json.RawMessage(`{"headers":{"X-Custom-Header":"test"},"method":"POST","url":"https://test.kratos.ory.sh/failed_login_hook"}`)},
}

hooks := p.SelfServiceFlowLoginFailedHooks(ctx)

require.Len(t, hooks, 1)
assert.Equal(t, expHooks, hooks)
})

for _, tc := range []struct {
strategy string
hooks []config.SelfServiceHook
Expand Down
34 changes: 21 additions & 13 deletions driver/config/stub/.kratos.webauthn.invalid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_recovery_hook
method: GET
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet

Expand All @@ -119,7 +119,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_verification_hook
method: GET
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet

Expand All @@ -136,7 +136,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_settings_password_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
profile:
Expand All @@ -145,15 +145,15 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_settings_profile_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
hooks:
- hook: web_hook
config:
url: https://test.kratos.ory.sh/after_settings_global_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet

Expand All @@ -166,7 +166,15 @@ selfservice:
config:
url: https://test.kratos.ory.sh/before_login_hook
method: POST
headers:
headers:
X-Custom-Header: test
failed:
hooks:
- hook: web_hook
config:
url: https://test.kratos.ory.sh/failed_login_hook
method: POST
headers:
X-Custom-Header: test
after:
default_browser_return_url: https://self-service/login/return_to
Expand All @@ -179,7 +187,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_login_password_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
auth:
Expand All @@ -193,7 +201,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_login_oidc_hook
method: GET
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
- hook: revoke_active_sessions
Expand All @@ -202,7 +210,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_login_global_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet

Expand All @@ -216,7 +224,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/before_registration_hook
method: GET
headers:
headers:
X-Custom-Header: test
after:
default_browser_return_url: https://self-service/registration/return_to
Expand All @@ -227,15 +235,15 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_registration_password_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
hooks:
- hook: web_hook
config:
url: https://test.kratos.ory.sh/after_registration_global_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
auth:
Expand All @@ -251,7 +259,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_registration_oidc_hook
method: GET
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
- hook: session
34 changes: 21 additions & 13 deletions driver/config/stub/.kratos.webauthn.origin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_recovery_hook
method: GET
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet

Expand All @@ -115,7 +115,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_verification_hook
method: GET
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet

Expand All @@ -132,7 +132,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_settings_password_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
profile:
Expand All @@ -141,15 +141,15 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_settings_profile_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
hooks:
- hook: web_hook
config:
url: https://test.kratos.ory.sh/after_settings_global_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet

Expand All @@ -162,7 +162,15 @@ selfservice:
config:
url: https://test.kratos.ory.sh/before_login_hook
method: POST
headers:
headers:
X-Custom-Header: test
failed:
hooks:
- hook: web_hook
config:
url: https://test.kratos.ory.sh/failed_login_hook
method: POST
headers:
X-Custom-Header: test
after:
default_browser_return_url: https://self-service/login/return_to
Expand All @@ -175,7 +183,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_login_password_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
auth:
Expand All @@ -189,7 +197,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_login_oidc_hook
method: GET
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
- hook: revoke_active_sessions
Expand All @@ -198,7 +206,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_login_global_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet

Expand All @@ -212,7 +220,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/before_registration_hook
method: GET
headers:
headers:
X-Custom-Header: test
after:
default_browser_return_url: https://self-service/registration/return_to
Expand All @@ -223,15 +231,15 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_registration_password_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
hooks:
- hook: web_hook
config:
url: https://test.kratos.ory.sh/after_registration_global_hook
method: POST
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
auth:
Expand All @@ -247,7 +255,7 @@ selfservice:
config:
url: https://test.kratos.ory.sh/after_registration_oidc_hook
method: GET
headers:
headers:
X-Custom-Header: test
body: /path/to/template.jsonnet
- hook: session
Loading
Loading