@@ -16,7 +16,9 @@ use axum_extra::TypedHeader;
1616use headers:: { Authorization , authorization:: Bearer } ;
1717use hyper:: StatusCode ;
1818use mas_axum_utils:: record_error;
19- use mas_data_model:: { BoxClock , Session , TokenType , User , personal:: session:: PersonalSession } ;
19+ use mas_data_model:: {
20+ BoxClock , Session , TokenFormatError , TokenType , User , personal:: session:: PersonalSession ,
21+ } ;
2022use mas_storage:: { BoxRepository , RepositoryError } ;
2123use oauth2_types:: scope:: Scope ;
2224use ulid:: Ulid ;
@@ -44,7 +46,11 @@ pub enum Rejection {
4446
4547 /// The access token was not of the correct type for the Admin API
4648 #[ error( "Invalid type of access token" ) ]
47- InvalidAccessTokenType ,
49+ InvalidAccessTokenType (
50+ #[ source]
51+ #[ from]
52+ Option < TokenFormatError > ,
53+ ) ,
4854
4955 /// The access token could not be found in the database
5056 #[ error( "Unknown access token" ) ]
@@ -96,7 +102,7 @@ impl IntoResponse for Rejection {
96102 | Rejection :: SessionRevoked
97103 | Rejection :: UserLocked
98104 | Rejection :: MissingScope
99- | Rejection :: InvalidAccessTokenType => StatusCode :: UNAUTHORIZED ,
105+ | Rejection :: InvalidAccessTokenType ( _ ) => StatusCode :: UNAUTHORIZED ,
100106
101107 Rejection :: RepositorySetup ( _)
102108 | Rejection :: Repository ( _)
@@ -160,7 +166,7 @@ where
160166 } ) ?;
161167
162168 let token = token. token ( ) ;
163- let token_type = TokenType :: check ( token) . or ( Err ( Rejection :: InvalidAccessTokenType ) ) ?;
169+ let token_type = TokenType :: check ( token) ?;
164170
165171 let session = match token_type {
166172 TokenType :: AccessToken => {
@@ -224,7 +230,7 @@ where
224230 CallerSession :: PersonalSession ( session)
225231 }
226232 _other => {
227- return Err ( Rejection :: InvalidAccessTokenType ) ;
233+ return Err ( Rejection :: InvalidAccessTokenType ( None ) ) ;
228234 }
229235 } ;
230236
0 commit comments