1use crate::api::{ApiResponse, ApiState};
12use axum::{
13 Json,
14 extract::{Query, State},
15 http::{HeaderMap, StatusCode},
16 response::{IntoResponse, Response},
17};
18use serde::{Deserialize, Serialize};
19
20#[derive(Debug, Deserialize)]
22pub struct AuthorizeRequest {
23 pub response_type: String,
24 pub client_id: String,
25 pub redirect_uri: String,
26 pub scope: Option<String>,
27 pub state: Option<String>,
28 pub code_challenge: Option<String>,
29 pub code_challenge_method: Option<String>,
30}
31
32#[derive(Deserialize)]
34pub struct TokenRequest {
35 pub grant_type: String,
36 pub code: Option<String>,
37 pub client_id: String,
38 pub client_secret: Option<String>,
39 pub redirect_uri: Option<String>,
40 pub refresh_token: Option<String>,
41 pub code_verifier: Option<String>,
42}
43
44impl std::fmt::Debug for TokenRequest {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 let mut d = f.debug_struct("TokenRequest");
47 d.field("grant_type", &self.grant_type);
48 d.field("code", &crate::utils::redact::redacted(&self.code));
49 d.field("client_id", &self.client_id);
50 d.field(
51 "client_secret",
52 &crate::utils::redact::redacted(&self.client_secret),
53 );
54 d.field("redirect_uri", &self.redirect_uri);
55 d.field(
56 "refresh_token",
57 &crate::utils::redact::redacted(&self.refresh_token),
58 );
59 d.field(
60 "code_verifier",
61 &crate::utils::redact::redacted(&self.code_verifier),
62 );
63 d.finish()
64 }
65}
66
67#[derive(Serialize)]
69pub struct TokenResponse {
70 pub access_token: String,
71 pub token_type: String,
72 pub expires_in: u64,
73 #[serde(skip_serializing_if = "Option::is_none")]
74 pub refresh_token: Option<String>,
75 #[serde(skip_serializing_if = "Option::is_none")]
76 pub scope: Option<String>,
77 #[serde(skip_serializing_if = "Option::is_none")]
78 pub id_token: Option<String>,
79}
80
81impl std::fmt::Debug for TokenResponse {
82 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
83 let mut d = f.debug_struct("TokenResponse");
84 d.field(
85 "access_token",
86 &crate::utils::redact::redacted(&self.access_token),
87 );
88 d.field("token_type", &self.token_type);
89 d.field("expires_in", &self.expires_in);
90 d.field(
91 "refresh_token",
92 &crate::utils::redact::redacted(&self.refresh_token),
93 );
94 d.field("scope", &self.scope);
95 d.field("id_token", &crate::utils::redact::redacted(&self.id_token));
96 d.finish()
97 }
98}
99
100#[derive(Debug, Serialize)]
102pub struct OAuthError {
103 pub error: String,
104 #[serde(skip_serializing_if = "Option::is_none")]
105 pub error_description: Option<String>,
106 #[serde(skip_serializing_if = "Option::is_none")]
107 pub error_uri: Option<String>,
108 #[serde(skip_serializing_if = "Option::is_none")]
109 pub state: Option<String>,
110}
111
112#[derive(Debug, Serialize)]
114pub struct ClientInfo {
115 pub client_id: String,
116 pub name: String,
117 pub description: String,
118 pub redirect_uris: Vec<String>,
119 pub scopes: Vec<String>,
120}
121
122const NOT_IMPLEMENTED_DESCRIPTION: &str =
123 "this OAuth endpoint is not implemented in this release line";
124
125fn not_implemented_response() -> Response {
126 let error = OAuthError {
127 error: "not_implemented".to_string(),
128 error_description: Some(NOT_IMPLEMENTED_DESCRIPTION.to_string()),
129 error_uri: None,
130 state: None,
131 };
132 (StatusCode::NOT_IMPLEMENTED, Json(error)).into_response()
133}
134
135fn not_implemented<T: Serialize>() -> ApiResponse<T> {
136 ApiResponse::<T>::error_typed("NOT_IMPLEMENTED", NOT_IMPLEMENTED_DESCRIPTION)
137}
138
139pub async fn authorize(
142 State(_state): State<ApiState>,
143 Query(_params): Query<AuthorizeRequest>,
144) -> impl IntoResponse {
145 not_implemented_response()
146}
147
148pub async fn token(
151 State(_state): State<ApiState>,
152 _headers: HeaderMap,
153 Json(_req): Json<TokenRequest>,
154) -> ApiResponse<TokenResponse> {
155 not_implemented()
156}
157
158#[derive(Deserialize)]
161pub struct RevokeRequest {
162 pub token: String,
163 pub token_type_hint: Option<String>,
164}
165
166impl std::fmt::Debug for RevokeRequest {
167 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
168 let mut d = f.debug_struct("RevokeRequest");
169 d.field("token", &crate::utils::redact::redacted(&self.token));
170 d.field("token_type_hint", &self.token_type_hint);
171 d.finish()
172 }
173}
174
175pub async fn revoke_token(
177 State(_state): State<ApiState>,
178 Json(_req): Json<RevokeRequest>,
179) -> ApiResponse<()> {
180 not_implemented()
181}
182
183#[derive(Deserialize)]
186pub struct IntrospectRequest {
187 pub token: String,
188 pub token_type_hint: Option<String>,
189}
190
191impl std::fmt::Debug for IntrospectRequest {
192 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
193 let mut d = f.debug_struct("IntrospectRequest");
194 d.field("token", &crate::utils::redact::redacted(&self.token));
195 d.field("token_type_hint", &self.token_type_hint);
196 d.finish()
197 }
198}
199
200#[derive(Debug, Serialize)]
201pub struct IntrospectResponse {
202 pub active: bool,
203 #[serde(skip_serializing_if = "Option::is_none")]
204 pub scope: Option<String>,
205 #[serde(skip_serializing_if = "Option::is_none")]
206 pub client_id: Option<String>,
207 #[serde(skip_serializing_if = "Option::is_none")]
208 pub username: Option<String>,
209 #[serde(skip_serializing_if = "Option::is_none")]
210 pub token_type: Option<String>,
211 #[serde(skip_serializing_if = "Option::is_none")]
212 pub exp: Option<u64>,
213 #[serde(skip_serializing_if = "Option::is_none")]
214 pub iat: Option<u64>,
215 #[serde(skip_serializing_if = "Option::is_none")]
216 pub sub: Option<String>,
217}
218
219pub async fn introspect_token(
221 State(_state): State<ApiState>,
222 Json(_req): Json<IntrospectRequest>,
223) -> ApiResponse<IntrospectResponse> {
224 not_implemented()
225}
226
227pub async fn get_client_info(
230 State(_state): State<ApiState>,
231 axum::extract::Path(_client_id): axum::extract::Path<String>,
232) -> ApiResponse<ClientInfo> {
233 not_implemented()
234}