Skip to content

Commit

Permalink
fix: enable b2b_sso hook in more places (#4168)
Browse files Browse the repository at this point in the history
fix: allow b2b_sso hook in more places

---------

Co-authored-by: zepatrik <[email protected]>
  • Loading branch information
hperl and zepatrik authored Oct 29, 2024
1 parent 793e1eb commit 0c48ad1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions embedx/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,9 @@
"anyOf": [
{
"$ref": "#/definitions/selfServiceWebHook"
},
{
"$ref": "#/definitions/b2bSSOHook"
}
]
},
Expand Down Expand Up @@ -766,6 +769,9 @@
},
{
"$ref": "#/definitions/selfServiceShowVerificationUIHook"
},
{
"$ref": "#/definitions/b2bSSOHook"
}
]
},
Expand Down
2 changes: 2 additions & 0 deletions selfservice/flow/duplicate_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package flow
import (
"encoding/json"

"github.com/gofrs/uuid"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"

Expand All @@ -19,6 +20,7 @@ type DuplicateCredentialsData struct {
CredentialsType identity.CredentialsType
CredentialsConfig sqlxx.JSONRawMessage
DuplicateIdentifier string
OrganizationID uuid.UUID
}

type InternalContexter interface {
Expand Down
2 changes: 2 additions & 0 deletions selfservice/flow/login/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/ory/x/jsonx"
"github.com/ory/x/sqlxx"
"github.com/ory/x/uuidx"

"github.com/ory/kratos/driver/config"
"github.com/ory/kratos/identity"
Expand Down Expand Up @@ -224,6 +225,7 @@ func TestDuplicateCredentials(t *testing.T) {
CredentialsType: "foo",
CredentialsConfig: sqlxx.JSONRawMessage(`{"bar":"baz"}`),
DuplicateIdentifier: "bar",
OrganizationID: uuidx.NewV4(),
}

require.NoError(t, flow.SetDuplicateCredentials(f, dc))
Expand Down
3 changes: 3 additions & 0 deletions selfservice/flow/registration/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ func (e *HookExecutor) PostRegistrationHook(w http.ResponseWriter, r *http.Reque
CredentialsConfig: i.Credentials[ct].Config,
DuplicateIdentifier: duplicateIdentifier,
}
if registrationFlow.OrganizationID.Valid {
registrationDuplicateCredentials.OrganizationID = registrationFlow.OrganizationID.UUID
}

if err := flow.SetDuplicateCredentials(registrationFlow, registrationDuplicateCredentials); err != nil {
return err
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 @@ -278,6 +278,7 @@ func (s *Strategy) registrationToLogin(ctx context.Context, w http.ResponseWrite
}
lf.TransientPayload = rf.TransientPayload
lf.Active = s.ID()
lf.OrganizationID = rf.OrganizationID

return lf, nil
}
Expand Down
5 changes: 5 additions & 0 deletions selfservice/strategy/oidc/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/ory/kratos/selfservice/hook/hooktest"
"github.com/ory/x/sqlxx"
"github.com/ory/x/uuidx"

"github.com/ory/kratos/hydra"
"github.com/ory/kratos/selfservice/sessiontokenexchange"
Expand Down Expand Up @@ -1531,6 +1532,7 @@ func TestStrategy(t *testing.T) {
subject2 := "[email protected]"
scope = []string{"openid"}
password := "lwkj52sdkjf"
orgID := uuidx.NewV4()

var i *identity.Identity
t.Run("step=create password identity", func(t *testing.T) {
Expand All @@ -1555,6 +1557,8 @@ func TestStrategy(t *testing.T) {

client := testhelpers.NewClientWithCookieJar(t, nil, nil)
loginFlow := newLoginFlow(t, returnTS.URL, time.Minute, flow.TypeBrowser)
loginFlow.OrganizationID = uuid.NullUUID{orgID, true}
require.NoError(t, reg.LoginFlowPersister().UpdateLoginFlow(context.Background(), loginFlow))

var linkingLoginFlow struct {
ID string
Expand All @@ -1572,6 +1576,7 @@ func TestStrategy(t *testing.T) {
assert.True(t, gjson.GetBytes(body, "ui.nodes.#(attributes.name==identifier)").Exists(), "%s", body)
assert.True(t, gjson.GetBytes(body, "ui.nodes.#(attributes.name==password)").Exists(), "%s", body)
assert.Equal(t, "[email protected]", gjson.GetBytes(body, "ui.messages.#(id==1010016).context.duplicateIdentifier").String())
assert.Equal(t, gjson.GetBytes(body, "organization_id").String(), orgID.String())
linkingLoginFlow.ID = gjson.GetBytes(body, "id").String()
linkingLoginFlow.UIAction = gjson.GetBytes(body, "ui.action").String()
linkingLoginFlow.CSRFToken = gjson.GetBytes(body, `ui.nodes.#(attributes.name=="csrf_token").attributes.value`).String()
Expand Down

0 comments on commit 0c48ad1

Please sign in to comment.