Trait stud_ip_scraper::IdentityProvider
source · pub trait IdentityProvider {
// Required methods
fn login(
client: &Client,
url: impl IntoUrl,
username: &str,
password: &str
) -> Result<SAMLAssertionData>;
fn entity_url() -> &'static str;
}
Expand description
An Identity Provider is required to log in via SSO
This is required as the login specifics might be drastically different for every institution. Currently, this crate does not provide a specific Identity provider, meaning you will have to implement one yourself for your specific Educational institutions.
Here is how an example provider could be defined:
use stud_ip_scraper::{IdentityProvider, SAMLAssertionData};
use reqwest::blocking::Client;
use anyhow::{bail, Context};
struct ExampleIdP;
impl IdentityProvider for ExampleIdP {
fn login(client: &Client, redirect_url: impl reqwest::IntoUrl, username: &str, password: &str) -> anyhow::Result<SAMLAssertionData> {
// Send credentials
let response = client.post(redirect_url)
.form(&[("username", username), ("password", password)])
.send()?;
if response.status() != 200 {
bail!("Could not login. Are the credentials incorrect?");
}
// Parse out Assertion data from response
// NOTE: This will probably be more involved for an actual IdP
let text = response.text()?;
let (relay_state, saml_response) = text
.split_once("\n")
.context("Could not parse SAML assertion data")?;
Ok(SAMLAssertionData {
relay_state: relay_state.to_string(),
saml_response: saml_response.to_string(),
})
}
fn entity_url() -> &'static str {
"https://sso.example.com/idp/shibboleth"
}
}
Required Methods§
sourcefn login(
client: &Client,
url: impl IntoUrl,
username: &str,
password: &str
) -> Result<SAMLAssertionData>
fn login( client: &Client, url: impl IntoUrl, username: &str, password: &str ) -> Result<SAMLAssertionData>
Attempts to Log in the client with a username and password.
Also accepts a url
, that is derived from the IdentityProvider::entity_url()
, but with potentially more data, from the Service Provider
Returns the SAMLAssertionData
, if successful.
sourcefn entity_url() -> &'static str
fn entity_url() -> &'static str
The entity url of the Identify Provider, also sometimes called entityID
Object Safety§
This trait is not object safe.