mirror of
https://github.com/pfzetto/axum-oidc.git
synced 2024-11-21 19:12:49 +01:00
update tower-sessions
This commit is contained in:
parent
991f24e31f
commit
dacaedf9ca
2 changed files with 17 additions and 19 deletions
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "axum-oidc"
|
name = "axum-oidc"
|
||||||
description = "A wrapper for the openidconnect crate for axum"
|
description = "A wrapper for the openidconnect crate for axum"
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = [ "Paul Z <info@pfz4.de>" ]
|
authors = [ "Paul Z <info@pfz4.de>" ]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -17,7 +17,7 @@ axum-core = "0.4"
|
||||||
axum = { version = "0.7", default-features = false, features = [ "query" ] }
|
axum = { version = "0.7", default-features = false, features = [ "query" ] }
|
||||||
tower-service = "0.3.2"
|
tower-service = "0.3.2"
|
||||||
tower-layer = "0.3"
|
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"
|
http = "1.0"
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
openidconnect = "3.4"
|
openidconnect = "3.4"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
str::FromStr,
|
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,20 +15,15 @@ use tower_service::Service;
|
||||||
use tower_sessions::Session;
|
use tower_sessions::Session;
|
||||||
|
|
||||||
use openidconnect::{
|
use openidconnect::{
|
||||||
core::{
|
core::CoreAuthenticationFlow, reqwest::async_http_client, AccessTokenHash, AuthorizationCode,
|
||||||
CoreAuthenticationFlow, CoreGenderClaim, CoreIdTokenFields, CoreJsonWebKeyType,
|
CsrfToken, Nonce, OAuth2TokenResponse, PkceCodeChallenge, PkceCodeVerifier, RedirectUrl, Scope,
|
||||||
CoreJweContentEncryptionAlgorithm, CoreJwsSigningAlgorithm,
|
TokenResponse,
|
||||||
},
|
|
||||||
reqwest::async_http_client,
|
|
||||||
AccessTokenHash, AuthorizationCode, CsrfToken, ExtraTokenFields, IdTokenFields, Nonce,
|
|
||||||
OAuth2TokenResponse, PkceCodeChallenge, PkceCodeVerifier, RedirectUrl, RefreshToken, Scope,
|
|
||||||
StandardTokenResponse, TokenResponse, TokenType,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::{Error, MiddlewareError},
|
error::{Error, MiddlewareError},
|
||||||
extractor::{OidcAccessToken, OidcClaims},
|
extractor::{OidcAccessToken, OidcClaims},
|
||||||
AdditionalClaims, BoxError, IdToken, OidcClient, OidcQuery, OidcSession, SESSION_KEY,
|
AdditionalClaims, BoxError, OidcClient, OidcQuery, OidcSession, SESSION_KEY,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Layer for the [OidcLoginMiddleware].
|
/// Layer for the [OidcLoginMiddleware].
|
||||||
|
@ -124,8 +118,10 @@ where
|
||||||
.extensions
|
.extensions
|
||||||
.get::<Session>()
|
.get::<Session>()
|
||||||
.ok_or(MiddlewareError::SessionNotFound)?;
|
.ok_or(MiddlewareError::SessionNotFound)?;
|
||||||
let login_session: Option<OidcSession> =
|
let login_session: Option<OidcSession> = session
|
||||||
session.get(SESSION_KEY).map_err(MiddlewareError::from)?;
|
.get(SESSION_KEY)
|
||||||
|
.await
|
||||||
|
.map_err(MiddlewareError::from)?;
|
||||||
|
|
||||||
let handler_uri =
|
let handler_uri =
|
||||||
strip_oidc_from_path(oidcclient.application_base_url.clone(), &parts.uri)?;
|
strip_oidc_from_path(oidcclient.application_base_url.clone(), &parts.uri)?;
|
||||||
|
@ -178,7 +174,7 @@ where
|
||||||
.refresh_token()
|
.refresh_token()
|
||||||
.map(|x| x.secret().to_string());
|
.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())
|
Ok(Redirect::temporary(&handler_uri.to_string()).into_response())
|
||||||
} else {
|
} else {
|
||||||
|
@ -208,7 +204,7 @@ where
|
||||||
refresh_token: None,
|
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())
|
Ok(Redirect::temporary(auth_url.as_str()).into_response())
|
||||||
}
|
}
|
||||||
|
@ -308,8 +304,10 @@ where
|
||||||
.extensions
|
.extensions
|
||||||
.get::<Session>()
|
.get::<Session>()
|
||||||
.ok_or(MiddlewareError::SessionNotFound)?;
|
.ok_or(MiddlewareError::SessionNotFound)?;
|
||||||
let mut login_session: Option<OidcSession> =
|
let mut login_session: Option<OidcSession> = session
|
||||||
session.get(SESSION_KEY).map_err(MiddlewareError::from)?;
|
.get(SESSION_KEY)
|
||||||
|
.await
|
||||||
|
.map_err(MiddlewareError::from)?;
|
||||||
|
|
||||||
let handler_uri =
|
let handler_uri =
|
||||||
strip_oidc_from_path(oidcclient.application_base_url.clone(), &parts.uri)?;
|
strip_oidc_from_path(oidcclient.application_base_url.clone(), &parts.uri)?;
|
||||||
|
@ -384,7 +382,7 @@ where
|
||||||
.get::<Session>()
|
.get::<Session>()
|
||||||
.ok_or(MiddlewareError::SessionNotFound)?;
|
.ok_or(MiddlewareError::SessionNotFound)?;
|
||||||
|
|
||||||
session.insert(SESSION_KEY, login_session).unwrap();
|
session.insert(SESSION_KEY, login_session).await.unwrap();
|
||||||
}
|
}
|
||||||
(None, None) => {}
|
(None, None) => {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue