soph_auth/support/
auth.rs1use crate::{
2 support::{Jwt, UserClaims},
3 Auth, AuthResult,
4};
5use soph_config::support::config;
6
7impl Auth {
8 pub fn new() -> AuthResult<Self> {
9 let config = config().parse::<crate::config::Auth>()?;
10
11 Ok(Self {
12 guard: Jwt::new(config.jwt),
13 })
14 }
15
16 pub fn authorize(&self, uid: String) -> AuthResult<String> {
17 self.guard.token(uid, None)
18 }
19
20 pub fn check(&self, token: &str) -> AuthResult<UserClaims> {
21 Ok(self.guard.validate(token)?.claims)
22 }
23}
24
25impl std::ops::Deref for Auth {
26 type Target = Jwt;
27
28 fn deref(&self) -> &Self::Target {
29 &self.guard
30 }
31}