pub enum RelayStateParam {
Absent,
PresentEmpty,
PresentValue(RelayState),
}Expand description
RelayState represented as absent, present empty, or present with a value.
Variants§
Absent
No RelayState parameter was sent.
PresentEmpty
RelayState was sent with an empty value.
PresentValue(RelayState)
RelayState was sent with a non-empty value.
Implementations§
Source§impl RelayStateParam
impl RelayStateParam
Sourcepub fn present_empty() -> Self
pub fn present_empty() -> Self
Construct a present RelayState parameter with an empty value.
Sourcepub fn try_from_option(
value: Option<impl Into<String>>,
) -> Result<Self, SamlError>
pub fn try_from_option( value: Option<impl Into<String>>, ) -> Result<Self, SamlError>
Preserve the exact RelayState presence state from optional caller input.
§Errors
Returns SamlError::Invalid when a present non-empty value exceeds
the SAML Bindings 80-byte RelayState limit.
Examples found in repository?
examples/sso.rs (line 53)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9 use saml_rs::{
10 AcsEndpoint, AuthnRequest, BrowserInput, CertificatePem, Credentials, EntityId, IdpConfig,
11 IdpDescriptor, IdpValidationPolicy, MetadataTrustPolicy, NameId, PrivateKeyPem,
12 RelayStateParam, ReplayPolicy, RespondSso, Saml, SamlValidationContext, SpConfig,
13 SpDescriptor, SpValidationPolicy, SsoEndpoint, SsoResponse, StartSso, Subject,
14 };
15 use std::time::SystemTime;
16
17 let privkey = include_str!("../tests/fixtures/key/sp_privkey.pem");
18 let cert = include_str!("../tests/fixtures/key/sp_signing_cert.cer");
19 let credentials = || Credentials {
20 signing_key: Some(PrivateKeyPem::new(privkey)),
21 signing_certificate: Some(CertificatePem::new(cert)),
22 ..Credentials::default()
23 };
24 let validation =
25 || SamlValidationContext::new(SystemTime::now(), ReplayPolicy::DisabledForCompatibility);
26
27 let sp = Saml::sp(
28 SpConfig::builder(EntityId::try_new("https://sp.example.com/metadata")?)
29 .acs_endpoint(AcsEndpoint::post("https://sp.example.com/acs")?)
30 .credentials(credentials())
31 .validation(SpValidationPolicy::strict())
32 .build()?,
33 )?;
34 let idp = Saml::idp(
35 IdpConfig::builder(EntityId::try_new("https://idp.example.com/metadata")?)
36 .sso_endpoint(SsoEndpoint::post("https://idp.example.com/sso")?)
37 .credentials(credentials())
38 .validation(IdpValidationPolicy::strict())
39 .build()?,
40 )?;
41
42 let sp_descriptor = SpDescriptor::from_metadata_xml_for(
43 EntityId::try_new("https://sp.example.com/metadata")?,
44 sp.metadata_xml(),
45 MetadataTrustPolicy::UnsignedForCompatibility,
46 )?;
47 let idp_descriptor = IdpDescriptor::from_metadata_xml_for(
48 EntityId::try_new("https://idp.example.com/metadata")?,
49 idp.metadata_xml(),
50 MetadataTrustPolicy::UnsignedForCompatibility,
51 )?;
52
53 let relay_state = RelayStateParam::try_from_option(Some("demo-state".to_string()))?;
54 let started = sp.start_sso(&idp_descriptor, StartSso::post().relay_state(relay_state))?;
55 println!(
56 "SP -> AuthnRequest id = {}",
57 started.pending.request_id().as_str()
58 );
59
60 let request = idp.receive_sso(
61 &sp_descriptor,
62 BrowserInput::<AuthnRequest>::post(started.outbound.post_form()?.fields().to_vec()),
63 validation(),
64 )?;
65 println!(
66 "IdP <- request issuer = {}",
67 request.message().issuer().as_str()
68 );
69
70 let response = idp.respond_sso(
71 &sp_descriptor,
72 &request,
73 Subject::new(NameId::new("alice@example.com", None), Vec::new()),
74 RespondSso::post(),
75 )?;
76
77 let session = sp.finish_sso(
78 &idp_descriptor,
79 &started.pending,
80 BrowserInput::<SsoResponse>::post(response.post_form()?.fields().to_vec()),
81 validation(),
82 );
83 let session = session?;
84 println!("SP <- authenticated = {}", session.name_id().value());
85 Ok(())
86}Trait Implementations§
Source§impl Clone for RelayStateParam
impl Clone for RelayStateParam
Source§fn clone(&self) -> RelayStateParam
fn clone(&self) -> RelayStateParam
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RelayStateParam
impl Debug for RelayStateParam
impl Eq for RelayStateParam
Source§impl Hash for RelayStateParam
impl Hash for RelayStateParam
Source§impl PartialEq for RelayStateParam
impl PartialEq for RelayStateParam
impl StructuralPartialEq for RelayStateParam
Auto Trait Implementations§
impl Freeze for RelayStateParam
impl RefUnwindSafe for RelayStateParam
impl Send for RelayStateParam
impl Sync for RelayStateParam
impl Unpin for RelayStateParam
impl UnsafeUnpin for RelayStateParam
impl UnwindSafe for RelayStateParam
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more