use serde::{Deserialize, Serialize};
use url::Url;
#[cfg(feature = "utoipa")]
use utoipa::{IntoParams, ToSchema};
use crate::v1::types::{
application::{Application, Scope},
email::EmailAddr,
ApplicationId, User, UserId,
};
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct Autoconfig {
pub issuer: Url,
pub authorization_endpoint: Url,
pub token_endpoint: Url,
pub userinfo_endpoint: Url,
pub scopes_supported: Vec<String>,
pub response_types_supported: Vec<String>,
pub grant_types_supported: Vec<String>,
pub subject_types_supported: Vec<String>,
pub token_endpoint_auth_methods_supported: Vec<String>,
}
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct Userinfo {
pub iss: Url,
pub sub: UserId,
pub email: Option<EmailAddr>,
pub email_verified: bool,
pub name: String,
pub profile: String,
pub updated_at: u64,
pub picture: Option<Url>,
}
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct OauthAuthorizeInfo {
pub application: Application,
pub bot_user: User,
pub auth_user: User,
pub authorized: bool,
}
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema, IntoParams))]
pub struct OauthAuthorizeParams {
pub response_type: String,
pub client_id: ApplicationId,
pub scope: String,
#[allow(unused)]
pub state: Option<String>,
pub redirect_uri: Option<Url>,
#[allow(unused)]
pub prompt: Option<String>,
pub code_challenge: Option<String>,
pub code_challenge_method: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct OauthAuthorizeResponse {
pub redirect_uri: Url,
}
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct OauthTokenRequest {
pub grant_type: String,
pub code: Option<String>,
pub redirect_uri: Option<Url>,
pub client_id: Option<ApplicationId>,
pub client_secret: Option<String>,
pub refresh_token: Option<String>,
pub code_verifier: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct OauthTokenResponse {
pub access_token: String,
pub token_type: String,
pub expires_in: u64,
pub refresh_token: Option<String>,
pub scope: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "utoipa", derive(ToSchema))]
pub struct OauthIntrospectResponse {
pub active: bool,
pub scopes: Vec<Scope>,
pub client_id: ApplicationId,
pub username: UserId,
pub exp: Option<u64>,
}