use chrono::DateTime;
use chrono::Utc;
use url::Url;
use std::borrow::Cow;
type Time = DateTime<Utc>;
pub struct NegotiationParameter<'a> {
pub client_id: Cow<'a, str>,
pub redirect_url: Cow<'a, Url>,
pub scope: Option<Cow<'a, Scope>>,
}
pub struct Negotiated<'a> {
pub client_id: Cow<'a, str>,
pub scope: Cow<'a, Scope>,
pub redirect_url: Url,
}
pub struct Request<'a> {
pub owner_id: &'a str,
pub client_id: &'a str,
pub redirect_url: &'a Url,
pub scope: &'a Scope,
}
pub struct Grant<'a> {
pub owner_id: Cow<'a, str>,
pub client_id: Cow<'a, str>,
pub redirect_url: Cow<'a, Url>,
pub scope: Cow<'a, Scope>,
pub until: Cow<'a, Time>,
}
#[derive(Clone, Debug)]
pub struct IssuedToken {
pub token: String,
pub refresh: String,
pub until: Time,
}
pub enum RegistrarError {
Unregistered,
MismatchedRedirect,
Error(error::AuthorizationError),
}
pub trait Registrar {
fn negotiate<'a>(&self, NegotiationParameter<'a>) -> Result<Cow<'a, Scope>, RegistrarError>;
}
pub trait Authorizer {
fn authorize(&mut self, Request) -> String;
fn extract<'a>(&mut self, &'a str) -> Option<Grant<'a>>;
}
pub trait Issuer {
fn issue(&mut self, Request) -> IssuedToken;
fn recover_token<'a>(&'a self, &'a str) -> Option<Grant<'a>>;
fn recover_refresh<'a>(&'a self, &'a str) -> Option<Grant<'a>>;
}
pub trait TokenGenerator {
fn generate(&self, &Grant) -> String;
}
pub mod authorizer;
pub mod backend;
pub mod error;
pub mod frontend;
pub mod generator;
pub mod issuer;
pub mod registrar;
mod scope;
#[cfg(test)]
mod tests;
pub use self::scope::Scope;
pub mod prelude {
pub use super::authorizer::Storage;
pub use super::backend::{CodeRef, IssuerRef, GuardRef};
pub use super::issuer::{TokenMap, TokenSigner};
pub use super::generator::RandomGenerator;
pub use super::registrar::ClientMap;
pub use super::scope::Scope;
}