1use std::fmt::Error as FormatterError;
2use std::fmt::{Debug, Display, Formatter};
3
4use super::{
5 Client, EmptyExtraTokenFields, ErrorResponseType, RequestTokenError, StandardErrorResponse,
6 StandardTokenResponse, TokenType,
7};
8use crate::{
9 revocation::{RevocationErrorResponseType, StandardRevocableToken},
10 StandardTokenIntrospectionResponse,
11};
12
13pub type BasicClient = Client<
17 BasicErrorResponse,
18 BasicTokenResponse,
19 BasicTokenType,
20 BasicTokenIntrospectionResponse,
21 StandardRevocableToken,
22 BasicRevocationErrorResponse,
23>;
24
25#[derive(Clone, Debug, PartialEq)]
29pub enum BasicTokenType {
30 Bearer,
35 Mac,
40 Extension(String),
44}
45impl BasicTokenType {
46 fn from_str(s: &str) -> Self {
47 match s {
48 "bearer" => BasicTokenType::Bearer,
49 "mac" => BasicTokenType::Mac,
50 ext => BasicTokenType::Extension(ext.to_string()),
51 }
52 }
53}
54impl AsRef<str> for BasicTokenType {
55 fn as_ref(&self) -> &str {
56 match *self {
57 BasicTokenType::Bearer => "bearer",
58 BasicTokenType::Mac => "mac",
59 BasicTokenType::Extension(ref ext) => ext.as_str(),
60 }
61 }
62}
63impl<'de> serde::Deserialize<'de> for BasicTokenType {
64 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
65 where
66 D: serde::de::Deserializer<'de>,
67 {
68 let variant_str = String::deserialize(deserializer)?;
69 Ok(Self::from_str(&variant_str))
70 }
71}
72impl serde::ser::Serialize for BasicTokenType {
73 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
74 where
75 S: serde::ser::Serializer,
76 {
77 serializer.serialize_str(self.as_ref())
78 }
79}
80impl TokenType for BasicTokenType {}
81
82pub type BasicTokenResponse = StandardTokenResponse<EmptyExtraTokenFields, BasicTokenType>;
86
87pub type BasicTokenIntrospectionResponse =
91 StandardTokenIntrospectionResponse<EmptyExtraTokenFields, BasicTokenType>;
92
93#[derive(Clone, PartialEq)]
100pub enum BasicErrorResponseType {
101 InvalidClient,
106 InvalidGrant,
112 InvalidRequest,
118 InvalidScope,
123 UnauthorizedClient,
127 UnsupportedGrantType,
131 Extension(String),
135}
136impl BasicErrorResponseType {
137 pub(crate) fn from_str(s: &str) -> Self {
138 match s {
139 "invalid_client" => BasicErrorResponseType::InvalidClient,
140 "invalid_grant" => BasicErrorResponseType::InvalidGrant,
141 "invalid_request" => BasicErrorResponseType::InvalidRequest,
142 "invalid_scope" => BasicErrorResponseType::InvalidScope,
143 "unauthorized_client" => BasicErrorResponseType::UnauthorizedClient,
144 "unsupported_grant_type" => BasicErrorResponseType::UnsupportedGrantType,
145 ext => BasicErrorResponseType::Extension(ext.to_string()),
146 }
147 }
148}
149impl AsRef<str> for BasicErrorResponseType {
150 fn as_ref(&self) -> &str {
151 match *self {
152 BasicErrorResponseType::InvalidClient => "invalid_client",
153 BasicErrorResponseType::InvalidGrant => "invalid_grant",
154 BasicErrorResponseType::InvalidRequest => "invalid_request",
155 BasicErrorResponseType::InvalidScope => "invalid_scope",
156 BasicErrorResponseType::UnauthorizedClient => "unauthorized_client",
157 BasicErrorResponseType::UnsupportedGrantType => "unsupported_grant_type",
158 BasicErrorResponseType::Extension(ref ext) => ext.as_str(),
159 }
160 }
161}
162impl<'de> serde::Deserialize<'de> for BasicErrorResponseType {
163 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
164 where
165 D: serde::de::Deserializer<'de>,
166 {
167 let variant_str = String::deserialize(deserializer)?;
168 Ok(Self::from_str(&variant_str))
169 }
170}
171impl serde::ser::Serialize for BasicErrorResponseType {
172 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
173 where
174 S: serde::ser::Serializer,
175 {
176 serializer.serialize_str(self.as_ref())
177 }
178}
179impl ErrorResponseType for BasicErrorResponseType {}
180impl Debug for BasicErrorResponseType {
181 fn fmt(&self, f: &mut Formatter) -> Result<(), FormatterError> {
182 Display::fmt(self, f)
183 }
184}
185
186impl Display for BasicErrorResponseType {
187 fn fmt(&self, f: &mut Formatter) -> Result<(), FormatterError> {
188 write!(f, "{}", self.as_ref())
189 }
190}
191
192pub type BasicErrorResponse = StandardErrorResponse<BasicErrorResponseType>;
196
197pub type BasicRequestTokenError<RE> = RequestTokenError<RE, BasicErrorResponse>;
201
202pub type BasicRevocationErrorResponse = StandardErrorResponse<RevocationErrorResponseType>;