diff --git a/AGENTS.md b/AGENTS.md index 612771f..3601035 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,7 +5,7 @@ Rust CLI (`amendable`) for the Amendable API. ## Product facts (do not invent others) - Site + Git HTTPS: `https://amendable.io` -- API: `https://api.amendable.io` header `access-token` +- API: `https://api.amendable.io` header `Authorization: Bearer` - Clone: `https://amendable.io/r//.git` - Git password is the access token. There is no SSH. - Command name is `amendable`. Package name is `amendable-cli`. diff --git a/src/client.rs b/src/client.rs index 0c3eb2d..f5c8952 100644 --- a/src/client.rs +++ b/src/client.rs @@ -32,8 +32,8 @@ impl Client { if auth { let token = self.token.as_deref().ok_or(Error::NotLoggedIn)?; headers.insert( - "access-token", - reqwest::header::HeaderValue::from_str(token) + reqwest::header::AUTHORIZATION, + reqwest::header::HeaderValue::from_str(&format!("Bearer {token}")) .map_err(|err| Error::message(err.to_string()))?, ); } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 2971e14..bcda469 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -107,7 +107,7 @@ fn handle(state: &Arc>, mut request: Request) { let url = request.url().to_string(); let (path, query) = split_url(&url); let method = request.method().clone(); - let token = header_value(&request, "access-token"); + let token = bearer_token(&request); let body = read_json(&mut request); let response = match method { @@ -363,6 +363,20 @@ fn header_value(request: &Request, name: &str) -> Option { }) } +fn bearer_token(request: &Request) -> Option { + let value = header_value(request, "authorization")?; + let (scheme, credentials) = value.split_once(' ')?; + if !scheme.eq_ignore_ascii_case("bearer") { + return None; + } + let token = credentials.trim(); + if token.is_empty() { + None + } else { + Some(token.to_string()) + } +} + fn read_json(request: &mut Request) -> Value { let mut buf = String::new(); let _ = std::io::Read::read_to_string(request.as_reader(), &mut buf);