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
33pub type TokenAuthMethod = oauth2::AuthType;
35
36#[derive(Clone)]
38pub struct AuthorizeUrl {
39 pub url: oauth2::url::Url,
40 pub state: String,
41 pub pkce_verifier: String,
42}
43impl Debug for AuthorizeUrl {
44 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45 f.debug_struct("AuthorizeUrl")
46 .field("url", &REDACTED)
47 .field("state", &self.state)
48 .field("pkce_verifier", &REDACTED)
49 .finish()
50 }
51}
52
53#[derive(Debug, Default, Clone)]
55pub struct UserInfo {
56 pub id: String,
58 pub name: Option<String>,
60 pub username: Option<String>,
62 pub email: Option<String>,
66 pub email_verified: Option<bool>,
68 pub avatar_url: Option<String>,
70 pub groups: Option<Vec<String>>,
72}
73
74#[derive(Clone)]
76pub struct StandardTokenResponse {
77 pub access_token: String,
79 pub refresh_token: Option<String>,
81 pub id_token: Option<String>,
83 pub expires_in: Option<std::time::Duration>,
85}
86impl Debug for StandardTokenResponse {
87 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88 f.debug_struct("StandardTokenResponse")
89 .field("access_token", &REDACTED)
90 .field("refresh_token", &REDACTED)
91 .field("id_token", &REDACTED)
92 .field("expires_in", &self.expires_in)
93 .finish()
94 }
95}
96
97#[derive(Clone)]
99pub struct OAuthCredentials {
100 pub client_id: String,
101 pub client_secret: String,
102}
103impl OAuthCredentials {
104 pub fn new(client_id: impl Into<String>, client_secret: impl Into<String>) -> Self {
105 Self {
106 client_id: client_id.into(),
107 client_secret: client_secret.into(),
108 }
109 }
110}
111impl<S> From<(S, S)> for OAuthCredentials
112where
113 S: Into<String>,
114{
115 fn from((id, secret): (S, S)) -> Self {
116 Self::new(id, secret)
117 }
118}
119impl Debug for OAuthCredentials {
120 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
121 f.debug_struct("OAuthCredentials")
122 .field("client_id", &self.client_id)
123 .field("client_secret", &REDACTED)
124 .finish()
125 }
126}
127
128#[derive(Debug, Clone, Default, Deserialize)]
130pub struct OidcDiscovery {
131 pub issuer: String,
132 pub authorization_endpoint: String,
133 pub token_endpoint: String,
134 pub userinfo_endpoint: String,
135}
136
137#[derive(Debug, Deserialize)]
139pub(crate) struct OidcUserInfo {
140 pub sub: String,
141 pub name: Option<String>,
142 pub preferred_username: Option<String>,
143 pub email: Option<String>,
144 pub email_verified: Option<bool>,
145 pub picture: Option<String>,
146 pub groups: Option<Vec<String>>,
147}