1use crate::{
2 revocation::{RevocationErrorResponseType, StandardRevocableToken},
3 Client, EmptyExtraTokenFields, EndpointNotSet, ErrorResponseType, RequestTokenError,
4 StandardErrorResponse, StandardTokenIntrospectionResponse, StandardTokenResponse, TokenType,
5};
6
7use std::fmt::Error as FormatterError;
8use std::fmt::{Debug, Display, Formatter};
9
10pub type BasicClient<
12 HasAuthUrl = EndpointNotSet,
13 HasDeviceAuthUrl = EndpointNotSet,
14 HasIntrospectionUrl = EndpointNotSet,
15 HasRevocationUrl = EndpointNotSet,
16 HasTokenUrl = EndpointNotSet,
17> = Client<
18 BasicErrorResponse,
19 BasicTokenResponse,
20 BasicTokenIntrospectionResponse,
21 StandardRevocableToken,
22 BasicRevocationErrorResponse,
23 HasAuthUrl,
24 HasDeviceAuthUrl,
25 HasIntrospectionUrl,
26 HasRevocationUrl,
27 HasTokenUrl,
28>;
29
30#[derive(Clone, Debug, PartialEq, Eq)]
32pub enum BasicTokenType {
33 Bearer,
36 Mac,
39 Extension(String),
41}
42impl BasicTokenType {
43 fn from_str(s: &str) -> Self {
44 match s {
45 "bearer" => BasicTokenType::Bearer,
46 "mac" => BasicTokenType::Mac,
47 ext => BasicTokenType::Extension(ext.to_string()),
48 }
49 }
50}
51impl AsRef<str> for BasicTokenType {
52 fn as_ref(&self) -> &str {
53 match *self {
54 BasicTokenType::Bearer => "bearer",
55 BasicTokenType::Mac => "mac",
56 BasicTokenType::Extension(ref ext) => ext.as_str(),
57 }
58 }
59}
60impl<'de> serde::Deserialize<'de> for BasicTokenType {
61 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
62 where
63 D: serde::de::Deserializer<'de>,
64 {
65 let variant_str = String::deserialize(deserializer)?;
66 Ok(Self::from_str(&variant_str))
67 }
68}
69impl serde::ser::Serialize for BasicTokenType {
70 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
71 where
72 S: serde::ser::Serializer,
73 {
74 serializer.serialize_str(self.as_ref())
75 }
76}
77impl TokenType for BasicTokenType {}
78
79pub type BasicTokenResponse = StandardTokenResponse<EmptyExtraTokenFields, BasicTokenType>;
81
82pub type BasicTokenIntrospectionResponse =
84 StandardTokenIntrospectionResponse<EmptyExtraTokenFields, BasicTokenType>;
85
86#[derive(Clone, PartialEq, Eq)]
91pub enum BasicErrorResponseType {
92 InvalidClient,
95 InvalidGrant,
99 InvalidRequest,
103 InvalidScope,
106 UnauthorizedClient,
108 UnsupportedGrantType,
110 Extension(String),
112}
113impl BasicErrorResponseType {
114 pub(crate) fn from_str(s: &str) -> Self {
115 match s {
116 "invalid_client" => BasicErrorResponseType::InvalidClient,
117 "invalid_grant" => BasicErrorResponseType::InvalidGrant,
118 "invalid_request" => BasicErrorResponseType::InvalidRequest,
119 "invalid_scope" => BasicErrorResponseType::InvalidScope,
120 "unauthorized_client" => BasicErrorResponseType::UnauthorizedClient,
121 "unsupported_grant_type" => BasicErrorResponseType::UnsupportedGrantType,
122 ext => BasicErrorResponseType::Extension(ext.to_string()),
123 }
124 }
125}
126impl AsRef<str> for BasicErrorResponseType {
127 fn as_ref(&self) -> &str {
128 match *self {
129 BasicErrorResponseType::InvalidClient => "invalid_client",
130 BasicErrorResponseType::InvalidGrant => "invalid_grant",
131 BasicErrorResponseType::InvalidRequest => "invalid_request",
132 BasicErrorResponseType::InvalidScope => "invalid_scope",
133 BasicErrorResponseType::UnauthorizedClient => "unauthorized_client",
134 BasicErrorResponseType::UnsupportedGrantType => "unsupported_grant_type",
135 BasicErrorResponseType::Extension(ref ext) => ext.as_str(),
136 }
137 }
138}
139impl<'de> serde::Deserialize<'de> for BasicErrorResponseType {
140 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
141 where
142 D: serde::de::Deserializer<'de>,
143 {
144 let variant_str = String::deserialize(deserializer)?;
145 Ok(Self::from_str(&variant_str))
146 }
147}
148impl serde::ser::Serialize for BasicErrorResponseType {
149 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
150 where
151 S: serde::ser::Serializer,
152 {
153 serializer.serialize_str(self.as_ref())
154 }
155}
156impl ErrorResponseType for BasicErrorResponseType {}
157impl Debug for BasicErrorResponseType {
158 fn fmt(&self, f: &mut Formatter) -> Result<(), FormatterError> {
159 Display::fmt(self, f)
160 }
161}
162
163impl Display for BasicErrorResponseType {
164 fn fmt(&self, f: &mut Formatter) -> Result<(), FormatterError> {
165 write!(f, "{}", self.as_ref())
166 }
167}
168
169pub type BasicErrorResponse = StandardErrorResponse<BasicErrorResponseType>;
171
172pub type BasicRequestTokenError<RE> = RequestTokenError<RE, BasicErrorResponse>;
174
175pub type BasicRevocationErrorResponse = StandardErrorResponse<RevocationErrorResponseType>;