tsk-50: Create Special endpoint for services to obtain a token (#53)
All checks were successful
Rust Build / Check (push) Successful in 32s
Release Tagging / release (push) Successful in 51s
Rust Build / Rustfmt (push) Successful in 25s
Rust Build / build (push) Successful in 42s
Rust Build / Check (pull_request) Successful in 36s
Rust Build / Clippy (push) Successful in 2m2s
Rust Build / Test Suite (pull_request) Successful in 42s
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / Clippy (pull_request) Successful in 37s
Rust Build / Test Suite (push) Successful in 3m57s
Rust Build / build (pull_request) Successful in 3m14s

Reviewed-on: #53
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
2025-08-03 23:09:50 +00:00
committed by phoenix
parent 5967ed5b13
commit 99390ce8b7
11 changed files with 186 additions and 28 deletions

View File

@@ -29,6 +29,15 @@ pub fn create_token(provided_key: &String) -> Result<(String, i64), josekit::Jos
icarus_models::token::create_token(provided_key, &resource, time::Duration::hours(4))
}
pub fn create_service_token(provided: &String) -> 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)],
};
icarus_models::token::create_token(provided, &resource, time::Duration::hours(1))
}
pub fn verify_token(key: &String, token: &String) -> bool {
let ver = Hs256.verifier_from_bytes(key.as_bytes()).unwrap();
let (payload, _header) = jwt::decode_with_verifier(token, &ver).unwrap();