feat(oauth2): get access token route and read basic user info
This commit is contained in:
parent
ecf1da2978
commit
f990708052
32 changed files with 465 additions and 67 deletions
49
src/models/token_claims.rs
Normal file
49
src/models/token_claims.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue