// Copyright (c) Tribufu. All Rights Reserved. use serde::{Deserialize, Serialize}; #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum OAuth2ResponseType { Code, Token, } #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum OAuth2ClientType { Confidential, Public, } #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum OAuth2TokenHintType { AccessToken, RefreshToken, } #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum OAuth2GrantType { AuthorizationCode, ClientCredentials, DeviceCode, Passkey, Password, RefreshToken, } #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum OAuth2AuthorizeError { AccessDenied, InvalidRequest, InvalidScope, ServerError, TemporarilyUnavailable, UnauthorizedClient, UnsupportedResponseType, } #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum OAuth2TokenType { Bearer, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct OAuth2AuthorizeRequest { pub response_type: OAuth2ResponseType, pub client_id: String, pub client_secret: Option, pub redirect_uri: String, pub scope: Option, pub state: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct OAuth2CodeResponse { pub code: String, #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct OAuth2ErrorResponse { pub error: OAuth2AuthorizeError, #[serde(skip_serializing_if = "Option::is_none")] pub error_description: Option, #[serde(skip_serializing_if = "Option::is_none")] pub error_uri: Option, #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct OAuth2TokenRequest { pub grant_type: OAuth2GrantType, #[serde(skip_serializing_if = "Option::is_none")] pub code: Option, #[serde(skip_serializing_if = "Option::is_none")] pub refresh_token: Option, #[serde(skip_serializing_if = "Option::is_none")] pub username: Option, #[serde(skip_serializing_if = "Option::is_none")] pub password: Option, #[serde(skip_serializing_if = "Option::is_none")] pub passkey: Option, #[serde(skip_serializing_if = "Option::is_none")] pub client_id: Option, #[serde(skip_serializing_if = "Option::is_none")] pub client_secret: Option, #[serde(skip_serializing_if = "Option::is_none")] pub redirect_uri: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct OAuth2TokenResponse { pub token_type: OAuth2TokenType, pub access_token: String, #[serde(skip_serializing_if = "Option::is_none")] pub refresh_token: Option, #[serde(skip_serializing_if = "Option::is_none")] pub scope: Option, #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, pub expires_in: u64, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct OAuth2RevokeRequest { pub token: String, pub token_type_hint: OAuth2TokenHintType, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct OAuth2IntrospectionResponse { pub active: bool, #[serde(skip_serializing_if = "Option::is_none")] pub client_id: Option, #[serde(skip_serializing_if = "Option::is_none")] pub username: Option, #[serde(skip_serializing_if = "Option::is_none")] pub scope: Option, #[serde(skip_serializing_if = "Option::is_none")] pub exp: Option, } impl OAuth2IntrospectionResponse { pub fn inative() -> Self { Self { active: false, client_id: None, username: None, scope: None, exp: None, } } }