Skip to content

Commit a4ce3d9

Browse files
committed
Deserialize vanilla openstack token with preconfigured jsonserializer
The default json.net serializer will helpfully reformat strings that appear to be date time strings for you, even when the destination property is a string. Use the preconfigured jsonserializer which has this disabled, to preserve the expires string as-is.
1 parent 3842728 commit a4ce3d9

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/corelib/Core/Providers/OpenStackIdentityProvider.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using Newtonsoft.Json;
23
using OpenStack;
34
using OpenStack.Authentication;
45

@@ -109,11 +110,12 @@ public override UserAccess GetUserAccess(CloudIdentity identity, bool forceCache
109110
if (response == null || response.Data == null)
110111
return null;
111112

112-
JToken userAccessObject = response.Data["access"];
113-
if (userAccessObject == null)
113+
// The defalut json serialization is helpfully formatting the expires date string. Use our custom serializer for this part to prevent chaos of timezone proportions.
114+
var rawJson = response.Data["access"]?.ToString(Formatting.None);
115+
if (rawJson == null)
114116
return null;
115117

116-
UserAccess access = userAccessObject.ToObject<UserAccess>();
118+
UserAccess access = OpenStackNet.Deserialize<UserAccess>(rawJson);
117119
if (access == null || access.Token == null)
118120
return null;
119121

src/corelib/OpenStackNet.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,26 @@ public static void ResetDefaults()
8989
}
9090
}
9191

92+
/// <summary>
93+
/// Deserializes an object from a json string representation.
94+
/// </summary>
95+
/// <typeparam name="T">The object type.</typeparam>
96+
/// <param name="json">The json string.</param>
97+
public static T Deserialize<T>(string json)
98+
{
99+
return Configuration.FlurlHttpSettings.JsonSerializer.Deserialize<T>(json);
100+
}
101+
102+
/// <summary>
103+
/// Serializes an object to a json string representation
104+
/// </summary>
105+
/// <param name="obj">The object.</param>
106+
/// <returns>The json string representation of the object.</returns>
107+
public static string Serialize(object obj)
108+
{
109+
return Configuration.FlurlHttpSettings.JsonSerializer.Serialize(obj);
110+
}
111+
92112
/// <summary>
93113
/// Provides global point for programmatically configuraing tracing
94114
/// </summary>

0 commit comments

Comments
 (0)