Skip to content

Commit

Permalink
Do not send NameIDPolicy with a blank Format (#53)
Browse files Browse the repository at this point in the history
* Do not send NameIDPolicy with a blank Format

Previously, if the `name_id_format` function returned None, this would
cause `NameIdPolicy` to have None as a format, leading to the following
tag in an AuthnRequest:

```xml
<saml2p:NameIDPolicy AllowCreate="true"/>
```

Skip creating a `Some(NameIDPolicy)` if `name_id_format` returns `None`.

Additionally, do not override if `authn_name_id_format` is set to
`Unspecified`: previously this would cause `name_id_format` to return
`None` where a caller explicitly set it to `Unspecified`.

* fmt
  • Loading branch information
jmpesp authored May 29, 2024
1 parent 1a6ad0f commit d5d0fff
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/service_provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,8 @@ impl ServiceProvider {
self.authn_name_id_format
.clone()
.and_then(|v| -> Option<String> {
let unspecified = NameIdFormat::UnspecifiedNameIDFormat.value();
if v.is_empty() {
Some(NameIdFormat::TransientNameIDFormat.value().to_string())
} else if v == unspecified {
None
} else {
Some(v)
}
Expand Down Expand Up @@ -478,9 +475,9 @@ impl ServiceProvider {
value: entity_id,
..Issuer::default()
}),
name_id_policy: Some(NameIdPolicy {
name_id_policy: self.name_id_format().map(|format| NameIdPolicy {
allow_create: Some(true),
format: self.name_id_format(),
format: Some(format),
..NameIdPolicy::default()
}),
force_authn: Some(self.force_authn),
Expand Down

0 comments on commit d5d0fff

Please sign in to comment.