Skip to content

Commit e9fe44b

Browse files
authored
add hook to customize audience restriction validation (crewjam#596)
based on the concept in crewjam#495
1 parent 90a401b commit e9fe44b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

service_provider.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ type ServiceProvider struct {
137137
// LogoutBindings specify the bindings available for SLO endpoint. If empty,
138138
// HTTP-POST binding is used.
139139
LogoutBindings []string
140+
141+
// ValidateAudienceRestriction allows you to override the default audience validation
142+
// for an assertion. If nil, the default audience validation is used.
143+
ValidateAudienceRestriction func(assertion *Assertion) error
140144
}
141145

142146
// MaxIssueDelay is the longest allowed time between when a SAML assertion is
@@ -1172,6 +1176,20 @@ func (sp *ServiceProvider) validateAssertion(assertion *Assertion, possibleReque
11721176
return fmt.Errorf("assertion Conditions is expired")
11731177
}
11741178

1179+
if err := sp.validateAudienceRestriction(assertion); err != nil {
1180+
return err
1181+
}
1182+
return nil
1183+
}
1184+
1185+
func (sp *ServiceProvider) validateAudienceRestriction(assertion *Assertion) error {
1186+
if sp.ValidateAudienceRestriction != nil {
1187+
if err := sp.ValidateAudienceRestriction(assertion); err != nil {
1188+
return fmt.Errorf("audience restriction validation failed: %w", err)
1189+
}
1190+
return nil
1191+
}
1192+
11751193
audienceRestrictionsValid := len(assertion.Conditions.AudienceRestrictions) == 0
11761194
audience := firstSet(sp.EntityID, sp.MetadataURL.String())
11771195
for _, audienceRestriction := range assertion.Conditions.AudienceRestrictions {

0 commit comments

Comments
 (0)