From 2e5a1b0c42adb9890b4126908b3f376cea070fdb Mon Sep 17 00:00:00 2001 From: Philippe Loctaux
Date: Tue, 24 Oct 2023 09:18:07 +0200
Subject: [PATCH] oauth: token route: client_id is not required if basic auth
is present
---
crates/ezidam/src/oauth.rs | 2 +-
crates/ezidam/src/routes/oauth/token.rs | 73 +++++++++++++++++--------
2 files changed, 51 insertions(+), 24 deletions(-)
diff --git a/crates/ezidam/src/oauth.rs b/crates/ezidam/src/oauth.rs
index 1230838..ef4c8ba 100644
--- a/crates/ezidam/src/oauth.rs
+++ b/crates/ezidam/src/oauth.rs
@@ -38,7 +38,7 @@ pub struct TokenRequest<'r> {
pub grant_type: GrantType,
pub code: Option<&'r str>,
pub redirect_uri: Option<&'r str>,
- pub client_id: &'r str,
+ pub client_id: Option<&'r str>,
pub client_secret: Option<&'r str>,
pub scope: Option<&'r str>,
pub refresh_token: Option<&'r str>,
diff --git a/crates/ezidam/src/routes/oauth/token.rs b/crates/ezidam/src/routes/oauth/token.rs
index a96485d..ffb8a5d 100644
--- a/crates/ezidam/src/routes/oauth/token.rs
+++ b/crates/ezidam/src/routes/oauth/token.rs
@@ -51,12 +51,14 @@ pub enum TokenError {
RefreshTokenExpired,
AuthorizationCodeUsed,
AuthorizationCodeExpired,
- HttpAuthDifferentClientId,
AppError(apps::Error),
- AppNotFound(String),
+ AppNotFoundFromAuthorizationCode(String),
+ AppNotFoundFromRefreshToken(String),
+ AppIdNotProvided,
AppSecretNotProvided,
Blocking(task::JoinError),
SecretCompare(hash::Error),
+ AppIdWrong,
AppSecretWrong,
UserError(users::Error),
UserNotFound,
@@ -111,14 +113,19 @@ impl<'r> Responder<'r, 'static> for TokenError {
Status::BadRequest,
"Authorization code has expired".to_string(),
),
- TokenError::HttpAuthDifferentClientId => (
- Status::BadRequest,
- "HTTP Auth differs from provided client_id".to_string(),
- ),
TokenError::AppError(e) => (Status::InternalServerError, e.to_string()),
- TokenError::AppNotFound(e) => {
- (Status::NotFound, format!("Could not find application {e}"))
- }
+ TokenError::AppNotFoundFromAuthorizationCode(e) => (
+ Status::NotFound,
+ format!("Could not find application from authorization code {e}"),
+ ),
+ TokenError::AppNotFoundFromRefreshToken(e) => (
+ Status::NotFound,
+ format!("Could not find application from refresh token {e}"),
+ ),
+ TokenError::AppIdNotProvided => (
+ Status::BadRequest,
+ "Could not get client_id: not provided in any way".to_string(),
+ ),
TokenError::AppSecretNotProvided => {
(Status::BadRequest, "Secret was not provided".to_string())
}
@@ -127,6 +134,7 @@ impl<'r> Responder<'r, 'static> for TokenError {
Status::InternalServerError,
format!("Failed to check app secret: {e}"),
),
+ TokenError::AppIdWrong => (Status::Forbidden, "Invalid client_id provided".to_string()),
TokenError::AppSecretWrong => {
(Status::Forbidden, "Invalid secret provided".to_string())
}
@@ -171,8 +179,8 @@ pub async fn request_token(
) -> std::result::Result