1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
//! `saml-rs` - SAML 2.0 Service Provider and Identity Provider support.
//!
//! # Start here
//!
//! Start new browser SSO/SLO integrations with [`Saml`]. The typed facade keeps
//! local role state in [`Saml<Sp>`] or [`Saml<Idp>`], accepts peer metadata
//! through typed descriptors, and returns pending transaction values that
//! callers can store with browser session state.
//!
//! The dependency-free config builders use strict typed defaults. Opt into
//! compatibility policy by name when a legacy peer requires unsigned protocol
//! messages.
//! Where the compact flow examples below use
//! [`ReplayPolicy::DisabledForCompatibility`] or unsigned metadata, treat those
//! as explicit interoperability choices. Production-shaped inbound flows should
//! use [`ReplayPolicy::RequireCache`] with a caller-owned [`ReplayCache`] and,
//! when protocol timestamps are not enough for expiry,
//! [`SamlValidationContext::with_replay_retention`].
//!
//! ```
//! use saml_rs::{AcsEndpoint, EntityId, SpConfig, SpValidationPolicy};
//!
//! # fn main() -> Result<(), saml_rs::SamlError> {
//! let config = SpConfig::builder(EntityId::try_new("https://sp.example.com/metadata")?)
//! .acs_endpoint(AcsEndpoint::post("https://sp.example.com/acs")?)
//! .validation(SpValidationPolicy::compatibility())
//! .build()?;
//!
//! assert_eq!(config.entity_id.as_str(), "https://sp.example.com/metadata");
//! # Ok(()) }
//! ```
//!
//! # SP-initiated SSO
//!
//! [`Saml<Sp>::start_sso`] creates the browser action and [`PendingAuthnRequest`].
//! Store the pending value and pass it back to [`Saml<Sp>::finish_sso`] when the
//! ACS endpoint receives the SAML response.
//!
//! ```no_run
//! use saml_rs::{
//! AcsEndpoint, BrowserInput, EntityId, FormField, IdpDescriptor,
//! MetadataTrustPolicy, ReplayPolicy, Saml, SamlValidationContext, SpConfig,
//! SpValidationPolicy, SsoResponse, StartSso,
//! };
//! use time::OffsetDateTime;
//!
//! # fn run(
//! # idp_metadata_xml: &str,
//! # form_fields: Vec<FormField>,
//! # ) -> Result<(), saml_rs::SamlError> {
//! let sp = Saml::sp(
//! SpConfig::builder(EntityId::try_new("https://sp.example.com/metadata")?)
//! .acs_endpoint(AcsEndpoint::post("https://sp.example.com/acs")?)
//! .validation(SpValidationPolicy::compatibility())
//! .build()?,
//! )?;
//! let idp = IdpDescriptor::from_metadata_xml_for(
//! EntityId::try_new("https://idp.example.com/metadata")?,
//! idp_metadata_xml,
//! MetadataTrustPolicy::UnsignedForCompatibility,
//! )?;
//!
//! let started = sp.start_sso(&idp, StartSso::redirect())?;
//! let redirect_url = started.outbound.redirect_url()?;
//! # let _ = redirect_url;
//!
//! let validation = SamlValidationContext::new(
//! OffsetDateTime::now_utc(),
//! ReplayPolicy::DisabledForCompatibility,
//! );
//! let session = sp.finish_sso(
//! &idp,
//! &started.pending,
//! BrowserInput::<SsoResponse>::post(form_fields),
//! validation,
//! )?;
//! let name_id = session.name_id().value();
//! # let _ = name_id;
//! # Ok(()) }
//! ```
//!
//! # IdP-initiated SSO
//!
//! Use [`Saml<Sp>::accept_unsolicited_sso`] for IdP-initiated responses. This
//! method is separate from `finish_sso` so unsolicited responses are an explicit
//! caller choice rather than a missing pending request.
//!
//! ```no_run
//! use saml_rs::{
//! BrowserInput, FormField, IdpDescriptor, ReplayPolicy, Saml,
//! SamlValidationContext, SsoResponse,
//! };
//! use time::OffsetDateTime;
//!
//! # fn accept(
//! # sp: &Saml<saml_rs::Sp>,
//! # idp: &IdpDescriptor,
//! # form_fields: Vec<FormField>,
//! # ) -> Result<(), saml_rs::SamlError> {
//! let validation = SamlValidationContext::new(
//! OffsetDateTime::now_utc(),
//! ReplayPolicy::DisabledForCompatibility,
//! );
//! let session = sp.accept_unsolicited_sso(
//! idp,
//! BrowserInput::<SsoResponse>::post(form_fields),
//! validation,
//! )?;
//! let issuer = session.issuer().as_str();
//! # let _ = issuer;
//! # Ok(()) }
//! ```
//!
//! # Identity Provider flows
//!
//! [`Saml<Idp>::receive_sso`] parses an SP `AuthnRequest`; [`Saml<Idp>::respond_sso`]
//! returns the typed browser response.
//!
//! ```no_run
//! use saml_rs::{
//! AuthnRequest, BrowserInput, FormField, NameId, ReplayPolicy, RespondSso,
//! Saml, SamlValidationContext, SpDescriptor, Subject,
//! };
//! use time::OffsetDateTime;
//!
//! # fn respond(
//! # idp: &Saml<saml_rs::Idp>,
//! # sp: &SpDescriptor,
//! # request_fields: Vec<FormField>,
//! # ) -> Result<(), saml_rs::SamlError> {
//! let validation = SamlValidationContext::new(
//! OffsetDateTime::now_utc(),
//! ReplayPolicy::DisabledForCompatibility,
//! );
//! let request = idp.receive_sso(
//! sp,
//! BrowserInput::<AuthnRequest>::post(request_fields),
//! validation,
//! )?;
//! let response = idp.respond_sso(
//! sp,
//! &request,
//! Subject::new(NameId::new("alice@example.com", None), Vec::new()),
//! RespondSso::post(),
//! )?;
//! let form = response.post_form()?;
//! # let _ = form;
//! # Ok(()) }
//! ```
//!
//! # Single Logout
//!
//! Typed SLO uses the same pattern: start with a [`LogoutSubject`], store the
//! returned [`PendingLogoutRequest`], and finish only with the matching
//! [`LogoutResponse`]. Receiving and responding to peer-initiated logout uses
//! [`Received<LogoutRequest>`] instead of free-form request ID strings.
//!
//! ```no_run
//! use saml_rs::{
//! BrowserInput, FormField, IdpDescriptor, LogoutResponse, ReplayPolicy,
//! Saml, SamlValidationContext, SsoSession, StartSlo,
//! };
//! use time::OffsetDateTime;
//!
//! # fn logout(
//! # sp: &Saml<saml_rs::Sp>,
//! # idp: &IdpDescriptor,
//! # session: &SsoSession,
//! # response_fields: Vec<FormField>,
//! # ) -> Result<(), saml_rs::SamlError> {
//! if let Some(subject) = session.logout_subject() {
//! let started = sp.start_slo(idp, subject, StartSlo::post())?;
//! let validation = SamlValidationContext::new(
//! OffsetDateTime::now_utc(),
//! ReplayPolicy::DisabledForCompatibility,
//! );
//! let completed = sp.finish_slo(
//! idp,
//! &started.pending,
//! BrowserInput::<LogoutResponse>::post(response_fields),
//! validation,
//! )?;
//! let peer = completed.peer_entity_id().as_str();
//! # let _ = peer;
//! }
//! # Ok(()) }
//! ```
//!
//! # Compile-time flow boundaries
//!
//! SSO and SLO pending values are different types. A logout pending value cannot
//! be used to finish Web SSO:
//!
//! ```compile_fail
//! use saml_rs::{
//! BrowserInput, IdpDescriptor, PendingLogoutRequest, Saml,
//! SamlValidationContext, SsoResponse,
//! };
//!
//! fn wrong(
//! sp: &Saml<saml_rs::Sp>,
//! idp: &IdpDescriptor,
//! pending: &PendingLogoutRequest,
//! input: BrowserInput<SsoResponse>,
//! validation: SamlValidationContext<'_>,
//! ) -> Result<(), saml_rs::SamlError> {
//! let _ = sp.finish_sso(idp, pending, input, validation)?;
//! Ok(())
//! }
//! ```
//!
//! SLO responses are correlated through [`Received<LogoutRequest>`], not
//! arbitrary request ID strings:
//!
//! ```compile_fail
//! use saml_rs::{RespondSlo, Saml, SpDescriptor};
//!
//! fn wrong(
//! idp: &Saml<saml_rs::Idp>,
//! sp: &SpDescriptor,
//! request_id: &str,
//! ) -> Result<(), saml_rs::SamlError> {
//! let _ = idp.respond_slo(sp, request_id, RespondSlo::post())?;
//! Ok(())
//! }
//! ```
//!
//! # Metadata trust
//!
//! Metadata trust is explicit and caller-pinned. [`MetadataTrustPolicy`] can
//! accept unsigned metadata for explicit legacy compatibility or require a
//! signature from caller-provided certificates with
//! [`MetadataTrustPolicy::RequireSignature`]. Prefer signed metadata with pinned
//! certificates for production trust decisions; the crate does not treat the
//! public web PKI CA store as SAML metadata trust.
//!
//! # Raw compatibility API
//!
//! The [`raw`] module contains the low-level compatibility API and protocol
//! helpers. Advanced callers should import [`raw::ServiceProvider`],
//! [`raw::IdentityProvider`], [`raw::HttpRequest`], and [`raw::BindingContext`]
//! from there rather than using root compatibility exports.
//!
//! Visible docs.rs modules and crate-root re-exports are the supported public
//! documentation surface. The [`raw`] module is supported for compatibility;
//! hidden modules are lower-level implementation or compatibility paths and
//! should not be the first choice for new integrations.
//!
//! # Unsupported profiles
//!
//! The high-level [`Saml`] API focuses on browser Web SSO, metadata-driven SP/IdP
//! setup, XML signature/encryption through `bergshamra`, and Single Logout. It
//! does not yet implement Artifact resolution, SOAP/back-channel profiles,
//! ECP/PAOS, SAML query protocols, NameID management, or metadata federation. If
//! you need one of those profiles for a real interoperability target, please
//! open an issue with the profile, binding, IdP/SP product, and a minimal
//! expected flow so we can consider the implementation.
//!
//! XML cryptography (XML-DSig sign/verify with anti-wrapping, XML-Enc, detached
//! message signatures) is delegated to `bergshamra` behind the
//! `crypto-bergshamra` feature, which is on by default. Configure assertion
//! encryption and XML-Enc compatibility exceptions through [`XmlEncryptionPolicy`].
//! Disable default features to build the crypto-free protocol layer; crypto
//! operations then fail closed with [`SamlError::Unsupported`].
pub use ;
pub use ;
pub use ;
pub use EntitySetting;
pub use IdentityProvider;
pub use MetadataSignatureVerification;
pub use ;
pub use ServiceProvider;