Skip to content

Commit

Permalink
Update SpotifyOAuth2Provider.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Sep 11, 2023
1 parent 9b96d5f commit f7f527b
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions MusicTypeChat/SpotifyOAuth2Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,19 @@ protected override async Task<Dictionary<string, string>> CreateAuthInfoAsync(st
var json = await DefaultUserProfileUrl
.GetJsonFromUrlAsync(request => { request.Headers.Add("Authorization", "Bearer " + accessToken); },
token: token).ConfigAwait();
var obj = JsonObject.Parse(json);
var obj = (Dictionary<string,object>) JSON.parse(json);

obj.Add("name", obj["display_name"]);
obj.MoveKey("id", "user_id");
if (obj.ContainsKey("images") && !string.IsNullOrEmpty(obj["images"]))
if (obj.TryGetValue("images", out var oImages) && oImages is List<object> { Count: > 0 } images)
{
if (JsonNode.Parse(obj["images"]) is JsonArray { Count: > 0 } imagesArray)
var firstImage = (Dictionary<string, object>)images[0];
if (firstImage.TryGetValue("url", out var oUrl) && oUrl is string url)
{
var firstImage = imagesArray[0]?.AsObject();
if (firstImage != null && ((IDictionary<string, JsonNode?>)firstImage).TryGetValue("url", out var value))
{
obj[AuthMetadataProvider.ProfileUrlKey] = value?.ToString();
}
obj[AuthMetadataProvider.ProfileUrlKey] = url;
}
}
return obj;
var objStr = obj.ToStringDictionary();
return objStr;
}
}

0 comments on commit f7f527b

Please sign in to comment.