about summary refs log tree commit diff
path: root/kittybox-rs/indieauth/src/pkce.rs
diff options
context:
space:
mode:
Diffstat (limited to 'kittybox-rs/indieauth/src/pkce.rs')
-rw-r--r--kittybox-rs/indieauth/src/pkce.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/kittybox-rs/indieauth/src/pkce.rs b/kittybox-rs/indieauth/src/pkce.rs
index 249917e..511b9fc 100644
--- a/kittybox-rs/indieauth/src/pkce.rs
+++ b/kittybox-rs/indieauth/src/pkce.rs
@@ -10,12 +10,22 @@ pub enum PKCEMethod {
     //#[default]
     S256,
     /// Plain string by itself. Please don't use this.
+    #[serde(rename = "snake_case")]
     Plain
 }
 // manual impl until Rust 1.62 hits nixos-unstable
 impl Default for PKCEMethod {
     fn default() -> Self { PKCEMethod::S256 }
 }
+impl PKCEMethod {
+    /// Return a string representing a PKCE method as it would be serialized.
+    pub fn as_str(&self) -> &'static str {
+        match self {
+            PKCEMethod::S256 => "S256",
+            PKCEMethod::Plain => "plain"
+        }
+    }
+}
 /// A PKCE verifier string that should be kept in secret until the end
 /// of the authentication ceremony, where it is revealed to prove that
 /// the one who uses the grant is the same entity who it was given to.
@@ -51,6 +61,7 @@ impl PKCEVerifier {
 #[derive(Eq, PartialEq, Debug, Clone, Serialize, Deserialize)]
 pub struct PKCEChallenge {
     code_challenge: String,
+    #[serde(rename = "code_challenge_method")]
     method: PKCEMethod
 }
 
@@ -88,4 +99,14 @@ impl PKCEChallenge {
     pub fn verify(&self, code_verifier: PKCEVerifier) -> bool {
         Self::new(code_verifier, self.method) == *self
     }
+
+    /// Return a reference to the code challenge string.
+    pub fn as_str(&self) -> &str {
+        self.code_challenge.as_str()
+    }
+
+    /// Return the method used to create this challenge.
+    pub fn method(&self) -> PKCEMethod {
+        self.method
+    }
 }