unilim-cas 1.0.1

A purrfect CAS authentication wrapper for Unilim.
Documentation
use super::CAS;
use crate::Error;
use crate::native;
use wasm_bindgen::prelude::*;

/// in-progress authentication awaiting a 2fa challenge.
#[wasm_bindgen]
pub struct PendingAuth {
    inner: native::PendingAuth,
}

impl From<native::PendingAuth> for PendingAuth {
    fn from(inner: native::PendingAuth) -> Self {
        Self { inner }
    }
}

#[wasm_bindgen]
impl PendingAuth {
    #[wasm_bindgen(getter)]
    pub fn solved(&self) -> bool {
        self.inner.solved
    }

    #[wasm_bindgen(getter, js_name = "isEmailAvailable")]
    pub fn is_email_available(&self) -> bool {
        self.inner.is_email_available
    }

    #[wasm_bindgen(getter, js_name = "isTotpAvailable")]
    pub fn is_totp_available(&self) -> bool {
        self.inner.is_totp_available
    }

    /// request an email code by selecting the `mail` 2fa method.
    #[wasm_bindgen(js_name = "sendEmailCode")]
    pub async fn send_email_code(&mut self) -> Result<(), Error> {
        self.inner.send_email_code().await
    }

    /// solve the challenge with an email code.
    #[wasm_bindgen(js_name = "solveWithEmailCode")]
    pub async fn solve_with_email_code(&mut self, code: String) -> Result<(), Error> {
        self.inner.solve_with_email_code(&code).await
    }

    /// solve the challenge with a totp code.
    #[wasm_bindgen(js_name = "solveWithTotp")]
    pub async fn solve_with_totp(&mut self, totp: String) -> Result<(), Error> {
        self.inner.solve_with_totp(&totp).await
    }

    /// register the browser to enable persistence and return the established
    /// session.
    pub async fn finish(&mut self) -> Result<CAS, Error> {
        self.inner.finish().await.map(CAS::from)
    }
}