feat(auth): add base oauth client

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-08-19 16:24:08 +02:00
parent 48e9d73e6d
commit 7dcd3b4efe
Signed by: kjuulh
GPG Key ID: 9AA7BC13CE474394

View File

@ -6,19 +6,36 @@ use std::sync::Arc;
#[derive(Clone, clap::Args)] #[derive(Clone, clap::Args)]
pub struct OAuthClientClap { pub struct OAuthClientClap {
#[clap(flatten)] #[clap(flatten)]
zitadel: Option<ZitadelConfig>, zitadel: Option<ZitadelClap>,
#[clap(flatten)] #[clap(flatten)]
noop: Option<NoopConfig>, noop: Option<NoopConfig>,
} }
#[derive(Clone, clap::Args)] #[derive(Clone, clap::Args)]
#[group(conflicts_with = "ZitadelConfig")]
pub struct NoopConfig { pub struct NoopConfig {
#[clap(env = "OAUTH_NOOP", long = "oauth-noop")] #[arg(env = "OAUTH_NOOP", long = "oauth-noop", group = "auth")]
pub oauth_noop: Option<bool>, pub oauth_noop: Option<bool>,
} }
#[derive(clap::Args, Clone)]
pub struct ZitadelClap {
#[arg(env = "ZITADEL_AUTH_URL", long = "zitadel-auth-url", group = "auth")]
pub auth_url: Option<String>,
#[arg(env = "ZITADEL_CLIENT_ID", long = "zitadel-client-id")]
pub client_id: Option<String>,
#[arg(env = "ZITADEL_CLIENT_SECRET", long = "zitadel-client-secret")]
pub client_secret: Option<String>,
#[arg(env = "ZITADEL_REDIRECT_URL", long = "zitadel-redirect-url")]
pub redirect_url: Option<String>,
#[arg(env = "ZITADEL_TOKEN_URL", long = "zitadel-token-url")]
pub token_url: Option<String>,
}
#[async_trait] #[async_trait]
pub trait OAuthClient { pub trait OAuthClient {
async fn get_token(&self) -> anyhow::Result<()>; async fn get_token(&self) -> anyhow::Result<()>;
@ -77,7 +94,7 @@ impl OAuthClient for NoopOAuthClient {
// -- Zitadel // -- Zitadel
#[derive(clap::Args, Clone)] #[derive(clap::Args, Clone)]
#[group(conflicts_with = "NoopConfig")] #[group(conflicts_with = "NoopConfig", required = false)]
pub struct ZitadelConfig { pub struct ZitadelConfig {
#[clap(env = "ZITADEL_AUTH_URL", long = "zitadel-auth-url")] #[clap(env = "ZITADEL_AUTH_URL", long = "zitadel-auth-url")]
auth_url: String, auth_url: String,