From 578c259b95f9a893de3224c09c60c4f83f24da08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=B6rl?= Date: Sun, 21 Apr 2024 11:03:44 +0200 Subject: [PATCH] implement serialization for space_separated_strings --- src/auth.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/auth.rs b/src/auth.rs index 33c6655..65c5912 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,18 @@ where deserializer.deserialize_str(Visitor) } +fn serialize_space_separated_strings( + value: &[String], + serializer: S, +) -> std::result::Result +where + S: serde::ser::Serializer, +{ + // Join the strings in the Vec with a space separator + let space_separated = value.join(" "); + serializer.serialize_str(&space_separated) +} + #[cfg(test)] mod tests { use super::*;