Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
avdb13 committed Oct 29, 2024
1 parent d4ecd43 commit 9b4aef1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
17 changes: 9 additions & 8 deletions atrium-oauth/oauth-client/src/server_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::jose::jwt::{RegisteredClaims, RegisteredClaimsAud};
use crate::keyset::Keyset;
use crate::resolver::OAuthResolver;
use crate::types::{
OAuthAuthorizationServerMetadata, OAuthClientMetadata, OAuthTokenResponse,
PushedAuthorizationRequestParameters, TokenGrantType, TokenRequestParameters, TokenSet,
AuthorizationCodeParameters, OAuthAuthorizationServerMetadata, OAuthClientMetadata,
OAuthTokenResponse, PushedAuthorizationRequestParameters, TokenRequestParameters, TokenSet,
};
use crate::utils::{compare_algos, generate_nonce};
use atrium_api::types::string::Datetime;
Expand Down Expand Up @@ -162,12 +162,13 @@ where
}
pub async fn exchange_code(&self, code: &str, verifier: &str) -> Result<TokenSet> {
self.verify_token_response(
self.request(OAuthRequest::Token(TokenRequestParameters {
grant_type: TokenGrantType::AuthorizationCode,
code: code.into(),
redirect_uri: self.client_metadata.redirect_uris[0].clone(), // ?
code_verifier: verifier.into(),
}))
self.request(OAuthRequest::Token(TokenRequestParameters::AuthorizationCode(
AuthorizationCodeParameters {
code: code.into(),
redirect_uri: self.client_metadata.redirect_uris[0].clone(), // ?
code_verifier: verifier.into(),
},
)))
.await?,
)
.await
Expand Down
25 changes: 14 additions & 11 deletions atrium-oauth/oauth-client/src/store/cached.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
use std::{
error::Error,
fmt::Debug,
future::Future,
hash::Hash,
pin::Pin,
sync::{Arc, Mutex},
};

use chrono::{DateTime, FixedOffset, Utc};
use tokio::sync::broadcast;

use super::{memory::MemorySimpleStore, SimpleStore};

pub type Getter<'f, T> = Pin<Box<dyn Future<Output = T> + Send + 'f>>;

pub struct CachedStore<S>
pub trait CachedStore<K, V, E>: SimpleStore<K, Cached<V, E>>
where
// S: SimpleStore<K, Cached<V, E>>,
// K: Clone + Eq + Hash,
// V: Expired + Clone + Send + Sync + 'static,
// E: Error + Clone + Send + Sync + 'static,
K: Clone + Debug + Eq + Hash + Send + Sync + 'static,
V: Expired + Debug + Clone + Send + Sync + 'static,
E: Error + Clone + Send + Sync + 'static,
{
pub store: S,
}

impl<S> Default for CachedStore<S>
pub type CachedMemoryStore<K, V, E> = MemorySimpleStore<K, Cached<V, E>>;

impl<K, V, E> CachedStore<K, V, E> for CachedMemoryStore<K, V, E>
where
S: Default,
K: Clone + Debug + Eq + Hash + Send + Sync + 'static,
V: Expired + Debug + Clone + Send + Sync + 'static,
E: Error + Clone + Send + Sync + 'static,
{
fn default() -> Self {
Self { store: Default::default() }
}
}

#[derive(Clone, Debug, Default)]
Expand Down
5 changes: 3 additions & 2 deletions atrium-oauth/oauth-client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ mod token;
pub use client_metadata::{OAuthClientMetadata, TryIntoOAuthClientMetadata};
pub use metadata::{OAuthAuthorizationServerMetadata, OAuthProtectedResourceMetadata};
pub use request::{
AuthorizationCodeChallengeMethod, AuthorizationResponseType,
PushedAuthorizationRequestParameters, TokenGrantType, TokenRequestParameters,
AuthorizationCodeChallengeMethod, AuthorizationCodeParameters, AuthorizationResponseType,
PushedAuthorizationRequestParameters, RefreshTokenParameters, RevocationRequestParameters,
TokenRequestParameters,
};
pub use response::{OAuthPusehedAuthorizationRequestResponse, OAuthTokenResponse};
use serde::Deserialize;
Expand Down

0 comments on commit 9b4aef1

Please sign in to comment.