web3-proxy/web3_proxy/src/user_token.rs

22 lines
489 B
Rust
Raw Normal View History

2022-10-28 09:38:21 +03:00
use axum::headers::authorization::Bearer;
use ulid::Ulid;
/// Key used for caching the user's login
pub struct UserBearerToken(pub Ulid);
impl TryFrom<Bearer> for UserBearerToken {
type Error = ulid::DecodeError;
fn try_from(b: Bearer) -> Result<Self, ulid::DecodeError> {
let u = Ulid::from_string(b.token())?;
Ok(UserBearerToken(u))
}
}
impl ToString for UserBearerToken {
fn to_string(&self) -> String {
format!("bearer:{}", self.0)
}
}