diff --git a/Cargo.toml b/Cargo.toml index d0c9d83..bb9d3f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "axum-oidc" description = "A wrapper for the openidconnect crate for axum" -version = "0.2.1" +version = "0.2.2" edition = "2021" authors = [ "Paul Z " ] readme = "README.md" @@ -17,7 +17,7 @@ axum-core = "0.4" axum = { version = "0.7", default-features = false, features = [ "query" ] } tower-service = "0.3.2" tower-layer = "0.3" -tower-sessions = { version = "0.7", default-features = false, features = [ "axum-core" ] } +tower-sessions = { version = "0.9", default-features = false, features = [ "axum-core" ] } http = "1.0" async-trait = "0.1" openidconnect = "3.4" diff --git a/src/middleware.rs b/src/middleware.rs index b913af6..e34206f 100644 --- a/src/middleware.rs +++ b/src/middleware.rs @@ -1,6 +1,5 @@ use std::{ marker::PhantomData, - str::FromStr, task::{Context, Poll}, }; @@ -16,20 +15,15 @@ use tower_service::Service; use tower_sessions::Session; use openidconnect::{ - core::{ - CoreAuthenticationFlow, CoreGenderClaim, CoreIdTokenFields, CoreJsonWebKeyType, - CoreJweContentEncryptionAlgorithm, CoreJwsSigningAlgorithm, - }, - reqwest::async_http_client, - AccessTokenHash, AuthorizationCode, CsrfToken, ExtraTokenFields, IdTokenFields, Nonce, - OAuth2TokenResponse, PkceCodeChallenge, PkceCodeVerifier, RedirectUrl, RefreshToken, Scope, - StandardTokenResponse, TokenResponse, TokenType, + core::CoreAuthenticationFlow, reqwest::async_http_client, AccessTokenHash, AuthorizationCode, + CsrfToken, Nonce, OAuth2TokenResponse, PkceCodeChallenge, PkceCodeVerifier, RedirectUrl, Scope, + TokenResponse, }; use crate::{ error::{Error, MiddlewareError}, extractor::{OidcAccessToken, OidcClaims}, - AdditionalClaims, BoxError, IdToken, OidcClient, OidcQuery, OidcSession, SESSION_KEY, + AdditionalClaims, BoxError, OidcClient, OidcQuery, OidcSession, SESSION_KEY, }; /// Layer for the [OidcLoginMiddleware]. @@ -124,8 +118,10 @@ where .extensions .get::() .ok_or(MiddlewareError::SessionNotFound)?; - let login_session: Option = - session.get(SESSION_KEY).map_err(MiddlewareError::from)?; + let login_session: Option = session + .get(SESSION_KEY) + .await + .map_err(MiddlewareError::from)?; let handler_uri = strip_oidc_from_path(oidcclient.application_base_url.clone(), &parts.uri)?; @@ -178,7 +174,7 @@ where .refresh_token() .map(|x| x.secret().to_string()); - session.insert(SESSION_KEY, login_session).unwrap(); + session.insert(SESSION_KEY, login_session).await.unwrap(); Ok(Redirect::temporary(&handler_uri.to_string()).into_response()) } else { @@ -208,7 +204,7 @@ where refresh_token: None, }; - session.insert(SESSION_KEY, oidc_session).unwrap(); + session.insert(SESSION_KEY, oidc_session).await.unwrap(); Ok(Redirect::temporary(auth_url.as_str()).into_response()) } @@ -308,8 +304,10 @@ where .extensions .get::() .ok_or(MiddlewareError::SessionNotFound)?; - let mut login_session: Option = - session.get(SESSION_KEY).map_err(MiddlewareError::from)?; + let mut login_session: Option = session + .get(SESSION_KEY) + .await + .map_err(MiddlewareError::from)?; let handler_uri = strip_oidc_from_path(oidcclient.application_base_url.clone(), &parts.uri)?; @@ -384,7 +382,7 @@ where .get::() .ok_or(MiddlewareError::SessionNotFound)?; - session.insert(SESSION_KEY, login_session).unwrap(); + session.insert(SESSION_KEY, login_session).await.unwrap(); } (None, None) => {} }