use anyhow::{Context, Result};
use chrono::Utc;
use jsonwebtoken::{encode, EncodingKey, Header};
use serde::Serialize;
#[derive(Debug, Serialize)]
struct Claims {
iat: i64,
exp: i64,
iss: String,
}
pub fn sign_app_jwt(app_id: u64, private_key_pem: &str) -> Result<String> {
let now = Utc::now().timestamp();
let claims = Claims {
iat: now - 60, exp: now + 9 * 60,
iss: app_id.to_string(),
};
let key = EncodingKey::from_rsa_pem(private_key_pem.as_bytes())
.context("failed to parse RSA private key from PEM")?;
encode(&Header::new(jsonwebtoken::Algorithm::RS256), &claims, &key)
.context("failed to sign JWT")
}