summaryrefslogtreecommitdiff
path: root/src/token
diff options
context:
space:
mode:
Diffstat (limited to 'src/token')
-rw-r--r--src/token/extract/cookie.rs (renamed from src/token/extract/identity_token.rs)22
-rw-r--r--src/token/extract/identity.rs6
-rw-r--r--src/token/extract/mod.rs4
3 files changed, 16 insertions, 16 deletions
diff --git a/src/token/extract/identity_token.rs b/src/token/extract/cookie.rs
index a1e900e..af5787d 100644
--- a/src/token/extract/identity_token.rs
+++ b/src/token/extract/cookie.rs
@@ -12,19 +12,21 @@ use crate::token::Secret;
// The usage pattern here - receive the extractor as an argument, return it in
// the response - is heavily modelled after CookieJar's own intended usage.
#[derive(Clone)]
-pub struct IdentityToken {
+pub struct Identity {
cookies: CookieJar,
}
-impl fmt::Debug for IdentityToken {
+impl fmt::Debug for Identity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- f.debug_struct("IdentityToken")
+ f.debug_struct("IdentityCookie")
.field("identity", &self.secret())
.finish()
}
}
-impl IdentityToken {
+impl Identity {
+ const COOKIE_NAME: &str = "identity";
+
// Creates a new, unpopulated identity token store.
#[cfg(test)]
pub fn new() -> Self {
@@ -40,7 +42,7 @@ impl IdentityToken {
// included.
pub fn secret(&self) -> Option<Secret> {
self.cookies
- .get(IDENTITY_COOKIE)
+ .get(Self::COOKIE_NAME)
.map(Cookie::value)
.map(Secret::from)
}
@@ -49,7 +51,7 @@ impl IdentityToken {
// back to the client when this extractor is included in a response.
pub fn set(self, secret: impl Into<Secret>) -> Self {
let secret = secret.into().reveal();
- let identity_cookie = Cookie::build((IDENTITY_COOKIE, secret))
+ let identity_cookie = Cookie::build((Self::COOKIE_NAME, secret))
.http_only(true)
.path("/")
.permanent()
@@ -64,15 +66,13 @@ impl IdentityToken {
// extractor is included in a response.
pub fn clear(self) -> Self {
Self {
- cookies: self.cookies.remove(IDENTITY_COOKIE),
+ cookies: self.cookies.remove(Self::COOKIE_NAME),
}
}
}
-const IDENTITY_COOKIE: &str = "identity";
-
#[async_trait::async_trait]
-impl<S> FromRequestParts<S> for IdentityToken
+impl<S> FromRequestParts<S> for Identity
where
S: Send + Sync,
{
@@ -84,7 +84,7 @@ where
}
}
-impl IntoResponseParts for IdentityToken {
+impl IntoResponseParts for Identity {
type Error = <CookieJar as IntoResponseParts>::Error;
fn into_response_parts(self, res: ResponseParts) -> Result<ResponseParts, Self::Error> {
diff --git a/src/token/extract/identity.rs b/src/token/extract/identity.rs
index 8b3cd94..a69f509 100644
--- a/src/token/extract/identity.rs
+++ b/src/token/extract/identity.rs
@@ -4,7 +4,7 @@ use axum::{
response::{IntoResponse, Response},
};
-use super::IdentityToken;
+use super::IdentityCookie;
use crate::{
app::App,
@@ -25,10 +25,10 @@ impl FromRequestParts<App> for Identity {
type Rejection = LoginError<Internal>;
async fn from_request_parts(parts: &mut Parts, state: &App) -> Result<Self, Self::Rejection> {
- let Ok(identity_token) = IdentityToken::from_request_parts(parts, state).await;
+ let Ok(cookie) = IdentityCookie::from_request_parts(parts, state).await;
let RequestedAt(used_at) = RequestedAt::from_request_parts(parts, state).await?;
- let secret = identity_token.secret().ok_or(LoginError::Unauthorized)?;
+ let secret = cookie.secret().ok_or(LoginError::Unauthorized)?;
let app = State::<App>::from_request_parts(parts, state).await?;
match app.tokens().validate(&secret, &used_at).await {
diff --git a/src/token/extract/mod.rs b/src/token/extract/mod.rs
index b4800ae..fc0f52b 100644
--- a/src/token/extract/mod.rs
+++ b/src/token/extract/mod.rs
@@ -1,4 +1,4 @@
+mod cookie;
mod identity;
-mod identity_token;
-pub use self::{identity::Identity, identity_token::IdentityToken};
+pub use self::{cookie::Identity as IdentityCookie, identity::Identity};