Skip to content

Commit dcd91c4

Browse files
committed
Support wasm32
1 parent acd81a7 commit dcd91c4

File tree

15 files changed

+40
-35
lines changed

15 files changed

+40
-35
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::keyset::Keyset;
22
use crate::types::{OAuthClientMetadata, TryIntoOAuthClientMetadata};
33
use atrium_xrpc::http::Uri;
4+
use serde::{Deserialize, Serialize};
45
use thiserror::Error;
56

67
#[derive(Error, Debug)]
@@ -21,7 +22,8 @@ pub enum Error {
2122

2223
pub type Result<T> = core::result::Result<T, Error>;
2324

24-
#[derive(Debug, Clone, PartialEq, Eq)]
25+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
26+
#[serde(rename_all = "snake_case")]
2527
pub enum AuthMethod {
2628
None,
2729
// https://openid.net/specs/openid-connect-core-1_0.html#ClientAuthentication
@@ -37,7 +39,8 @@ impl From<AuthMethod> for String {
3739
}
3840
}
3941

40-
#[derive(Debug, Clone, PartialEq, Eq)]
42+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
43+
#[serde(rename_all = "snake_case")]
4144
pub enum GrantType {
4245
AuthorizationCode,
4346
RefreshToken,
@@ -52,7 +55,8 @@ impl From<GrantType> for String {
5255
}
5356
}
5457

55-
#[derive(Debug, Clone, PartialEq, Eq)]
58+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
59+
#[serde(rename_all = "snake_case")]
5660
pub enum Scope {
5761
Atproto,
5862
}
@@ -65,19 +69,19 @@ impl From<Scope> for String {
6569
}
6670
}
6771

68-
#[derive(Debug, Clone, PartialEq, Eq)]
72+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
6973
pub struct AtprotoLocalhostClientMetadata {
7074
pub redirect_uris: Vec<String>,
7175
}
7276

73-
#[derive(Debug, Clone, PartialEq, Eq)]
77+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
7478
pub struct AtprotoClientMetadata {
7579
pub client_id: String,
7680
pub client_uri: String,
7781
pub redirect_uris: Vec<String>,
7882
pub token_endpoint_auth_method: AuthMethod,
7983
pub grant_types: Vec<GrantType>,
80-
pub scope: Vec<Scope>,
84+
pub scopes: Vec<Scope>,
8185
pub jwks_uri: Option<String>,
8286
pub token_endpoint_auth_signing_alg: Option<String>,
8387
}
@@ -117,7 +121,7 @@ impl TryIntoOAuthClientMetadata for AtprotoClientMetadata {
117121
if !self.grant_types.contains(&GrantType::AuthorizationCode) {
118122
return Err(Error::InvalidGrantTypes);
119123
}
120-
if !self.scope.contains(&Scope::Atproto) {
124+
if !self.scopes.contains(&Scope::Atproto) {
121125
return Err(Error::InvalidScope);
122126
}
123127
let (jwks_uri, mut jwks) = (self.jwks_uri, None);
@@ -147,7 +151,7 @@ impl TryIntoOAuthClientMetadata for AtprotoClientMetadata {
147151
token_endpoint_auth_method: Some(self.token_endpoint_auth_method.into()),
148152
grant_types: Some(self.grant_types.into_iter().map(|v| v.into()).collect()),
149153
scope: Some(
150-
self.scope
154+
self.scopes
151155
.into_iter()
152156
.map(|v| v.into())
153157
.collect::<Vec<String>>()

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use atrium_xrpc::http::{Request, Response};
77
use atrium_xrpc::HttpClient;
88
use base64::engine::general_purpose::URL_SAFE_NO_PAD;
99
use base64::Engine;
10+
use chrono::Utc;
1011
use jose_jwa::{Algorithm, Signing};
1112
use jose_jwk::{crypto, EcCurves, Jwk, Key};
1213
use rand::rngs::SmallRng;
@@ -30,8 +31,6 @@ pub enum Error {
3031
UnsupportedKey,
3132
#[error(transparent)]
3233
SerdeJson(#[from] serde_json::Error),
33-
#[error(transparent)]
34-
SystemTime(#[from] std::time::SystemTimeError),
3534
}
3635

3736
type Result<T> = core::result::Result<T, Error>;
@@ -86,11 +85,7 @@ impl<T> DpopClient<T> {
8685
let claims = Claims {
8786
registered: RegisteredClaims {
8887
jti: Some(Self::generate_jti()),
89-
iat: Some(
90-
std::time::SystemTime::now()
91-
.duration_since(std::time::UNIX_EPOCH)?
92-
.as_secs(),
93-
),
88+
iat: Some(Utc::now().timestamp()),
9489
..Default::default()
9590
},
9691
public: PublicClaims {

atrium-oauth/oauth-client/src/jose/jwt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ pub struct RegisteredClaims {
1818
#[serde(skip_serializing_if = "Option::is_none")]
1919
pub aud: Option<RegisteredClaimsAud>,
2020
#[serde(skip_serializing_if = "Option::is_none")]
21-
pub exp: Option<u64>,
21+
pub exp: Option<i64>,
2222
#[serde(skip_serializing_if = "Option::is_none")]
23-
pub nbf: Option<u64>,
23+
pub nbf: Option<i64>,
2424
#[serde(skip_serializing_if = "Option::is_none")]
25-
pub iat: Option<u64>,
25+
pub iat: Option<i64>,
2626
#[serde(skip_serializing_if = "Option::is_none")]
2727
pub jti: Option<String>,
2828
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ where
259259
self.keyset.clone(),
260260
)?;
261261
let token_set = server.exchange_code(&params.code, &state.verifier).await?;
262-
// TODO: verify id_token?
263262

263+
// TODO: create session?
264264
Ok(token_set)
265265
}
266266
fn generate_dpop_key(metadata: &OAuthAuthorizationServerMetadata) -> Option<Key> {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ use oauth_protected_resource_resolver::OAuthProtectedResourceMetadata;
1919
use std::marker::PhantomData;
2020
use std::sync::Arc;
2121

22-
#[async_trait]
22+
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
23+
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
2324
pub trait Resolver {
2425
type Input;
2526
type Output;

atrium-oauth/oauth-client/src/resolver/did_resolver/base_resolver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ pub trait BaseResolver {
1414
fn get_resolver(&self, method: Method) -> Arc<dyn DidResolver + Send + Sync + 'static>;
1515
}
1616

17-
#[async_trait]
17+
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
18+
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
1819
impl<T> Resolver for T
1920
where
2021
T: BaseResolver + Send + Sync + 'static,

atrium-oauth/oauth-client/src/resolver/did_resolver/plc_resolver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ impl<T> PlcResolver<T> {
2626
}
2727
}
2828

29-
#[async_trait]
29+
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
30+
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
3031
impl<T> Resolver for PlcResolver<T>
3132
where
3233
T: HttpClient + Send + Sync + 'static,

atrium-oauth/oauth-client/src/resolver/did_resolver/web_resolver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ impl<T> WebResolver<T> {
1717
}
1818
}
1919

20-
#[async_trait]
20+
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
21+
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
2122
impl<T> Resolver for WebResolver<T>
2223
where
2324
T: HttpClient + Send + Sync + 'static,

atrium-oauth/oauth-client/src/resolver/handle_resolver/appview_resolver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ impl<T> AppViewResolver<T> {
2323
}
2424
}
2525

26-
#[async_trait]
26+
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27+
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
2728
impl<T> Resolver for AppViewResolver<T>
2829
where
2930
T: HttpClient + Send + Sync + 'static,

atrium-oauth/oauth-client/src/resolver/oauth_authorization_server_resolver.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ impl<T> DefaultOAuthAuthorizationServerResolver<T> {
1717
}
1818
}
1919

20-
#[async_trait]
20+
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
21+
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
2122
impl<T> Resolver for DefaultOAuthAuthorizationServerResolver<T>
2223
where
2324
T: HttpClient + Send + Sync + 'static,

0 commit comments

Comments
 (0)