use std::sync::Arc;
use crate::error::ChannelError;
use crate::transport::UpstreamClient;
pub struct AuthCodeStart {
pub authorize_url: String,
pub redirect_uri: String,
pub extra: Option<serde_json::Value>,
}
pub struct DeviceInit {
pub device_code: String,
pub user_code: String,
pub verification_url: String,
pub interval_secs: u64,
}
#[derive(Debug)]
pub enum DevicePoll {
Pending,
Ready(serde_json::Value),
Denied,
}
pub struct AuthCodeStartCtx<'a> {
pub provider_settings: &'a serde_json::Value,
pub params: &'a serde_json::Value,
pub redirect_uri: &'a str,
pub state: &'a str,
pub pkce_challenge: &'a str,
}
pub struct AuthCodeExchangeCtx<'a> {
pub provider_settings: &'a serde_json::Value,
pub code: &'a str,
pub verifier: &'a str,
pub redirect_uri: &'a str,
pub extra: Option<&'a serde_json::Value>,
}
pub struct DeviceStartCtx<'a> {
pub provider_settings: &'a serde_json::Value,
pub params: &'a serde_json::Value,
}
pub struct DevicePollCtx<'a> {
pub provider_settings: &'a serde_json::Value,
pub device_code: &'a str,
}
pub struct CookieExchangeCtx<'a> {
pub provider_settings: &'a serde_json::Value,
pub cookie: &'a str,
}
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
pub trait ChannelLogin: Send + Sync {
async fn authcode_start(
&self,
_client: &Arc<dyn UpstreamClient>,
_ctx: AuthCodeStartCtx<'_>,
) -> Result<Option<AuthCodeStart>, ChannelError> {
Ok(None)
}
async fn authcode_exchange(
&self,
_client: &Arc<dyn UpstreamClient>,
_ctx: AuthCodeExchangeCtx<'_>,
) -> Result<serde_json::Value, ChannelError> {
Err(ChannelError::Unsupported("authcode login"))
}
async fn device_start(
&self,
_client: &Arc<dyn UpstreamClient>,
_ctx: DeviceStartCtx<'_>,
) -> Result<DeviceInit, ChannelError> {
Err(ChannelError::Unsupported("device login"))
}
async fn device_poll(
&self,
_client: &Arc<dyn UpstreamClient>,
_ctx: DevicePollCtx<'_>,
) -> Result<DevicePoll, ChannelError> {
Err(ChannelError::Unsupported("device login"))
}
async fn cookie_exchange(
&self,
_client: &Arc<dyn UpstreamClient>,
_ctx: CookieExchangeCtx<'_>,
) -> Result<serde_json::Value, ChannelError> {
Err(ChannelError::Unsupported("cookie login"))
}
}