- generate JWT id_token in token exchange - store optional nonce in authorization object - switch to RS256 algorithm for JWT signature - add JWKs endpoint to provide OIDC clients with public keys
61 lines
1.5 KiB
Rust
61 lines
1.5 KiB
Rust
use fully_pub::fully_pub;
|
|
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
use sqlx::types::Json;
|
|
use utils::get_random_human_token;
|
|
use uuid::Uuid;
|
|
|
|
#[derive(sqlx::Type, Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
#[derive(strum_macros::Display)]
|
|
#[fully_pub]
|
|
enum UserStatus {
|
|
Disabled,
|
|
Invited,
|
|
Active
|
|
}
|
|
|
|
#[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)]
|
|
#[fully_pub]
|
|
struct User {
|
|
/// uuid
|
|
id: String,
|
|
handle: String,
|
|
full_name: Option<String>,
|
|
email: Option<String>,
|
|
website: Option<String>,
|
|
avatar_asset_id: Option<String>,
|
|
password_hash: Option<String>, // argon2 password hash
|
|
status: UserStatus,
|
|
roles: Json<Vec<String>>,
|
|
reset_password_token: Option<String>,
|
|
|
|
last_login_at: Option<DateTime<Utc>>,
|
|
created_at: DateTime<Utc>
|
|
}
|
|
|
|
impl User {
|
|
pub fn new(
|
|
handle: String
|
|
) -> User {
|
|
User {
|
|
id: Uuid::new_v4().to_string(),
|
|
handle,
|
|
full_name: None,
|
|
email: None,
|
|
website: None,
|
|
avatar_asset_id: None,
|
|
password_hash: None,
|
|
status: UserStatus::Disabled,
|
|
roles: Json(Vec::new()),
|
|
reset_password_token: None,
|
|
last_login_at: None,
|
|
created_at: Utc::now()
|
|
}
|
|
}
|
|
|
|
pub fn invite(self: &mut Self) {
|
|
self.reset_password_token = Some(get_random_human_token());
|
|
self.status = UserStatus::Invited;
|
|
}
|
|
|
|
}
|