about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2025-04-09 23:10:30 +0300
committerVika <vika@fireburn.ru>2025-04-09 23:31:57 +0300
commit005efec015b3337e62037115d9fad05304161f97 (patch)
treec99ee10dee5447c83b1cbf3ac6f1e3d9fe16ac83
parentfa6e3fef17de18f80b5148b443d5f79f35d2dde2 (diff)
downloadkittybox-005efec015b3337e62037115d9fad05304161f97.tar.zst
kittybox-indieauth: 0.2.0 → 0.3.0
`ClientMetadata` now returns a `ClientIdMismatch` error type.

Change-Id: I51d3adfd2114f6cb89948bb5ba54588dde795142
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--indieauth/Cargo.toml4
-rw-r--r--indieauth/src/lib.rs30
-rw-r--r--templates/Cargo.toml2
5 files changed, 24 insertions, 16 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2b2092e..28723c7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1931,7 +1931,7 @@ dependencies = [
 
 [[package]]
 name = "kittybox-indieauth"
-version = "0.2.0"
+version = "0.3.0"
 dependencies = [
  "axum-core",
  "data-encoding",
diff --git a/Cargo.toml b/Cargo.toml
index 5293563..3e085db 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -106,7 +106,7 @@ features = ["fs", "axum"]
 version = "0.1.0"
 path = "./templates"
 [dependencies.kittybox-indieauth]
-version = "0.2.0"
+version = "0.3.0"
 path = "./indieauth"
 features = ["axum"]
 
diff --git a/indieauth/Cargo.toml b/indieauth/Cargo.toml
index 3bc3864..563c847 100644
--- a/indieauth/Cargo.toml
+++ b/indieauth/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "kittybox-indieauth"
-version = "0.2.0"
+version = "0.3.0"
 edition = "2021"
 
 [features]
@@ -9,7 +9,7 @@ axum = ["dep:axum-core", "dep:serde_json", "dep:http"]
 
 [dev-dependencies]
 serde_json = { workspace = true }       # A JSON serialization file format
-serde_urlencoded = { workspace = true }  # `x-www-form-urlencoded` meets Serde
+serde_urlencoded = { workspace = true } # `x-www-form-urlencoded` meets Serde
 
 [dependencies]
 axum-core = { workspace = true, optional = true }
diff --git a/indieauth/src/lib.rs b/indieauth/src/lib.rs
index 0fcd32c..459d943 100644
--- a/indieauth/src/lib.rs
+++ b/indieauth/src/lib.rs
@@ -36,20 +36,18 @@ pub use rand;
 /// mandatory.
 #[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
 #[non_exhaustive]
+#[serde(rename_all = "snake_case")]
 pub enum IntrospectionEndpointAuthMethod {
     /// `Authorization` header with a `Bearer` token.
+    #[serde(rename = "CamelCase")]
     Bearer,
     /// A token passed as part of a POST request.
-    #[serde(rename = "snake_case")]
     ClientSecretPost,
     /// Username and password passed using HTTP Basic authentication.
-    #[serde(rename = "snake_case")]
     ClientSecretBasic,
     /// TLS client auth with a certificate signed by a valid CA.
-    #[serde(rename = "snake_case")]
     TlsClientAuth,
     /// TLS client auth with a self-signed certificate.
-    #[serde(rename = "snake_case")]
     SelfSignedTlsClientAuth
 }
 
@@ -311,17 +309,27 @@ pub struct ClientMetadata {
     pub homepage_uri: Option<Url>
 }
 
+/// Error that occurs when creating [`ClientMetadata`] with mismatched `client_id` and `client_uri`.
+#[derive(Debug)]
+pub struct ClientIdMismatch;
+
+impl std::error::Error for ClientIdMismatch {}
+impl std::fmt::Display for ClientIdMismatch {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        write!(f, "client_id must be a prefix of client_uri")
+    }
+}
+
 impl ClientMetadata {
-    /// Create a new [`ClientMetadata`] with all the optional fields
-    /// omitted.
+    /// Create a new [`ClientMetadata`] with all the optional fields omitted.
     ///
     /// # Errors
     ///
-    /// Returns `()` if the `client_uri` is not a prefix of
-    /// `client_id` as required by the IndieAuth spec.
-    pub fn new(client_id: url::Url, client_uri: url::Url) -> Result<Self, ()> {
+    /// Returns `()` if the `client_uri` is not a prefix of `client_id` as required by the IndieAuth
+    /// spec.
+    pub fn new(client_id: url::Url, client_uri: url::Url) -> Result<Self, ClientIdMismatch> {
         if client_id.as_str().as_bytes()[..client_uri.as_str().len()] != *client_uri.as_str().as_bytes() {
-            return Err(());
+            return Err(ClientIdMismatch);
         }
 
         Ok(Self {
@@ -961,7 +969,7 @@ pub enum ErrorKind {
     /// AutoAuth/OAuth2 Device Flow: Access was denied by the
     /// authorization endpoint.
     AccessDenied,
-    
+
 }
 // TODO consider relying on serde_variant for these conversions
 impl AsRef<str> for ErrorKind {
diff --git a/templates/Cargo.toml b/templates/Cargo.toml
index 19855e6..ca56dfe 100644
--- a/templates/Cargo.toml
+++ b/templates/Cargo.toml
@@ -28,5 +28,5 @@ serde_json = { workspace = true }
 version = "0.3.0"
 path = "../util"
 [dependencies.kittybox-indieauth]
-version = "0.2.0"
+version = "0.3.0"
 path = "../indieauth"