Skip to content
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
1 change: 1 addition & 0 deletions selfservice/strategy/oidc/strategy_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ func (s *Strategy) Login(w http.ResponseWriter, r *http.Request, f *login.Flow,
if err != nil {
return nil, s.HandleError(ctx, w, r, f, pid, nil, err)
}
f.Active = s.ID()
_, err = s.ProcessLogin(ctx, w, r, f, nil, claims, provider, &AuthCodeContainer{
FlowID: f.ID.String(),
Traits: p.Traits,
Expand Down
1 change: 1 addition & 0 deletions selfservice/strategy/oidc/strategy_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func (s *Strategy) Register(w http.ResponseWriter, r *http.Request, f *registrat
if err != nil {
return s.HandleError(ctx, w, r, f, pid, nil, err)
}
f.Active = s.ID()
_, err = s.processRegistration(ctx, w, r, f, nil, claims, provider, &AuthCodeContainer{
FlowID: f.ID.String(),
Traits: p.Traits,
Expand Down
46 changes: 46 additions & 0 deletions selfservice/strategy/oidc/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,52 @@
})

}

t.Run("case=runs method-specific post-registration and post-login hooks", func(t *testing.T) {
postRegistrationWebhook := hooktest.NewServer()
t.Cleanup(postRegistrationWebhook.Close)
postRegistrationWebhook.SetConfig(t, conf.GetProvider(t.Context()),
config.HookStrategyKey(config.ViperKeySelfServiceRegistrationAfter, identity.CredentialsTypeOIDC.String()))
postLoginWebhook := hooktest.NewServer()
t.Cleanup(postLoginWebhook.Close)
postLoginWebhook.SetConfig(t, conf.GetProvider(t.Context()),
config.HookStrategyKey(config.ViperKeySelfServiceLoginAfter, identity.CredentialsTypeOIDC.String()))

nonce := randx.MustString(16, randx.Alpha)
token := strings.NewReplacer("{{sub}}", testhelpers.RandomEmail(), "{{nonce}}", nonce).Replace(`{
"iss": "https://appleid.apple.com",
"sub": "{{sub}}",
"nonce": "{{nonce}}"
}`)

submit := func(t *testing.T, action, transientPayload string) {
res, err := cl.PostForm(action, url.Values{
"id_token": {token},
"id_token_nonce": {nonce},
"provider": {"test-provider"},
"transient_payload": {transientPayload},
})
require.NoError(t, err)
defer res.Body.Close()

Check failure on line 1413 in selfservice/strategy/oidc/strategy_test.go

View workflow job for this annotation

GitHub Actions / Run tests and lints

Error return value of `res.Body.Close` is not checked (errcheck)
body := ioutilx.MustReadAll(res.Body)
require.NotEmpty(t, gjson.GetBytes(body, "session_token").String(), "%s", body)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

registrationPayload := `{"data": "id-token-registration"}`
rf := newAPIRegistrationFlow(t, returnTS.URL, time.Minute)
submit(t, assertFormValues(t, rf.ID, "test-provider"), registrationPayload)
postRegistrationWebhook.AssertTransientPayload(t, registrationPayload)

loginPayload := `{"data": "id-token-login"}`
lf := newAPILoginFlow(t, returnTS.URL, time.Minute)
submit(t, assertFormValues(t, lf.ID, "test-provider"), loginPayload)
postLoginWebhook.AssertTransientPayload(t, loginPayload)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

registrationToLoginPayload := `{"data": "id-token-registration-to-login"}`
rf = newAPIRegistrationFlow(t, returnTS.URL, time.Minute)
submit(t, assertFormValues(t, rf.ID, "test-provider"), registrationToLoginPayload)
postLoginWebhook.AssertTransientPayload(t, registrationToLoginPayload)
})
})

t.Run("case=login without registered account with return_to", func(t *testing.T) {
Expand Down
Loading