feat(oauth2): get access token route and read basic user info

This commit is contained in:
Matthieu Bessat 2024-11-11 14:49:17 +01:00
parent ecf1da2978
commit f990708052
32 changed files with 465 additions and 67 deletions

View file

@ -0,0 +1,49 @@
use fully_pub::fully_pub;
use jsonwebtoken::get_current_timestamp;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
#[fully_pub]
struct UserTokenClaims {
/// subject: user id
sub: String,
/// token expiration
exp: u64,
/// token issuer
iss: String
// TODO: add roles
}
impl UserTokenClaims {
pub fn from_user_id(user_id: &str) -> Self {
UserTokenClaims {
sub: user_id.into(),
exp: get_current_timestamp() + 86_000,
iss: "Minauth".into()
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[fully_pub]
struct AppUserTokenClaims {
/// combined subject
client_id: String,
user_id: String,
/// token expiration
exp: u64,
/// token issuer
iss: String
}
impl AppUserTokenClaims {
pub fn from_client_user_id(client_id: &str, user_id: &str) -> Self {
AppUserTokenClaims {
client_id: client_id.into(),
user_id: user_id.into(),
exp: get_current_timestamp() + 86_000,
iss: "Minauth".into()
}
}
}