use std::sync::LazyLock;
use url::Url;
#[cfg(any(feature = "microsoft", doc))]
pub mod microsoft;
pub trait Provider {
fn auth_uri(&self) -> &Url;
fn token_uri(&self) -> &Url;
fn credentials_in_body(&self) -> bool {
false
}
}
pub mod google {
use std::sync::LazyLock;
use url::Url;
use super::Provider;
pub const REDIRECT_URI_OOB: &str = "urn:ietf:wg:oauth:2.0:oob";
pub const REDIRECT_URI_OOB_AUTO: &str = "urn:ietf:wg:oauth:2.0:oob:auto";
static AUTH_URI: LazyLock<Url> =
LazyLock::new(|| Url::parse("https://accounts.google.com/o/oauth2/v2/auth").unwrap());
static TOKEN_URI: LazyLock<Url> =
LazyLock::new(|| Url::parse("https://www.googleapis.com/oauth2/v4/token").unwrap());
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Web;
impl Provider for Web {
fn auth_uri(&self) -> &Url {
&AUTH_URI
}
fn token_uri(&self) -> &Url {
&TOKEN_URI
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Installed;
impl Provider for Installed {
fn auth_uri(&self) -> &Url {
&AUTH_URI
}
fn token_uri(&self) -> &Url {
&TOKEN_URI
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct GitHub;
impl Provider for GitHub {
fn auth_uri(&self) -> &Url {
static GITHUB_AUTH_URI: LazyLock<Url> =
LazyLock::new(|| Url::parse("https://github.com/login/oauth/authorize").unwrap());
&GITHUB_AUTH_URI
}
fn token_uri(&self) -> &Url {
static GITHUB_TOKEN_URI: LazyLock<Url> =
LazyLock::new(|| Url::parse("https://github.com/login/oauth/access_token").unwrap());
&GITHUB_TOKEN_URI
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Imgur;
impl Provider for Imgur {
fn auth_uri(&self) -> &Url {
static IMGUR_AUTH_URI: LazyLock<Url> =
LazyLock::new(|| Url::parse("https://api.imgur.com/oauth2/authorize").unwrap());
&IMGUR_AUTH_URI
}
fn token_uri(&self) -> &Url {
static IMGUR_TOKEN_URI: LazyLock<Url> =
LazyLock::new(|| Url::parse("https://api.imgur.com/oauth2/token").unwrap());
&IMGUR_TOKEN_URI
}
}
#[test]
fn google_urls() {
let prov = google::Web;
prov.auth_uri();
prov.token_uri();
let prov = google::Installed;
prov.auth_uri();
prov.token_uri();
}
#[test]
fn github_urls() {
let prov = GitHub;
prov.auth_uri();
prov.token_uri();
}
#[test]
fn imgur_urls() {
let prov = Imgur;
prov.auth_uri();
prov.token_uri();
}