Skip to content

Commit 51f4c00

Browse files
Style consistency
Use trailing comma in dictionaries. Use var instead of explicit type.
1 parent 72bcab6 commit 51f4c00

File tree

24 files changed

+89
-75
lines changed

24 files changed

+89
-75
lines changed

src/AspNet.Security.OAuth.ArcGIS/ArcGISAuthenticationHandler.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
3131
[NotNull] OAuthTokenResponse tokens)
3232
{
3333
// Note: the ArcGIS API doesn't support content negotiation via headers.
34-
string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string?>
34+
var parameters = new Dictionary<string, string?>
3535
{
3636
["f"] = "json",
37-
["token"] = tokens.AccessToken
38-
});
37+
["token"] = tokens.AccessToken,
38+
};
39+
40+
var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters!);
3941

4042
using var request = new HttpRequestMessage(HttpMethod.Get, address);
4143
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

src/AspNet.Security.OAuth.Ebay/EbayAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
6060
{
6161
["grant_type"] = "authorization_code",
6262
["code"] = context.Code,
63-
["redirect_uri"] = Options.RuName!
63+
["redirect_uri"] = Options.RuName!,
6464
};
6565

6666
// PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl
@@ -90,7 +90,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
9090

9191
private AuthenticationHeaderValue CreateAuthorizationHeader()
9292
{
93-
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(
93+
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(
9494
string.Concat(
9595
EscapeDataString(Options.ClientId),
9696
":",

src/AspNet.Security.OAuth.Fitbit/FitbitAuthenticationHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
5757
{
5858
["grant_type"] = "authorization_code",
5959
["redirect_uri"] = context.RedirectUri,
60-
["code"] = context.Code
60+
["code"] = context.Code,
6161
};
6262

6363
// PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl
@@ -97,7 +97,7 @@ private AuthenticationHeaderValue CreateAuthorizationHeader()
9797
return Uri.EscapeDataString(value).Replace("%20", "+", StringComparison.Ordinal);
9898
}
9999

100-
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(
100+
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(
101101
string.Concat(
102102
EscapeDataString(Options.ClientId),
103103
":",

src/AspNet.Security.OAuth.Foursquare/FoursquareAuthenticationHandler.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
3131
{
3232
// See https://developer.foursquare.com/overview/versioning
3333
// for more information about the mandatory "v" and "m" parameters.
34-
string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string?>
34+
var parameters = new Dictionary<string, string?>
3535
{
3636
["m"] = "foursquare",
3737
["v"] = !string.IsNullOrEmpty(Options.ApiVersion) ? Options.ApiVersion : FoursquareAuthenticationDefaults.ApiVersion,
3838
["oauth_token"] = tokens.AccessToken,
39-
});
39+
};
40+
41+
var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters);
4042

4143
using var request = new HttpRequestMessage(HttpMethod.Get, address);
4244

src/AspNet.Security.OAuth.Line/LineAuthenticationHandler.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
4040
["code"] = context.Code,
4141
["redirect_uri"] = context.RedirectUri,
4242
["client_id"] = Options.ClientId,
43-
["client_secret"] = Options.ClientSecret
43+
["client_secret"] = Options.ClientSecret,
4444
};
4545

4646
// PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl
@@ -89,7 +89,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
8989
// When the email address is not public, retrieve it from the emails endpoint if the user:email scope is specified.
9090
if (!string.IsNullOrEmpty(Options.UserEmailsEndpoint) && Options.Scope.Contains("email"))
9191
{
92-
string? email = await GetEmailAsync(tokens);
92+
var email = await GetEmailAsync(tokens);
9393

9494
if (!string.IsNullOrEmpty(email))
9595
{
@@ -103,14 +103,14 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
103103

104104
protected virtual async Task<string?> GetEmailAsync([NotNull] OAuthTokenResponse tokens)
105105
{
106-
using var request = new HttpRequestMessage(HttpMethod.Post, Options.UserEmailsEndpoint);
107-
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
108-
109106
var parameters = new Dictionary<string, string?>
110107
{
111108
["id_token"] = tokens.Response?.RootElement.GetString("id_token") ?? string.Empty,
112-
["client_id"] = Options.ClientId
109+
["client_id"] = Options.ClientId,
113110
};
111+
112+
using var request = new HttpRequestMessage(HttpMethod.Post, Options.UserEmailsEndpoint);
113+
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
114114
request.Content = new FormUrlEncodedContent(parameters);
115115

116116
using var response = await Backchannel.SendAsync(request, Context.RequestAborted);

src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationOptions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public LinkedInAuthenticationOptions()
106106

107107
private string GetFullName(JsonElement user)
108108
{
109-
string?[] nameParts = new string?[]
109+
var nameParts = new string?[]
110110
{
111111
GetMultiLocaleString(user, ProfileFields.FirstName),
112112
GetMultiLocaleString(user, ProfileFields.LastName),
@@ -134,7 +134,7 @@ private static IEnumerable<string> GetPictureUrls(JsonElement user)
134134
continue;
135135
}
136136

137-
string? pictureUrl = imageIdentifier
137+
var pictureUrl = imageIdentifier
138138
.EnumerateArray()
139139
.FirstOrDefault()
140140
.GetString("identifier");
@@ -161,13 +161,13 @@ private static IEnumerable<string> GetPictureUrls(JsonElement user)
161161
private static string? DefaultMultiLocaleStringResolver(IReadOnlyDictionary<string, string?> localizedValues, string? preferredLocale)
162162
{
163163
if (!string.IsNullOrEmpty(preferredLocale) &&
164-
localizedValues.TryGetValue(preferredLocale, out string? preferredLocaleValue))
164+
localizedValues.TryGetValue(preferredLocale, out var preferredLocaleValue))
165165
{
166166
return preferredLocaleValue;
167167
}
168168

169-
string currentUIKey = Thread.CurrentThread.CurrentUICulture.ToString().Replace('-', '_');
170-
if (localizedValues.TryGetValue(currentUIKey, out string? currentUIValue))
169+
var currentUIKey = Thread.CurrentThread.CurrentUICulture.ToString().Replace('-', '_');
170+
if (localizedValues.TryGetValue(currentUIKey, out var currentUIValue))
171171
{
172172
return currentUIValue;
173173
}

src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected override string BuildChallengeUrl([NotNull] AuthenticationProperties p
3636
{
3737
["client_id"] = Options.ClientId,
3838
["scope"] = scope,
39-
["response_type"] = "code"
39+
["response_type"] = "code",
4040
};
4141

4242
if (Options.UsePkce)

src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
4949
using var requestMessage = new HttpRequestMessage(HttpMethod.Post, Options.TokenEndpoint);
5050
requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
5151

52-
byte[] byteArray = Encoding.ASCII.GetBytes(Options.ClientId + ":" + Options.ClientSecret);
52+
var byteArray = Encoding.ASCII.GetBytes(Options.ClientId + ":" + Options.ClientSecret);
5353
requestMessage.Headers.Authorization =
5454
new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
5555
requestMessage.Content = requestContent;

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
3232
[NotNull] AuthenticationProperties properties,
3333
[NotNull] OAuthTokenResponse tokens)
3434
{
35-
string accessSecret = GetMD5Hash(tokens.AccessToken + Options.ClientSecret);
36-
string sign = GetMD5Hash($"application_key={Options.PublicSecret}format=jsonmethod=users.getCurrentUser{accessSecret}");
35+
var accessSecret = GetMD5Hash(tokens.AccessToken + Options.ClientSecret);
36+
var sign = GetMD5Hash($"application_key={Options.PublicSecret}format=jsonmethod=users.getCurrentUser{accessSecret}");
3737

38-
string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string?>
38+
var parameters = new Dictionary<string, string?>
3939
{
4040
["application_key"] = Options.PublicSecret ?? string.Empty,
4141
["format"] = "json",
4242
["method"] = "users.getCurrentUser",
4343
["sig"] = sign,
4444
["access_token"] = tokens.AccessToken,
45-
});
45+
};
46+
47+
var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters);
4648

4749
using var request = new HttpRequestMessage(HttpMethod.Get, address);
4850
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
@@ -70,7 +72,7 @@ protected override string FormatScope([NotNull] IEnumerable<string> scopes)
7072
private static string GetMD5Hash(string input)
7173
{
7274
#pragma warning disable CA5351
73-
byte[] hash = MD5.HashData(Encoding.UTF8.GetBytes(input));
75+
var hash = MD5.HashData(Encoding.UTF8.GetBytes(input));
7476
#pragma warning restore CA5351
7577

7678
return Convert.ToHexString(hash).ToLowerInvariant();

src/AspNet.Security.OAuth.QQ/QQAuthenticationHandler.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
3030
[NotNull] AuthenticationProperties properties,
3131
[NotNull] OAuthTokenResponse tokens)
3232
{
33-
(int errorCode, string? openId, string? unionId) = await GetUserIdentifierAsync(tokens);
33+
(var errorCode, var openId, var unionId) = await GetUserIdentifierAsync(tokens);
3434

3535
if (errorCode != 0 || string.IsNullOrEmpty(openId))
3636
{
@@ -43,12 +43,14 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
4343
identity.AddClaim(new Claim(QQAuthenticationConstants.Claims.UnionId, unionId, ClaimValueTypes.String, Options.ClaimsIssuer));
4444
}
4545

46-
string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string?>(3)
46+
var parameters = new Dictionary<string, string?>(3)
4747
{
4848
["oauth_consumer_key"] = Options.ClientId,
4949
["access_token"] = tokens.AccessToken,
5050
["openid"] = openId,
51-
});
51+
};
52+
53+
var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters);
5254

5355
using var response = await Backchannel.GetAsync(address);
5456
if (!response.IsSuccessStatusCode)
@@ -60,7 +62,7 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
6062
using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted);
6163
using var payload = JsonDocument.Parse(stream);
6264

63-
int status = payload.RootElement.GetProperty("ret").GetInt32();
65+
var status = payload.RootElement.GetProperty("ret").GetInt32();
6466

6567
if (status != 0)
6668
{
@@ -86,7 +88,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
8688
["redirect_uri"] = context.RedirectUri,
8789
["code"] = context.Code,
8890
["grant_type"] = "authorization_code",
89-
["fmt"] = "json" // Return JSON instead of x-www-form-urlencoded which is default due to historical reasons
91+
["fmt"] = "json", // Return JSON instead of x-www-form-urlencoded which is default due to historical reasons
9092
};
9193

9294
// PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl
@@ -96,7 +98,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
9698
context.Properties.Items.Remove(OAuthConstants.CodeVerifierKey);
9799
}
98100

99-
string address = QueryHelpers.AddQueryString(Options.TokenEndpoint, tokenRequestParameters);
101+
var address = QueryHelpers.AddQueryString(Options.TokenEndpoint, tokenRequestParameters);
100102

101103
using var request = new HttpRequestMessage(HttpMethod.Get, address);
102104

@@ -127,7 +129,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
127129
queryString.Add("unionid", "1");
128130
}
129131

130-
string address = QueryHelpers.AddQueryString(Options.UserIdentificationEndpoint, queryString);
132+
var address = QueryHelpers.AddQueryString(Options.UserIdentificationEndpoint, queryString);
131133
using var request = new HttpRequestMessage(HttpMethod.Get, address);
132134

133135
using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
@@ -142,7 +144,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
142144

143145
var payloadRoot = payload.RootElement;
144146

145-
int errorCode =
147+
var errorCode =
146148
payloadRoot.TryGetProperty("error", out var errorCodeElement) && errorCodeElement.ValueKind == JsonValueKind.Number ?
147149
errorCodeElement.GetInt32() :
148150
0;

0 commit comments

Comments
 (0)