Skip to content

Commit 6d4399a

Browse files
committed
fix: error for invalid combination
1 parent 23e7835 commit 6d4399a

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

crates/rmcp/src/transport/auth.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,11 @@ impl AuthorizationRequest {
744744
}
745745

746746
/// Set the client secret paired with a pre-registered client ID.
747+
///
748+
/// Must be used together with
749+
/// [`with_preregistered_client`](Self::with_preregistered_client);
750+
/// authorization fails with [`AuthError::RegistrationFailed`] if a secret
751+
/// is provided without a client ID.
747752
pub fn with_client_secret(mut self, client_secret: impl Into<String>) -> Self {
748753
self.client_secret = Some(client_secret.into());
749754
self
@@ -3072,6 +3077,17 @@ impl AuthorizationSession {
30723077
mut auth_manager: AuthorizationManager,
30733078
mut request: AuthorizationRequest,
30743079
) -> Result<Self, (AuthorizationManager, AuthError)> {
3080+
if request.client_secret.is_some() && request.client_id.is_none() {
3081+
return Err((
3082+
auth_manager,
3083+
AuthError::RegistrationFailed(
3084+
"client_secret was provided without a pre-registered client_id; \
3085+
pair with_client_secret with with_preregistered_client"
3086+
.to_string(),
3087+
),
3088+
));
3089+
}
3090+
30753091
if request.scopes.is_empty() {
30763092
request.scopes = auth_manager.select_scopes(None, &[]);
30773093
} else {

0 commit comments

Comments
 (0)