Skip to content

Commit 0d9bc1f

Browse files
dyzymartincostello
authored andcommitted
Odnoklassniki provider: Comments for options, code cleanup.
1 parent f3f5b2f commit 0d9bc1f

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

src/AspNet.Security.OAuth.Odnoklassniki/OdnoklassnikiAuthenticationDefaults.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,5 @@ public static class OdnoklassnikiAuthenticationDefaults
4848
/// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>.
4949
/// </summary>
5050
public const string UserInformationEndpoint = "https://api.ok.ru/fb.do";
51-
5251
}
5352
}

src/AspNet.Security.OAuth.Odnoklassniki/OdnoklassnikiAuthenticationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static AuthenticationBuilder AddOdnoklassniki([NotNull] this Authenticati
3232
/// <see cref="AuthenticationBuilder"/>, which enables Odnoklassniki authentication capabilities.
3333
/// </summary>
3434
/// <param name="builder">The authentication builder.</param>
35-
/// <param name="configuration">The delegate used to configure the OpenID 2.0 options.</param>
35+
/// <param name="configuration">The delegate used to configure the OAuth 2.0 options.</param>
3636
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
3737
public static AuthenticationBuilder AddOdnoklassniki(
3838
[NotNull] this AuthenticationBuilder builder,

src/AspNet.Security.OAuth.Odnoklassniki/OdnoklassnikiAuthenticationHandler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
using System.Collections.Generic;
8-
using System.Linq;
8+
using System.Globalization;
99
using System.Net.Http;
1010
using System.Net.Http.Headers;
1111
using System.Security.Claims;
@@ -38,10 +38,10 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync([NotNull]
3838
[NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens)
3939
{
4040
string sign;
41-
using (var md5Hash = MD5.Create())
41+
using (var algorithm = MD5.Create())
4242
{
43-
var accessSecret = GetMd5Hash(md5Hash, tokens.AccessToken + Options.ClientSecret);
44-
sign = GetMd5Hash(md5Hash,$"application_key={Options.PublicSecret}format=jsonmethod=users.getCurrentUser{accessSecret}");
43+
var accessSecret = GetMd5Hash(algorithm, tokens.AccessToken + Options.ClientSecret);
44+
sign = GetMd5Hash(algorithm, $"application_key={Options.PublicSecret}format=jsonmethod=users.getCurrentUser{accessSecret}");
4545
}
4646

4747
var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string>
@@ -82,7 +82,7 @@ private static string GetMd5Hash(HashAlgorithm hashAlgorithm, string input)
8282
{
8383
var sBuilder = new StringBuilder();
8484
foreach (var t in hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes(input)))
85-
sBuilder.Append(t.ToString("x2"));
85+
sBuilder.Append(t.ToString("x2", CultureInfo.InvariantCulture));
8686
return sBuilder.ToString();
8787
}
8888
}

src/AspNet.Security.OAuth.Odnoklassniki/OdnoklassnikiAuthenticationOptions.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,26 @@
77
using System.Security.Claims;
88
using Microsoft.AspNetCore.Authentication;
99
using Microsoft.AspNetCore.Authentication.OAuth;
10-
using Microsoft.AspNetCore.Http;
1110
using static AspNet.Security.OAuth.Odnoklassniki.OdnoklassnikiAuthenticationConstants;
1211

1312
namespace AspNet.Security.OAuth.Odnoklassniki
1413
{
1514
/// <summary>
1615
/// Defines a set of options used by <see cref="OdnoklassnikiAuthenticationHandler"/>.
16+
/// App registration could be performed by using next instruction: https://apiok.ru/dev/app/create.
17+
/// After registration you will receive email with 3 parameters:
18+
/// 1. Application ID - mapped to ClientId
19+
/// 2. Public App key - mapped to PublicSecret
20+
/// 3. Secret App key - mapped to ClientSecret
21+
/// Email retrieval requires request to provider on [email protected] for GET_EMAIL permission (https://apiok.ru/ext/oauth/permissions).
1722
/// </summary>
1823
public class OdnoklassnikiAuthenticationOptions : OAuthOptions
1924
{
20-
public string PublicSecret { get; set; }
21-
2225
public OdnoklassnikiAuthenticationOptions()
2326
{
2427
ClaimsIssuer = OdnoklassnikiAuthenticationDefaults.Issuer;
2528

26-
CallbackPath = new PathString(OdnoklassnikiAuthenticationDefaults.CallbackPath);
29+
CallbackPath = OdnoklassnikiAuthenticationDefaults.CallbackPath;
2730

2831
AuthorizationEndpoint = OdnoklassnikiAuthenticationDefaults.AuthorizationEndpoint;
2932
TokenEndpoint = OdnoklassnikiAuthenticationDefaults.TokenEndpoint;
@@ -40,5 +43,9 @@ public OdnoklassnikiAuthenticationOptions()
4043
ClaimActions.MapJsonKey(Claims.ImageUrl, "pic_2");
4144
}
4245

46+
/// <summary>
47+
/// Public App Key from application registration email.
48+
/// </summary>
49+
public string PublicSecret { get; set; }
4350
}
4451
}

0 commit comments

Comments
 (0)