mirror of
https://github.com/tribufu/sdk-rust
synced 2025-06-16 03:04:19 +00:00
168 lines
4.2 KiB
Rust
168 lines
4.2 KiB
Rust
// 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<String>,
|
|
pub redirect_uri: String,
|
|
pub scope: Option<String>,
|
|
pub state: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct OAuth2CodeResponse {
|
|
pub code: String,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub state: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct OAuth2ErrorResponse {
|
|
pub error: OAuth2AuthorizeError,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub error_description: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub error_uri: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub state: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct OAuth2TokenRequest {
|
|
pub grant_type: OAuth2GrantType,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub code: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub refresh_token: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub username: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub password: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub passkey: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub client_id: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub client_secret: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub redirect_uri: Option<String>,
|
|
}
|
|
|
|
#[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<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub scope: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub state: Option<String>,
|
|
|
|
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<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub username: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub scope: Option<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub exp: Option<i64>,
|
|
}
|
|
|
|
impl OAuth2IntrospectionResponse {
|
|
fn inative() -> Self {
|
|
Self {
|
|
active: false,
|
|
client_id: None,
|
|
username: None,
|
|
scope: None,
|
|
exp: None,
|
|
}
|
|
}
|
|
}
|