Skip to main content

aauth_protocol/
metadata.rs

1//! Metadata documents, published at `{issuer}/.well-known/{dwk}`.
2
3use serde::{Deserialize, Serialize};
4
5/// The `dwk` ("document well-known") names of each role's metadata document.
6pub mod dwk {
7    /// An agent provider's.
8    pub const AGENT: &str = "aauth-agent.json";
9    /// A Person Server's.
10    pub const PERSON: &str = "aauth-person.json";
11    /// A resource's.
12    pub const RESOURCE: &str = "aauth-resource.json";
13    /// An Access Server's.
14    pub const ACCESS: &str = "aauth-access.json";
15
16    /// Whether `name` is one of the four.
17    pub fn is_known(name: &str) -> bool {
18        [AGENT, PERSON, RESOURCE, ACCESS].contains(&name)
19    }
20}
21
22/// The URL a metadata document is published at.
23///
24/// ```
25/// # use aauth_protocol::metadata::{dwk, metadata_url};
26/// assert_eq!(
27///     metadata_url("https://ps.example/", dwk::PERSON),
28///     "https://ps.example/.well-known/aauth-person.json"
29/// );
30/// ```
31pub fn metadata_url(issuer: &str, dwk: &str) -> String {
32    format!("{}/.well-known/{dwk}", crate::identifier::trim(issuer))
33}
34
35/// A Person Server's `aauth-person.json`.
36#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
37pub struct PersonServerMetadata {
38    /// The Person Server's server identifier.
39    pub issuer: String,
40    /// Where an agent exchanges a resource token for an auth token.
41    pub auth_token_endpoint: String,
42    /// Where an agent asks for a person token. Only for resources that ask
43    /// for one; a three-party Person Server need not publish it.
44    #[serde(default, skip_serializing_if = "Option::is_none")]
45    pub person_token_endpoint: Option<String>,
46    /// Where an agent proposes, updates and completes missions.
47    #[serde(default, skip_serializing_if = "Option::is_none")]
48    pub mission_endpoint: Option<String>,
49    /// The keys its tokens are signed with.
50    #[serde(default, skip_serializing_if = "Option::is_none")]
51    pub jwks_uri: Option<String>,
52    /// A display name.
53    #[serde(default, skip_serializing_if = "Option::is_none")]
54    pub name: Option<String>,
55    /// A display description.
56    #[serde(default, skip_serializing_if = "Option::is_none")]
57    pub description: Option<String>,
58}
59
60/// The part of any role's metadata document that key discovery reads.
61#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
62pub struct KeyedMetadata {
63    /// The issuer the document describes. When present it must be the one
64    /// the document was fetched under.
65    #[serde(default, skip_serializing_if = "Option::is_none")]
66    pub issuer: Option<String>,
67    /// Where the issuer's keys are published.
68    #[serde(default, skip_serializing_if = "Option::is_none")]
69    pub jwks_uri: Option<String>,
70    /// The issuer's keys, inline instead of at `jwks_uri`.
71    #[serde(default, skip_serializing_if = "Option::is_none")]
72    pub jwks: Option<crate::jwk::Jwks>,
73    /// A display name.
74    #[serde(default, skip_serializing_if = "Option::is_none")]
75    pub name: Option<String>,
76}