use crate::{
support::{Jwt, UserClaims},
Auth, AuthResult,
};
use soph_config::support::config;
impl Auth {
pub fn new() -> AuthResult<Self> {
let config = config().parse::<crate::config::Auth>()?;
Ok(Self {
guard: Jwt::new(config.jwt),
})
}
pub fn authorize(&self, uid: String) -> AuthResult<String> {
self.guard.token(uid, None)
}
pub fn check(&self, token: &str) -> AuthResult<UserClaims> {
Ok(self.guard.validate(token)?.claims)
}
}
impl std::ops::Deref for Auth {
type Target = Jwt;
fn deref(&self) -> &Self::Target {
&self.guard
}
}