Compare commits

..
Author SHA1 Message Date
phoenix 3ea92ae64e bump: textsender_models
Release Tagging / release (pull_request) Successful in 36s
textsender_models PR / Check (pull_request) Successful in 1m22s
textsender_models PR / Clippy (pull_request) Successful in 1m34s
textsender_models PR / Rustfmt (pull_request) Successful in 32s
2026-06-22 23:14:00 -04:00
phoenix 0e8e0db284 Refactored function 2026-06-22 23:13:17 -04:00
3 changed files with 15 additions and 7 deletions
Generated
+1 -1
View File
@@ -1656,7 +1656,7 @@ dependencies = [
[[package]]
name = "textsender_models"
version = "0.4.3"
version = "0.4.10"
dependencies = [
"const_format",
"dotenvy",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "textsender_models"
version = "0.4.3"
version = "0.4.10"
edition = "2024"
rust-version = "1.96"
description = "Models used for the textsender project"
+13 -5
View File
@@ -70,11 +70,17 @@ pub struct TokenResource {
/// Token type
pub const TOKEN_TYPE: &str = "JWT";
pub struct CreateTokenResult {
pub access_token: String,
pub issued: i64,
pub expires_in: i64,
}
pub fn create_token(
key: &String,
token_resource: &TokenResource,
duration: time::Duration,
) -> Result<(String, i64), josekit::JoseError> {
) -> Result<CreateTokenResult, josekit::JoseError> {
let mut header = josekit::jws::JwsHeader::new();
header.set_token_type(TOKEN_TYPE);
@@ -102,10 +108,12 @@ pub fn create_token(
let signer = josekit::jws::alg::hmac::HmacJwsAlgorithm::Hs256
.signer_from_bytes(key.as_bytes())
.unwrap();
Ok((
josekit::jwt::encode_with_signer(&payload, &header, &signer).unwrap(),
(expire - time::OffsetDateTime::UNIX_EPOCH).whole_seconds(),
))
Ok(CreateTokenResult {
access_token: josekit::jwt::encode_with_signer(&payload, &header, &signer).unwrap(),
issued: (expire - time::OffsetDateTime::UNIX_EPOCH).whole_seconds(),
expires_in: (issued - time::OffsetDateTime::UNIX_EPOCH).whole_seconds(),
})
}
Err(e) => Err(josekit::JoseError::InvalidClaim(e.into())),
}