Skip to content

Commit 9df86af

Browse files
sla1kkevinchalet
authored andcommitted
Update the Vkontakte provider to specify an explicit API version
1 parent 3789cfb commit 9df86af

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

src/AspNet.Security.OAuth.Vkontakte/VkontakteAuthenticationDefaults.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,10 @@ public static class VkontakteAuthenticationDefaults
4747
/// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>.
4848
/// </summary>
4949
public const string UserInformationEndpoint = "https://api.vk.com/method/users.get.json";
50+
51+
/// <summary>
52+
/// Default API version.
53+
/// </summary>
54+
public const string ApiVersion = "5.78";
5055
}
5156
}

src/AspNet.Security.OAuth.Vkontakte/VkontakteAuthenticationHandler.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* for more information concerning the license and the contributors participating to this project.
55
*/
66

7+
using System.Collections.Generic;
78
using System.Net.Http;
89
using System.Security.Claims;
910
using System.Threading.Tasks;
@@ -27,7 +28,11 @@ public VkontakteAuthenticationHandler(HttpClient client)
2728

2829
protected override async Task<AuthenticationTicket> CreateTicketAsync([NotNull] ClaimsIdentity identity, [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens)
2930
{
30-
var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "access_token", tokens.AccessToken);
31+
var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string>
32+
{
33+
["access_token"] = tokens.AccessToken,
34+
["v"] = !string.IsNullOrEmpty(Options.ApiVersion) ? Options.ApiVersion : VkontakteAuthenticationDefaults.ApiVersion
35+
});
3136

3237
if (Options.Fields.Count != 0)
3338
{

src/AspNet.Security.OAuth.Vkontakte/VkontakteAuthenticationHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static string GetId([NotNull] JObject user)
2626
throw new ArgumentNullException(nameof(user));
2727
}
2828

29-
return user.Value<string>("uid");
29+
return user.Value<string>("id");
3030
}
3131

3232
/// <summary>

src/AspNet.Security.OAuth.Vkontakte/VkontakteAuthenticationOptions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ public VkontakteAuthenticationOptions()
3737
/// </summary>
3838
public ISet<string> Fields { get; } = new HashSet<string>
3939
{
40-
"uid",
40+
"id",
4141
"first_name",
4242
"last_name",
4343
"photo_rec",
4444
"photo",
4545
"hash"
4646
};
47+
48+
/// <summary>
49+
/// Gets or sets the VKontakte API version.
50+
/// See https://vk.com/dev/versions for more information.
51+
/// </summary>
52+
public string ApiVersion { get; set; } = VkontakteAuthenticationDefaults.ApiVersion;
4753
}
4854
}

0 commit comments

Comments
 (0)