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: add context param to policy #4315

Merged
merged 1 commit into from
Feb 20, 2025
Merged
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
9 changes: 5 additions & 4 deletions selfservice/strategy/oidc/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@
handleUnknownProviderError func(err error) error
handleMethodNotAllowedError func(err error) error

conflictingIdentityPolicy func(existingIdentity, newIdentity *identity.Identity, provider Provider, claims *Claims) ConflictingIdentityVerdict
conflictingIdentityPolicy ConflictingIdentityPolicy
}
type ConflictingIdentityPolicy func(ctx context.Context, existingIdentity, newIdentity *identity.Identity, provider Provider, claims *Claims) ConflictingIdentityVerdict

type AuthCodeContainer struct {
FlowID string `json:"flow_id"`
Expand Down Expand Up @@ -246,14 +247,14 @@

// WithOnConflictingIdentity sets a policy handler for deciding what to do when a
// new identity conflicts with an existing one during login.
func WithOnConflictingIdentity(handler func(existingIdentity, newIdentity *identity.Identity, provider Provider, claims *Claims) ConflictingIdentityVerdict) NewStrategyOpt {
func WithOnConflictingIdentity(handler ConflictingIdentityPolicy) NewStrategyOpt {

Check warning on line 250 in selfservice/strategy/oidc/strategy.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/strategy.go#L250

Added line #L250 was not covered by tests
return func(s *Strategy) { s.conflictingIdentityPolicy = handler }
}

// SetOnConflictingIdentity sets a policy handler for deciding what to do when a
// new identity conflicts with an existing one during login. This should only be
// called in tests.
func (s *Strategy) SetOnConflictingIdentity(t testing.TB, handler func(existingIdentity, newIdentity *identity.Identity, provider Provider, claims *Claims) ConflictingIdentityVerdict) {
func (s *Strategy) SetOnConflictingIdentity(t testing.TB, handler ConflictingIdentityPolicy) {
if t == nil {
panic("this should only be called in tests")
}
Expand Down Expand Up @@ -774,7 +775,7 @@
return node.OpenIDConnectGroup
}

func (s *Strategy) CompletedAuthenticationMethod(ctx context.Context) session.AuthenticationMethod {
func (s *Strategy) CompletedAuthenticationMethod(context.Context) session.AuthenticationMethod {
return session.AuthenticationMethod{
Method: s.ID(),
AAL: identity.AuthenticatorAssuranceLevel1,
Expand Down
6 changes: 3 additions & 3 deletions selfservice/strategy/oidc/strategy_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
return ConflictingIdentityVerdictReject, nil, nil, nil
}

verdict = s.conflictingIdentityPolicy(existingIdentity, newIdentity, provider, claims)
verdict = s.conflictingIdentityPolicy(ctx, existingIdentity, newIdentity, provider, claims)
if verdict == ConflictingIdentityVerdictMerge {
existingIdentity.SetCredentials(s.ID(), *creds)
if err := s.d.PrivilegedIdentityPool().UpdateIdentity(ctx, existingIdentity); err != nil {
Expand Down Expand Up @@ -392,11 +392,11 @@
return s.populateMethod(r, f, text.NewInfoLoginWith)
}

func (s *Strategy) PopulateLoginMethodSecondFactor(r *http.Request, sr *login.Flow) error {
func (s *Strategy) PopulateLoginMethodSecondFactor(*http.Request, *login.Flow) error {
return nil
}

func (s *Strategy) PopulateLoginMethodSecondFactorRefresh(r *http.Request, sr *login.Flow) error {
func (s *Strategy) PopulateLoginMethodSecondFactorRefresh(*http.Request, *login.Flow) error {

Check warning on line 399 in selfservice/strategy/oidc/strategy_login.go

View check run for this annotation

Codecov / codecov/patch

selfservice/strategy/oidc/strategy_login.go#L399

Added line #L399 was not covered by tests
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion selfservice/strategy/oidc/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ func TestStrategy(t *testing.T) {
scope = []string{"openid"}

reg.AllLoginStrategies().MustStrategy("oidc").(*oidc.Strategy).SetOnConflictingIdentity(t,
func(existingIdentity, newIdentity *identity.Identity, _ oidc.Provider, _ *oidc.Claims) oidc.ConflictingIdentityVerdict {
func(ctx context.Context, existingIdentity, newIdentity *identity.Identity, _ oidc.Provider, _ *oidc.Claims) oidc.ConflictingIdentityVerdict {
return oidc.ConflictingIdentityVerdictMerge
})

Expand Down
Loading