use serde::{Deserialize, Serialize};
use crate::{
auth::jws::{ClientId, GrantId},
capabilities::Capability,
crypto::PublicKey,
};
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GrantSessionResponse {
pub token: String,
pub session: GrantSessionInfo,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GrantInfo {
pub grant_id: GrantId,
pub client_id: String,
pub capabilities: String,
pub issued_at: u64,
pub expires_at: u64,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GrantSessionInfo {
pub homeserver: PublicKey,
pub pubky: PublicKey,
pub client_id: ClientId,
pub capabilities: Vec<Capability>,
pub grant_id: GrantId,
pub token_expires_at: u64,
pub grant_expires_at: u64,
pub created_at: u64,
}
#[cfg(test)]
mod tests {
use crate::crypto::Keypair;
use super::*;
#[test]
fn grant_session_response_serde_roundtrip() {
let hs_kp = Keypair::random();
let user_kp = Keypair::random();
let response = GrantSessionResponse {
token: "eyJhbGciOiJFZERTQSIs.payload.signature".to_string(),
session: GrantSessionInfo {
homeserver: hs_kp.public_key(),
pubky: user_kp.public_key(),
client_id: ClientId::new("franky.pubky.app").unwrap(),
capabilities: vec![Capability::root()],
grant_id: GrantId::generate(),
token_expires_at: 1700003600,
grant_expires_at: 1763136000,
created_at: 1700000000,
},
};
let json = serde_json::to_string(&response).unwrap();
let parsed: GrantSessionResponse = serde_json::from_str(&json).unwrap();
assert_eq!(response, parsed);
}
}