From 29b26900f48b67a6f1b3b9675a76ebf4f72c9afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=B6rl?= Date: Sun, 21 Apr 2024 11:07:44 +0200 Subject: [PATCH] implement serialization for space_separated_strings --- src/auth.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index 33c6655..02aa8fa 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -354,7 +354,8 @@ pub struct TokenResponse { /// Indicates the token type value. The only type that Azure AD supports is Bearer. pub token_type: String, /// A list of the Microsoft Graph permissions that the access_token is valid for. - #[serde(deserialize_with = "space_separated_strings")] + #[serde(deserialize_with = "deserialize_space_separated_strings")] + #[serde(serialize_with = "serialize_space_separated_strings")] pub scope: Vec, /// How long the access token is valid (in seconds). #[serde(rename = "expires_in")] @@ -385,7 +386,9 @@ impl fmt::Debug for TokenResponse { } } -fn space_separated_strings<'de, D>(deserializer: D) -> std::result::Result, D::Error> +fn deserialize_space_separated_strings<'de, D>( + deserializer: D, +) -> std::result::Result, D::Error> where D: serde::de::Deserializer<'de>, { @@ -409,6 +412,17 @@ where deserializer.deserialize_str(Visitor) } +fn serialize_space_separated_strings( + value: &[String], + serializer: S, +) -> std::result::Result +where + S: serde::ser::Serializer, +{ + let space_separated = value.join(" "); + serializer.serialize_str(&space_separated) +} + #[cfg(test)] mod tests { use super::*;