Skip to content

Commit 465c57e

Browse files
committed
wip
1 parent 468032b commit 465c57e

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

atrium-oauth/oauth-client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ base64.workspace = true
2222
chrono.workspace = true
2323
ecdsa = { workspace = true, features = ["signing"] }
2424
elliptic-curve.workspace = true
25+
futures.workspace = true
2526
jose-jwa.workspace = true
2627
jose-jwk = { workspace = true, features = ["p256"] }
2728
p256 = { workspace = true, features = ["ecdsa"] }

atrium-oauth/oauth-client/src/http_client/dpop.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ impl<T> DpopClient<T> {
9696
htu: Some(htu),
9797
nonce,
9898
ath,
99-
..Default::default()
10099
},
101100
};
102101
Ok(create_signed_jwt(secret_key.into(), header.into(), claims)?)
@@ -112,6 +111,12 @@ impl<T> DpopClient<T> {
112111
};
113112
}
114113
// is resource server?
114+
if response.status() == 401 {
115+
let header = response.headers().get("WWW-Authenticate").and_then(|v| v.to_str().ok());
116+
if let Some(s) = header.and_then(|s| s.strip_prefix("DPoP ")) {
117+
return s.contains("error=\"use_dpop_nonce\"");
118+
};
119+
}
115120

116121
false
117122
}
@@ -139,14 +144,15 @@ where
139144
let htu = uri.to_string();
140145

141146
let ath = match request.headers().get("Authorization").and_then(|v| v.to_str().ok()) {
142-
Some(s) if s.starts_with("DPoP") => {
143-
Some(URL_SAFE_NO_PAD.encode(Sha256::digest(s.strip_prefix("DPoP").unwrap())))
147+
Some(s) if s.starts_with("DPoP ") => {
148+
Some(URL_SAFE_NO_PAD.encode(Sha256::digest(s.strip_prefix("DPoP ").unwrap())))
144149
}
145150
_ => None,
146151
};
147152

148153
let init_nonce = self.nonces.get(&nonce_key).await?;
149-
let init_proof = self.build_proof(htm.clone(), htu.clone(), init_nonce.clone(), ath)?;
154+
let init_proof =
155+
self.build_proof(htm.clone(), htu.clone(), init_nonce.clone(), ath.clone())?;
150156
request.headers_mut().insert("DPoP", init_proof.parse()?);
151157
let response = self.inner.send_http(request.clone()).await?;
152158

atrium-oauth/oauth-client/src/oauth_session.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use atrium_common::store::CellStore;
55
use atrium_identity::{did::DidResolver, handle::HandleResolver};
66
use atrium_xrpc::{
77
http::{Request, Response},
8+
types::JwtTokenType,
89
HttpClient, XrpcClient,
910
};
1011
use chrono::TimeDelta;
@@ -80,7 +81,22 @@ where
8081
H: HandleResolver + Send + Sync + 'static,
8182
{
8283
fn base_uri(&self) -> String {
83-
todo!()
84+
let Ok(Some(Session { dpop_key: _, token_set })) =
85+
futures::FutureExt::now_or_never(self.get_session(false)).transpose()
86+
else {
87+
panic!("session, now or never");
88+
};
89+
dbg!(&token_set);
90+
token_set.aud
91+
}
92+
async fn authentication_token(&self, is_refresh: bool) -> Option<(JwtTokenType, String)> {
93+
let Session { dpop_key: _, token_set } = self.get_session(false).await.ok()?;
94+
dbg!(&token_set);
95+
if is_refresh {
96+
Some(JwtTokenType::DPoP).zip(token_set.refresh_token.clone())
97+
} else {
98+
Some((JwtTokenType::DPoP, token_set.access_token))
99+
}
84100
}
85101
}
86102

0 commit comments

Comments
 (0)