From 9b4aef1d9a11135e9b42f97da8cf9bb5573bfb4f Mon Sep 17 00:00:00 2001 From: avdb13 Date: Tue, 29 Oct 2024 17:21:33 +0000 Subject: [PATCH] small changes --- atrium-oauth/oauth-client/src/server_agent.rs | 17 +++++++------ atrium-oauth/oauth-client/src/store/cached.rs | 25 +++++++++++-------- atrium-oauth/oauth-client/src/types.rs | 5 ++-- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/atrium-oauth/oauth-client/src/server_agent.rs b/atrium-oauth/oauth-client/src/server_agent.rs index 03a60570..d35afdbe 100644 --- a/atrium-oauth/oauth-client/src/server_agent.rs +++ b/atrium-oauth/oauth-client/src/server_agent.rs @@ -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; @@ -162,12 +162,13 @@ where } pub async fn exchange_code(&self, code: &str, verifier: &str) -> Result { 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 diff --git a/atrium-oauth/oauth-client/src/store/cached.rs b/atrium-oauth/oauth-client/src/store/cached.rs index fb130cc9..8b0b1baf 100644 --- a/atrium-oauth/oauth-client/src/store/cached.rs +++ b/atrium-oauth/oauth-client/src/store/cached.rs @@ -1,6 +1,8 @@ use std::{ error::Error, + fmt::Debug, future::Future, + hash::Hash, pin::Pin, sync::{Arc, Mutex}, }; @@ -8,25 +10,26 @@ use std::{ use chrono::{DateTime, FixedOffset, Utc}; use tokio::sync::broadcast; +use super::{memory::MemorySimpleStore, SimpleStore}; + pub type Getter<'f, T> = Pin + Send + 'f>>; -pub struct CachedStore +pub trait CachedStore: SimpleStore> where -// S: SimpleStore>, -// 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 Default for CachedStore +pub type CachedMemoryStore = MemorySimpleStore>; + +impl CachedStore for CachedMemoryStore 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)] diff --git a/atrium-oauth/oauth-client/src/types.rs b/atrium-oauth/oauth-client/src/types.rs index 45ef9bdb..a00de3d7 100644 --- a/atrium-oauth/oauth-client/src/types.rs +++ b/atrium-oauth/oauth-client/src/types.rs @@ -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;