tsk-51: Changes made related to icarus_models
This commit is contained in:
@@ -78,7 +78,7 @@ pub mod endpoint {
|
||||
if hashing::verify_password(&payload.password, user.password.clone()).unwrap() {
|
||||
// Create token
|
||||
let key = icarus_envy::environment::get_secret_key().await;
|
||||
let (token_literal, duration) = token_stuff::create_token(&key).unwrap();
|
||||
let (token_literal, duration) = token_stuff::create_token(&key, &user.id).unwrap();
|
||||
|
||||
if token_stuff::verify_token(&key, &token_literal) {
|
||||
let current_time = time::OffsetDateTime::now_utc();
|
||||
@@ -122,7 +122,7 @@ pub mod endpoint {
|
||||
match repo::service::valid_passphrase(&pool, &payload.passphrase).await {
|
||||
Ok((id, _passphrase, _date_created)) => {
|
||||
let key = icarus_envy::environment::get_secret_key().await;
|
||||
let (token_literal, duration) = token_stuff::create_service_token(&key).unwrap();
|
||||
let (token_literal, duration) = token_stuff::create_service_token(&key, &id).unwrap();
|
||||
|
||||
if token_stuff::verify_token(&key, &token_literal) {
|
||||
let login_result = icarus_models::login_result::LoginResult {
|
||||
|
@@ -20,20 +20,22 @@ pub fn get_expiration(issued: &time::OffsetDateTime) -> Result<time::OffsetDateT
|
||||
Ok(*issued + duration_expire)
|
||||
}
|
||||
|
||||
pub fn create_token(provided_key: &String) -> Result<(String, i64), josekit::JoseError> {
|
||||
pub fn create_token(provided_key: &String, id: &uuid::Uuid) -> Result<(String, i64), josekit::JoseError> {
|
||||
let resource = icarus_models::token::TokenResource {
|
||||
message: String::from(MESSAGE),
|
||||
issuer: String::from(ISSUER),
|
||||
audiences: vec![String::from(AUDIENCE)],
|
||||
id: *id,
|
||||
};
|
||||
icarus_models::token::create_token(provided_key, &resource, time::Duration::hours(4))
|
||||
}
|
||||
|
||||
pub fn create_service_token(provided: &String) -> Result<(String, i64), josekit::JoseError> {
|
||||
pub fn create_service_token(provided: &String, id: &uuid::Uuid) -> Result<(String, i64), josekit::JoseError> {
|
||||
let resource = icarus_models::token::TokenResource {
|
||||
message: String::from("Service random"),
|
||||
issuer: String::from(ISSUER),
|
||||
audiences: vec![String::from(AUDIENCE)],
|
||||
id: *id,
|
||||
};
|
||||
icarus_models::token::create_token(provided, &resource, time::Duration::hours(1))
|
||||
}
|
||||
|
Reference in New Issue
Block a user