tsk-51: Code formatting
Some checks failed
Rust Build / Rustfmt (pull_request) Successful in 40s
Rust Build / Test Suite (pull_request) Failing after 39s
Rust Build / Check (pull_request) Failing after 1m3s
Rust Build / build (pull_request) Failing after 40s
Rust Build / Clippy (pull_request) Failing after 1m3s
Some checks failed
Rust Build / Rustfmt (pull_request) Successful in 40s
Rust Build / Test Suite (pull_request) Failing after 39s
Rust Build / Check (pull_request) Failing after 1m3s
Rust Build / build (pull_request) Failing after 40s
Rust Build / Clippy (pull_request) Failing after 1m3s
This commit is contained in:
@@ -78,7 +78,8 @@ 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, &user.id).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 +123,8 @@ 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, &id).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,7 +20,10 @@ pub fn get_expiration(issued: &time::OffsetDateTime) -> Result<time::OffsetDateT
|
||||
Ok(*issued + duration_expire)
|
||||
}
|
||||
|
||||
pub fn create_token(provided_key: &String, id: &uuid::Uuid) -> 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),
|
||||
@@ -30,7 +33,10 @@ pub fn create_token(provided_key: &String, id: &uuid::Uuid) -> Result<(String, i
|
||||
icarus_models::token::create_token(provided_key, &resource, time::Duration::hours(4))
|
||||
}
|
||||
|
||||
pub fn create_service_token(provided: &String, id: &uuid::Uuid) -> 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),
|
||||
@@ -42,44 +48,31 @@ pub fn create_service_token(provided: &String, id: &uuid::Uuid) -> Result<(Strin
|
||||
|
||||
pub fn verify_token(key: &String, token: &String) -> bool {
|
||||
match get_payload(key, token) {
|
||||
Ok((payload, _header)) => {
|
||||
match payload.subject() {
|
||||
Some(_sub) => true,
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
Err(_err) => {
|
||||
false
|
||||
}
|
||||
Ok((payload, _header)) => match payload.subject() {
|
||||
Some(_sub) => true,
|
||||
None => false,
|
||||
},
|
||||
Err(_err) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extract_id_from_token(key: &String, token: &String) -> Result<uuid::Uuid, std::io::Error> {
|
||||
match get_payload(key, token) {
|
||||
Ok((payload, _header)) => {
|
||||
match payload.claim("id") {
|
||||
Some(id) => {
|
||||
match uuid::Uuid::parse_str(id.as_str().unwrap()) {
|
||||
Ok(extracted) => {
|
||||
Ok(extracted)
|
||||
}
|
||||
Err(err) => {
|
||||
Err(std::io::Error::other(err.to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
Err(std::io::Error::other("No claim found"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
Err(std::io::Error::other(err.to_string()))
|
||||
}
|
||||
Ok((payload, _header)) => match payload.claim("id") {
|
||||
Some(id) => match uuid::Uuid::parse_str(id.as_str().unwrap()) {
|
||||
Ok(extracted) => Ok(extracted),
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
},
|
||||
None => Err(std::io::Error::other("No claim found")),
|
||||
},
|
||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_payload(key: &String, token: &String) -> Result<(josekit::jwt::JwtPayload, josekit::jws::JwsHeader), josekit::JoseError> {
|
||||
fn get_payload(
|
||||
key: &String,
|
||||
token: &String,
|
||||
) -> Result<(josekit::jwt::JwtPayload, josekit::jws::JwsHeader), josekit::JoseError> {
|
||||
let ver = Hs256.verifier_from_bytes(key.as_bytes()).unwrap();
|
||||
jwt::decode_with_verifier(token, &ver)
|
||||
}
|
||||
|
Reference in New Issue
Block a user