pub fn parse_authn_request(request_data: &str) -> Result<AuthnRequest, String> {
    // more examples here
    // https://developers.onelogin.com/saml/examples/authnrequest

    let mut saml_request = AuthnRequestParser::new();
    let tokenizer = xmlparser::Tokenizer::from(request_data);
    for token in tokenizer {
        match token {
            Ok(token_value) => {
                saml_request = match token_value {
                    Token::Attribute {
                        prefix: _,
                        local,
                        value,
                        span: _,
                    } => match parse_authn_tokenizer_attribute(local, value, saml_request) {
                        Ok(value) => value,
                        Err(error) => {
                            return Err(format!("Failed to parse authn request: {:?}", error))
                        }
                    },
                    Token::ElementStart {
                        prefix: _,
                        local,
                        span: _,
                    } => parse_authn_tokenizer_element_start(local, saml_request),
                    Token::Text { text } => {
                        // if issuer_state == -1 { continue }
                        if saml_request.issuer_state == 1 {
                            let issuer = text.as_str();
                            debug!("Found issuer: {}", issuer);
                            saml_request.issuer = Some(issuer.to_string());
                            saml_request.issuer_state = -1; // reset the state machine so we don't try and do this again
                        } else {
                            debug!(
                                "Found issuer text and not at issuer_state==1 ({}) text={:?}",
                                saml_request.issuer_state, text
                            );
                        }
                        saml_request
                    }
                    _ => saml_request,
                };
            }
            Err(ref error) => {
                return Err(format!(
                    "Error parsing token: {:?}\n{:?}",
                    error, request_data
                ));
            }
        }
    }

    println!("found relay_state={:?}", &saml_request.relay_state);
    Ok(AuthnRequest::from(saml_request))
}
/// Give it a string full of XML and it'll give you back a [AuthnRequest] object which has the details
Give it a string full of XML and it'll give you back a [AuthnRequest] object which has the details
Give it a string full of XML and it ' ll give you back a [ AuthnRequest ] object which has the details
pub fn parse_authn_request(request_data: &str) -> Result<AuthnRequest, String> {
    // more examples here
    // https://developers.onelogin.com/saml/examples/authnrequest
    let mut saml_request = AuthnRequestParser::new();
    let tokenizer = xmlparser::Tokenizer::from(request_data);
    for token in tokenizer {
        match token {
            Ok(token_value) => {
                saml_request = match token_value {
                    Token::Attribute {
                        prefix: _,
                        local,
                        value,
                        span: _,
                    } => match parse_authn_tokenizer_attribute(local, value, saml_request) {
                        Ok(value) => value,
                        Err(error) => {
                            return Err(format!("Failed to parse authn request: {:?}", error))
                        }
                    },
                    Token::ElementStart {
                        prefix: _,
                        local,
                        span: _,
                    } => parse_authn_tokenizer_element_start(local, saml_request),
                    Token::Text { text } => {
                        // if issuer_state == -1 { continue }
                        if saml_request.issuer_state == 1 {
                            let issuer = text.as_str();
                            debug!("Found issuer: {}", issuer);
                            saml_request.issuer = Some(issuer.to_string());
                            saml_request.issuer_state = -1; // reset the state machine so we don't try and do this again
                        } else {
                            debug!(
                                "Found issuer text and not at issuer_state==1 ({}) text={:?}",
                                saml_request.issuer_state, text
                            );
                        }
                        saml_request
                    }
                    _ => saml_request,
                };
            }
            Err(ref error) => {
                return Err(format!(
                    "Error parsing token: {:?}\n{:?}",
                    error, request_data
                ));
            }
        }
    }
    println!("found relay_state={:?}", &saml_request.relay_state);
    Ok(AuthnRequest::from(saml_request))
}
pub fn parse_authn_request ( request_data : & str ) -> Result < AuthnRequest , String > { // more examples here // https://developers.onelogin.com/saml/examples/authnrequest let mut saml_request = AuthnRequestParser :: new ( ) ; let tokenizer = xmlparser :: Tokenizer :: from ( request_data ) ; for token in tokenizer { match token { Ok ( token_value ) => { saml_request = match token_value { Token :: Attribute { prefix : _ , local , value , span : _ , } => match parse_authn_tokenizer_attribute ( local , value , saml_request ) { Ok ( value ) => value , Err ( error ) => { return Err ( format ! ( " " error ) ) } } , Token :: ElementStart { prefix : _ , local , span : _ , } => parse_authn_tokenizer_element_start ( local , saml_request ) , Token :: Text { text } => { // if issuer_state == -1 { continue } if saml_request . issuer_state == 1 { let issuer = text . as_str ( ) ; debug ! ( " " issuer ) ; saml_request . issuer = Some ( issuer . to_string ( ) ) ; saml_request . issuer_state = - 1 ; // reset the state machine so we don't try and do this again } else { debug ! ( " " saml_request issuer_state text ) ; } saml_request } _ => saml_request , } ; } Err ( ref error ) => { return Err ( format ! ( " \n " error request_data ) ) ; } } } println ! ( " " saml_request relay_state ) ; Ok ( AuthnRequest :: from ( saml_request ) ) }
Give it a string full of XML and it'll give you back a [AuthnRequest] object which has the details
Give it a string full of XML and it ' ll give you back a [ AuthnRequest ] object which has the details
request_data
&str
request_data
&str