fix(qbzd): QConnect form-encoded createToken + mDNS hostname + response parsing
3 fixes: 1. qws/createToken needs form body (jwt=jwt_qws, user_auth_token_needed, strong_auth_needed) not empty body. Was getting 400 Bad Request. 2. mDNS hostname must end with '.local.' for service registration. 3. Response parsing: jwt_qws.endpoint + jwt_qws.jwt, not tokens array. All 3 patterns copied from working desktop implementation in qconnect_service.rs. cc
This commit is contained in:
2 files changed
+9
-10
No files matched your search
@@ -265,7 +265,7 @@ fn register_mdns(config: &DaemonConfig) -> Result<mdns_sd::ServiceDaemon, String
|
|||||||
let service_info = mdns_sd::ServiceInfo::new(
|
let service_info = mdns_sd::ServiceInfo::new(
|
||||||
"_qbz._tcp.local.",
|
"_qbz._tcp.local.",
|
||||||
&service_name,
|
&service_name,
|
||||||
&format!("{}.", hostname::get().ok().and_then(|h| h.into_string().ok()).unwrap_or_else(|| "localhost".to_string())),
|
&format!("{}.local.", hostname::get().ok().and_then(|h| h.into_string().ok()).unwrap_or_else(|| "localhost".to_string())),
|
||||||
"",
|
"",
|
||||||
config.server.port,
|
config.server.port,
|
||||||
None,
|
None,
|
||||||
|
|||||||
@@ -307,7 +307,11 @@ async fn fetch_qws_credentials(client: &qbz_qobuz::QobuzClient) -> Option<(Strin
|
|||||||
.post("https://www.qobuz.com/api.json/0.2/qws/createToken")
|
.post("https://www.qobuz.com/api.json/0.2/qws/createToken")
|
||||||
.header("X-App-Id", &app_id)
|
.header("X-App-Id", &app_id)
|
||||||
.header("X-User-Auth-Token", &auth_token)
|
.header("X-User-Auth-Token", &auth_token)
|
||||||
.header("Content-Length", "0")
|
.form(&[
|
||||||
|
("jwt", "jwt_qws"),
|
||||||
|
("user_auth_token_needed", "true"),
|
||||||
|
("strong_auth_needed", "true"),
|
||||||
|
])
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.ok()?;
|
.ok()?;
|
||||||
@@ -318,14 +322,9 @@ async fn fetch_qws_credentials(client: &qbz_qobuz::QobuzClient) -> Option<(Strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
let body: serde_json::Value = resp.json().await.ok()?;
|
let body: serde_json::Value = resp.json().await.ok()?;
|
||||||
let endpoint = body.get("endpoint_url")?.as_str()?.to_string();
|
let jwt_qws = body.get("jwt_qws")?;
|
||||||
let jwt = body.get("tokens")
|
let endpoint = jwt_qws.get("endpoint")?.as_str()?.to_string();
|
||||||
.and_then(|t| t.as_array())
|
let jwt = jwt_qws.get("jwt")?.as_str()?.to_string();
|
||||||
.and_then(|arr| arr.iter().find_map(|t| {
|
|
||||||
if t.get("kind")?.as_str()? == "jwt_qws" {
|
|
||||||
Some(t.get("token")?.as_str()?.to_string())
|
|
||||||
} else { None }
|
|
||||||
}))?;
|
|
||||||
|
|
||||||
Some((endpoint, jwt))
|
Some((endpoint, jwt))
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user