1use std::fmt::Debug;
2
3use serde::{Deserialize, Serialize};
4
5const REDACTED: &str = "[redacted]";
7
8pub(crate) type OAuthClient = oauth2::Client<
10 oauth2::basic::BasicErrorResponse,
11 OAuthTokenResponse,
12 oauth2::basic::BasicTokenIntrospectionResponse,
13 oauth2::StandardRevocableToken,
14 oauth2::basic::BasicRevocationErrorResponse,
15 oauth2::EndpointSet,
16 oauth2::EndpointNotSet,
17 oauth2::EndpointNotSet,
18 oauth2::EndpointNotSet,
19 oauth2::EndpointSet,
20>;
21
22pub(crate) type OAuthTokenResponse =
24 oauth2::StandardTokenResponse<OidcExtraTokenFields, oauth2::basic::BasicTokenType>;
25
26#[derive(Clone, Debug, Default, Deserialize, Serialize)]
28pub(crate) struct OidcExtraTokenFields {
29 pub id_token: Option<String>,
30}
31impl oauth2::ExtraTokenFields for OidcExtraTokenFields {}
32
33#[derive(Clone)]
35pub struct AuthorizeUrl {
36 pub url: oauth2::url::Url,
37 pub state: String,
38 pub pkce_verifier: String,
39}
40impl Debug for AuthorizeUrl {
41 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 f.debug_struct("AuthorizeUrl")
43 .field("url", &REDACTED)
44 .field("state", &self.state)
45 .field("pkce_verifier", &REDACTED)
46 .finish()
47 }
48}
49
50#[derive(Debug, Default, Clone)]
52pub struct UserInfo {
53 pub id: String,
55 pub name: Option<String>,
57 pub username: Option<String>,
59 pub email: Option<String>,
63 pub email_verified: Option<bool>,
65 pub avatar_url: Option<String>,
67 pub groups: Option<Vec<String>>,
69}
70
71#[derive(Clone)]
73pub struct StandardTokenResponse {
74 pub access_token: String,
76 pub refresh_token: Option<String>,
78 pub id_token: Option<String>,
80 pub expires_in: Option<std::time::Duration>,
82}
83impl Debug for StandardTokenResponse {
84 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
85 f.debug_struct("StandardTokenResponse")
86 .field("access_token", &REDACTED)
87 .field("refresh_token", &REDACTED)
88 .field("id_token", &REDACTED)
89 .field("expires_in", &self.expires_in)
90 .finish()
91 }
92}
93
94#[derive(Clone)]
96pub struct OAuthCredentials {
97 pub client_id: String,
98 pub client_secret: String,
99}
100impl OAuthCredentials {
101 pub fn new(client_id: impl Into<String>, client_secret: impl Into<String>) -> Self {
102 Self {
103 client_id: client_id.into(),
104 client_secret: client_secret.into(),
105 }
106 }
107}
108impl Debug for OAuthCredentials {
109 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
110 f.debug_struct("OAuthCredentials")
111 .field("client_id", &self.client_id)
112 .field("client_secret", &REDACTED)
113 .finish()
114 }
115}
116impl<S> From<(S, S)> for OAuthCredentials
117where
118 S: Into<String>,
119{
120 fn from((id, secret): (S, S)) -> Self {
121 Self::new(id, secret)
122 }
123}
124
125#[derive(Debug, Clone, Default, Deserialize)]
127pub struct OidcDiscovery {
128 pub issuer: String,
129 pub authorization_endpoint: String,
130 pub token_endpoint: String,
131 pub userinfo_endpoint: String,
132}
133
134#[derive(Debug, Deserialize)]
136pub(crate) struct OidcUserInfo {
137 pub sub: String,
138 pub name: Option<String>,
139 pub preferred_username: Option<String>,
140 pub email: Option<String>,
141 pub email_verified: Option<bool>,
142 pub picture: Option<String>,
143 pub groups: Option<Vec<String>>,
144}