Skip to content

Commit 23e7835

Browse files
committed
fix: dcr registration uses requested application type
1 parent 9a3c0af commit 23e7835

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

crates/rmcp/src/transport/auth.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3078,6 +3078,10 @@ impl AuthorizationSession {
30783078
auth_manager.add_offline_access_if_supported(&mut request.scopes);
30793079
}
30803080

3081+
if request.application_type.is_some() {
3082+
auth_manager.application_type = request.application_type.clone();
3083+
}
3084+
30813085
let redirect_uri = request.redirect_uri.clone();
30823086
let scopes = request.scopes.clone();
30833087
let scope_refs: Vec<&str> = scopes.iter().map(|s| s.as_str()).collect();
@@ -4410,6 +4414,40 @@ mod tests {
44104414
assert!(matches!(state, super::OAuthState::Session(_)));
44114415
}
44124416

4417+
#[tokio::test]
4418+
async fn dcr_registration_uses_requested_application_type() {
4419+
let mut responses = preregistered_discovery_responses();
4420+
responses.push(http_response(
4421+
201,
4422+
serde_json::json!({
4423+
"client_id": "dcr-client",
4424+
"redirect_uris": ["http://localhost:8080/callback"]
4425+
}),
4426+
));
4427+
let client = RecordingOAuthHttpClient::with_responses(responses);
4428+
let mut state = super::OAuthState::new_with_oauth_http_client(
4429+
"https://mcp.example.com/mcp",
4430+
Arc::new(client.clone()),
4431+
)
4432+
.await
4433+
.unwrap();
4434+
4435+
let request = AuthorizationRequest::new("http://localhost:8080/callback")
4436+
.with_client_name("test-client")
4437+
.with_application_type("web")
4438+
.with_scopes(["read"]);
4439+
state.start_authorization(request).await.unwrap();
4440+
4441+
// SEP-837: the requested application_type must be sent in the DCR request
4442+
let requests = client.requests();
4443+
let registration = requests
4444+
.iter()
4445+
.find(|request| request.uri.contains("/register"))
4446+
.expect("registration endpoint should be called");
4447+
let body: serde_json::Value = serde_json::from_slice(&registration.body).unwrap();
4448+
assert_eq!(body.get("application_type").unwrap(), "web");
4449+
}
4450+
44134451
#[tokio::test]
44144452
async fn cimd_rejects_non_https_client_metadata_url_and_recovers_state() {
44154453
let client = RecordingOAuthHttpClient::with_responses(cimd_discovery_responses());

0 commit comments

Comments
 (0)