From 51f4c0065774d10ce18aec6c73c9a040d150e107 Mon Sep 17 00:00:00 2001 From: martincostello Date: Thu, 6 Jan 2022 14:16:17 +0000 Subject: [PATCH] Style consistency Use trailing comma in dictionaries. Use var instead of explicit type. --- .../ArcGISAuthenticationHandler.cs | 8 +++++--- .../EbayAuthenticationHandler.cs | 4 ++-- .../FitbitAuthenticationHandler.cs | 4 ++-- .../FoursquareAuthenticationHandler.cs | 6 ++++-- .../LineAuthenticationHandler.cs | 12 ++++++------ .../LinkedInAuthenticationOptions.cs | 10 +++++----- .../MixcloudAuthenticationHandler.cs | 2 +- .../NotionAuthenticationHandler.cs | 2 +- .../OdnoklassnikiAuthenticationHandler.cs | 12 +++++++----- .../QQAuthenticationHandler.cs | 18 ++++++++++-------- .../RedditAuthenticationHandler.cs | 6 +++--- .../ShopifyAuthenticationHandler.cs | 2 +- .../ShopifyAuthenticationProperties.cs | 4 ++-- .../StackExchangeAuthenticationHandler.cs | 6 +++--- .../UntappdAuthenticationHandler.cs | 18 +++++++++--------- .../VisualStudioAuthenticationHandler.cs | 2 +- .../VkontakteAuthenticationHandler.cs | 8 +++++--- .../WeiboAuthenticationHandler.cs | 12 +++++++----- .../WeixinAuthenticationHandler.cs | 4 ++-- .../WorkWeixinAuthenticationHandler.cs | 4 ++-- .../YahooAuthenticationHandler.cs | 4 ++-- .../YammerAuthenticationHandler.cs | 4 ++-- .../YandexAuthenticationHandler.cs | 2 +- .../ZaloAuthenticationHandler.cs | 10 ++++++---- 24 files changed, 89 insertions(+), 75 deletions(-) diff --git a/src/AspNet.Security.OAuth.ArcGIS/ArcGISAuthenticationHandler.cs b/src/AspNet.Security.OAuth.ArcGIS/ArcGISAuthenticationHandler.cs index 28ddc6757..afb1edb6c 100644 --- a/src/AspNet.Security.OAuth.ArcGIS/ArcGISAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.ArcGIS/ArcGISAuthenticationHandler.cs @@ -31,11 +31,13 @@ protected override async Task CreateTicketAsync( [NotNull] OAuthTokenResponse tokens) { // Note: the ArcGIS API doesn't support content negotiation via headers. - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary + var parameters = new Dictionary { ["f"] = "json", - ["token"] = tokens.AccessToken - }); + ["token"] = tokens.AccessToken, + }; + + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters!); using var request = new HttpRequestMessage(HttpMethod.Get, address); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.Ebay/EbayAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Ebay/EbayAuthenticationHandler.cs index cd30b6315..4fb0fa6ef 100644 --- a/src/AspNet.Security.OAuth.Ebay/EbayAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Ebay/EbayAuthenticationHandler.cs @@ -60,7 +60,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA { ["grant_type"] = "authorization_code", ["code"] = context.Code, - ["redirect_uri"] = Options.RuName! + ["redirect_uri"] = Options.RuName!, }; // PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl @@ -90,7 +90,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA private AuthenticationHeaderValue CreateAuthorizationHeader() { - string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes( + var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes( string.Concat( EscapeDataString(Options.ClientId), ":", diff --git a/src/AspNet.Security.OAuth.Fitbit/FitbitAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Fitbit/FitbitAuthenticationHandler.cs index fb5b4bf33..2eabb8a71 100644 --- a/src/AspNet.Security.OAuth.Fitbit/FitbitAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Fitbit/FitbitAuthenticationHandler.cs @@ -57,7 +57,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA { ["grant_type"] = "authorization_code", ["redirect_uri"] = context.RedirectUri, - ["code"] = context.Code + ["code"] = context.Code, }; // PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl @@ -97,7 +97,7 @@ private AuthenticationHeaderValue CreateAuthorizationHeader() return Uri.EscapeDataString(value).Replace("%20", "+", StringComparison.Ordinal); } - string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes( + var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes( string.Concat( EscapeDataString(Options.ClientId), ":", diff --git a/src/AspNet.Security.OAuth.Foursquare/FoursquareAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Foursquare/FoursquareAuthenticationHandler.cs index 14441aafa..9a6b5ab9f 100644 --- a/src/AspNet.Security.OAuth.Foursquare/FoursquareAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Foursquare/FoursquareAuthenticationHandler.cs @@ -31,12 +31,14 @@ protected override async Task CreateTicketAsync( { // See https://developer.foursquare.com/overview/versioning // for more information about the mandatory "v" and "m" parameters. - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary + var parameters = new Dictionary { ["m"] = "foursquare", ["v"] = !string.IsNullOrEmpty(Options.ApiVersion) ? Options.ApiVersion : FoursquareAuthenticationDefaults.ApiVersion, ["oauth_token"] = tokens.AccessToken, - }); + }; + + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters); using var request = new HttpRequestMessage(HttpMethod.Get, address); diff --git a/src/AspNet.Security.OAuth.Line/LineAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Line/LineAuthenticationHandler.cs index 9218036fa..fc9218d4d 100644 --- a/src/AspNet.Security.OAuth.Line/LineAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Line/LineAuthenticationHandler.cs @@ -40,7 +40,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA ["code"] = context.Code, ["redirect_uri"] = context.RedirectUri, ["client_id"] = Options.ClientId, - ["client_secret"] = Options.ClientSecret + ["client_secret"] = Options.ClientSecret, }; // PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl @@ -89,7 +89,7 @@ protected override async Task CreateTicketAsync( // When the email address is not public, retrieve it from the emails endpoint if the user:email scope is specified. if (!string.IsNullOrEmpty(Options.UserEmailsEndpoint) && Options.Scope.Contains("email")) { - string? email = await GetEmailAsync(tokens); + var email = await GetEmailAsync(tokens); if (!string.IsNullOrEmpty(email)) { @@ -103,14 +103,14 @@ protected override async Task CreateTicketAsync( protected virtual async Task GetEmailAsync([NotNull] OAuthTokenResponse tokens) { - using var request = new HttpRequestMessage(HttpMethod.Post, Options.UserEmailsEndpoint); - request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - var parameters = new Dictionary { ["id_token"] = tokens.Response?.RootElement.GetString("id_token") ?? string.Empty, - ["client_id"] = Options.ClientId + ["client_id"] = Options.ClientId, }; + + using var request = new HttpRequestMessage(HttpMethod.Post, Options.UserEmailsEndpoint); + request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Content = new FormUrlEncodedContent(parameters); using var response = await Backchannel.SendAsync(request, Context.RequestAborted); diff --git a/src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationOptions.cs b/src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationOptions.cs index 035c2ef0a..01322c0f4 100644 --- a/src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationOptions.cs +++ b/src/AspNet.Security.OAuth.LinkedIn/LinkedInAuthenticationOptions.cs @@ -106,7 +106,7 @@ public LinkedInAuthenticationOptions() private string GetFullName(JsonElement user) { - string?[] nameParts = new string?[] + var nameParts = new string?[] { GetMultiLocaleString(user, ProfileFields.FirstName), GetMultiLocaleString(user, ProfileFields.LastName), @@ -134,7 +134,7 @@ private static IEnumerable GetPictureUrls(JsonElement user) continue; } - string? pictureUrl = imageIdentifier + var pictureUrl = imageIdentifier .EnumerateArray() .FirstOrDefault() .GetString("identifier"); @@ -161,13 +161,13 @@ private static IEnumerable GetPictureUrls(JsonElement user) private static string? DefaultMultiLocaleStringResolver(IReadOnlyDictionary localizedValues, string? preferredLocale) { if (!string.IsNullOrEmpty(preferredLocale) && - localizedValues.TryGetValue(preferredLocale, out string? preferredLocaleValue)) + localizedValues.TryGetValue(preferredLocale, out var preferredLocaleValue)) { return preferredLocaleValue; } - string currentUIKey = Thread.CurrentThread.CurrentUICulture.ToString().Replace('-', '_'); - if (localizedValues.TryGetValue(currentUIKey, out string? currentUIValue)) + var currentUIKey = Thread.CurrentThread.CurrentUICulture.ToString().Replace('-', '_'); + if (localizedValues.TryGetValue(currentUIKey, out var currentUIValue)) { return currentUIValue; } diff --git a/src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationHandler.cs index 66475dc32..d0f2a8603 100644 --- a/src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Mixcloud/MixcloudAuthenticationHandler.cs @@ -36,7 +36,7 @@ protected override string BuildChallengeUrl([NotNull] AuthenticationProperties p { ["client_id"] = Options.ClientId, ["scope"] = scope, - ["response_type"] = "code" + ["response_type"] = "code", }; if (Options.UsePkce) diff --git a/src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs index 50393d4b5..8b337c187 100644 --- a/src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Notion/NotionAuthenticationHandler.cs @@ -49,7 +49,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA using var requestMessage = new HttpRequestMessage(HttpMethod.Post, Options.TokenEndpoint); requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - byte[] byteArray = Encoding.ASCII.GetBytes(Options.ClientId + ":" + Options.ClientSecret); + var byteArray = Encoding.ASCII.GetBytes(Options.ClientId + ":" + Options.ClientSecret); requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); requestMessage.Content = requestContent; diff --git a/src/AspNet.Security.OAuth.Odnoklassniki/OdnoklassnikiAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Odnoklassniki/OdnoklassnikiAuthenticationHandler.cs index 780eeaea1..5c1661123 100644 --- a/src/AspNet.Security.OAuth.Odnoklassniki/OdnoklassnikiAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Odnoklassniki/OdnoklassnikiAuthenticationHandler.cs @@ -32,17 +32,19 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string accessSecret = GetMD5Hash(tokens.AccessToken + Options.ClientSecret); - string sign = GetMD5Hash($"application_key={Options.PublicSecret}format=jsonmethod=users.getCurrentUser{accessSecret}"); + var accessSecret = GetMD5Hash(tokens.AccessToken + Options.ClientSecret); + var sign = GetMD5Hash($"application_key={Options.PublicSecret}format=jsonmethod=users.getCurrentUser{accessSecret}"); - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary + var parameters = new Dictionary { ["application_key"] = Options.PublicSecret ?? string.Empty, ["format"] = "json", ["method"] = "users.getCurrentUser", ["sig"] = sign, ["access_token"] = tokens.AccessToken, - }); + }; + + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters); using var request = new HttpRequestMessage(HttpMethod.Get, address); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -70,7 +72,7 @@ protected override string FormatScope([NotNull] IEnumerable scopes) private static string GetMD5Hash(string input) { #pragma warning disable CA5351 - byte[] hash = MD5.HashData(Encoding.UTF8.GetBytes(input)); + var hash = MD5.HashData(Encoding.UTF8.GetBytes(input)); #pragma warning restore CA5351 return Convert.ToHexString(hash).ToLowerInvariant(); diff --git a/src/AspNet.Security.OAuth.QQ/QQAuthenticationHandler.cs b/src/AspNet.Security.OAuth.QQ/QQAuthenticationHandler.cs index 9190057df..a4fba6ff2 100644 --- a/src/AspNet.Security.OAuth.QQ/QQAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.QQ/QQAuthenticationHandler.cs @@ -30,7 +30,7 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - (int errorCode, string? openId, string? unionId) = await GetUserIdentifierAsync(tokens); + (var errorCode, var openId, var unionId) = await GetUserIdentifierAsync(tokens); if (errorCode != 0 || string.IsNullOrEmpty(openId)) { @@ -43,12 +43,14 @@ protected override async Task CreateTicketAsync( identity.AddClaim(new Claim(QQAuthenticationConstants.Claims.UnionId, unionId, ClaimValueTypes.String, Options.ClaimsIssuer)); } - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary(3) + var parameters = new Dictionary(3) { ["oauth_consumer_key"] = Options.ClientId, ["access_token"] = tokens.AccessToken, ["openid"] = openId, - }); + }; + + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters); using var response = await Backchannel.GetAsync(address); if (!response.IsSuccessStatusCode) @@ -60,7 +62,7 @@ protected override async Task CreateTicketAsync( using var stream = await response.Content.ReadAsStreamAsync(Context.RequestAborted); using var payload = JsonDocument.Parse(stream); - int status = payload.RootElement.GetProperty("ret").GetInt32(); + var status = payload.RootElement.GetProperty("ret").GetInt32(); if (status != 0) { @@ -86,7 +88,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA ["redirect_uri"] = context.RedirectUri, ["code"] = context.Code, ["grant_type"] = "authorization_code", - ["fmt"] = "json" // Return JSON instead of x-www-form-urlencoded which is default due to historical reasons + ["fmt"] = "json", // Return JSON instead of x-www-form-urlencoded which is default due to historical reasons }; // PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl @@ -96,7 +98,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA context.Properties.Items.Remove(OAuthConstants.CodeVerifierKey); } - string address = QueryHelpers.AddQueryString(Options.TokenEndpoint, tokenRequestParameters); + var address = QueryHelpers.AddQueryString(Options.TokenEndpoint, tokenRequestParameters); using var request = new HttpRequestMessage(HttpMethod.Get, address); @@ -127,7 +129,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA queryString.Add("unionid", "1"); } - string address = QueryHelpers.AddQueryString(Options.UserIdentificationEndpoint, queryString); + var address = QueryHelpers.AddQueryString(Options.UserIdentificationEndpoint, queryString); using var request = new HttpRequestMessage(HttpMethod.Get, address); using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted); @@ -142,7 +144,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA var payloadRoot = payload.RootElement; - int errorCode = + var errorCode = payloadRoot.TryGetProperty("error", out var errorCodeElement) && errorCodeElement.ValueKind == JsonValueKind.Number ? errorCodeElement.GetInt32() : 0; diff --git a/src/AspNet.Security.OAuth.Reddit/RedditAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Reddit/RedditAuthenticationHandler.cs index 7faf5d457..4c7d96f5e 100644 --- a/src/AspNet.Security.OAuth.Reddit/RedditAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Reddit/RedditAuthenticationHandler.cs @@ -61,7 +61,7 @@ protected override async Task CreateTicketAsync( protected override string BuildChallengeUrl([NotNull] AuthenticationProperties properties, [NotNull] string redirectUri) { - string challengeUrl = base.BuildChallengeUrl(properties, redirectUri); + var challengeUrl = base.BuildChallengeUrl(properties, redirectUri); // Add duration=permanent to the authorization request to get an access token that doesn't expire after 1 hour. // See https://github.com/reddit/reddit/wiki/OAuth2#authorization for more information. @@ -87,7 +87,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA { ["grant_type"] = "authorization_code", ["redirect_uri"] = context.RedirectUri, - ["code"] = context.Code + ["code"] = context.Code, }; // PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl @@ -134,7 +134,7 @@ private AuthenticationHeaderValue CreateAuthorizationHeader() return Uri.EscapeDataString(value).Replace("%20", "+", StringComparison.Ordinal); } - string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes( + var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes( string.Concat( EscapeDataString(Options.ClientId), ":", diff --git a/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationHandler.cs index 083911204..e1eab6779 100644 --- a/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationHandler.cs @@ -153,7 +153,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA { ["client_id"] = Options.ClientId, ["client_secret"] = Options.ClientSecret, - ["code"] = context.Code + ["code"] = context.Code, }; // PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl diff --git a/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationProperties.cs b/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationProperties.cs index 73008ca13..f36fc28be 100644 --- a/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationProperties.cs +++ b/src/AspNet.Security.OAuth.Shopify/ShopifyAuthenticationProperties.cs @@ -55,7 +55,7 @@ public bool RequestPerUserToken { get { - string? prop = GetProperty(ShopifyAuthenticationDefaults.GrantOptionsAuthenticationProperty); + var prop = GetProperty(ShopifyAuthenticationDefaults.GrantOptionsAuthenticationProperty); return string.Equals(prop, ShopifyAuthenticationDefaults.PerUserAuthenticationPropertyValue, StringComparison.OrdinalIgnoreCase); } @@ -77,6 +77,6 @@ private void SetProperty(string propName, string? value) private string? GetProperty(string propName) { - return Items.TryGetValue(propName, out string? val) ? val : null; + return Items.TryGetValue(propName, out var val) ? val : null; } } diff --git a/src/AspNet.Security.OAuth.StackExchange/StackExchangeAuthenticationHandler.cs b/src/AspNet.Security.OAuth.StackExchange/StackExchangeAuthenticationHandler.cs index 1fe43f06e..abc8a99b5 100644 --- a/src/AspNet.Security.OAuth.StackExchange/StackExchangeAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.StackExchange/StackExchangeAuthenticationHandler.cs @@ -49,7 +49,7 @@ protected override async Task CreateTicketAsync( queryArguments["key"] = Options.RequestKey; } - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, queryArguments); + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, queryArguments); using var request = new HttpRequestMessage(HttpMethod.Get, address); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -79,7 +79,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA ["redirect_uri"] = context.RedirectUri, ["client_secret"] = Options.ClientSecret, ["code"] = context.Code, - ["grant_type"] = "authorization_code" + ["grant_type"] = "authorization_code", }; // PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl @@ -107,7 +107,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA var token = new JsonObject(); - foreach ((string key, StringValues value) in content) + foreach ((var key, var value) in content) { token[key] = value.ToString(); } diff --git a/src/AspNet.Security.OAuth.Untappd/UntappdAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Untappd/UntappdAuthenticationHandler.cs index 68d375987..8ca092402 100644 --- a/src/AspNet.Security.OAuth.Untappd/UntappdAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Untappd/UntappdAuthenticationHandler.cs @@ -44,17 +44,17 @@ protected override async Task ExchangeCodeAsync([NotNull] OA context.Properties.Items.Remove(OAuthConstants.CodeVerifierKey); } - using var requestContent = new FormUrlEncodedContent(tokenRequestParameters); + var parameters = new Dictionary + { + ["client_id"] = Options.ClientId, + ["redirect_uri"] = context.RedirectUri, + ["client_secret"] = Options.ClientSecret, + ["code"] = context.Code, + }; - string address = QueryHelpers.AddQueryString(Options.TokenEndpoint, - new Dictionary - { - ["client_id"] = Options.ClientId, - ["redirect_uri"] = context.RedirectUri, - ["client_secret"] = Options.ClientSecret, - ["code"] = context.Code - }); + var address = QueryHelpers.AddQueryString(Options.TokenEndpoint, parameters); + using var requestContent = new FormUrlEncodedContent(tokenRequestParameters); using var requestMessage = new HttpRequestMessage(HttpMethod.Get, address); requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); requestMessage.Content = requestContent; diff --git a/src/AspNet.Security.OAuth.VisualStudio/VisualStudioAuthenticationHandler.cs b/src/AspNet.Security.OAuth.VisualStudio/VisualStudioAuthenticationHandler.cs index 9ad8944df..921262712 100644 --- a/src/AspNet.Security.OAuth.VisualStudio/VisualStudioAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.VisualStudio/VisualStudioAuthenticationHandler.cs @@ -60,7 +60,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA ["client_assertion"] = Options.ClientSecret, ["assertion"] = context.Code, ["grant_type"] = "urn:ietf:params:oauth:grant-type:jwt-bearer", - ["client_assertion_type"] = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer" + ["client_assertion_type"] = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", }; // PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl diff --git a/src/AspNet.Security.OAuth.Vkontakte/VkontakteAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Vkontakte/VkontakteAuthenticationHandler.cs index ba27c2a69..0d36b1916 100644 --- a/src/AspNet.Security.OAuth.Vkontakte/VkontakteAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Vkontakte/VkontakteAuthenticationHandler.cs @@ -29,11 +29,13 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary + var parameters = new Dictionary { ["access_token"] = tokens.AccessToken, - ["v"] = !string.IsNullOrEmpty(Options.ApiVersion) ? Options.ApiVersion : VkontakteAuthenticationDefaults.ApiVersion - }); + ["v"] = !string.IsNullOrEmpty(Options.ApiVersion) ? Options.ApiVersion : VkontakteAuthenticationDefaults.ApiVersion, + }; + + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters); if (Options.Fields.Count != 0) { diff --git a/src/AspNet.Security.OAuth.Weibo/WeiboAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Weibo/WeiboAuthenticationHandler.cs index 79bf8e063..157539007 100644 --- a/src/AspNet.Security.OAuth.Weibo/WeiboAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Weibo/WeiboAuthenticationHandler.cs @@ -31,11 +31,13 @@ protected override async Task CreateTicketAsync( [NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) { - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary + var parameters = new Dictionary { ["access_token"] = tokens.AccessToken, - ["uid"] = tokens.Response!.RootElement.GetString("uid") - }); + ["uid"] = tokens.Response!.RootElement.GetString("uid"), + }; + + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters); using var request = new HttpRequestMessage(HttpMethod.Get, address); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -55,7 +57,7 @@ protected override async Task CreateTicketAsync( !identity.HasClaim(claim => claim.Type == ClaimTypes.Email) && Options.Scope.Contains("email")) { - string? email = await GetEmailAsync(tokens); + var email = await GetEmailAsync(tokens); if (!string.IsNullOrEmpty(address)) { @@ -82,7 +84,7 @@ protected override string FormatScope([NotNull] IEnumerable scopes) protected virtual async Task GetEmailAsync([NotNull] OAuthTokenResponse tokens) { // See http://open.weibo.com/wiki/2/account/profile/email for more information about the /account/profile/email.json endpoint. - string address = QueryHelpers.AddQueryString(Options.UserEmailsEndpoint, "access_token", tokens.AccessToken!); + var address = QueryHelpers.AddQueryString(Options.UserEmailsEndpoint, "access_token", tokens.AccessToken!); using var request = new HttpRequestMessage(HttpMethod.Get, address); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); diff --git a/src/AspNet.Security.OAuth.Weixin/WeixinAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Weixin/WeixinAuthenticationHandler.cs index f9b84a495..e3af29fab 100644 --- a/src/AspNet.Security.OAuth.Weixin/WeixinAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Weixin/WeixinAuthenticationHandler.cs @@ -57,7 +57,7 @@ protected override async Task CreateTicketAsync( var parameters = new Dictionary { ["access_token"] = tokens.AccessToken, - ["openid"] = tokens.Response?.RootElement.GetString("openid") + ["openid"] = tokens.Response?.RootElement.GetString("openid"), }; var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters); @@ -94,7 +94,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA ["appid"] = Options.ClientId, ["secret"] = Options.ClientSecret, ["code"] = context.Code, - ["grant_type"] = "authorization_code" + ["grant_type"] = "authorization_code", }; // PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl diff --git a/src/AspNet.Security.OAuth.WorkWeixin/WorkWeixinAuthenticationHandler.cs b/src/AspNet.Security.OAuth.WorkWeixin/WorkWeixinAuthenticationHandler.cs index 8e6e0e796..2a8aa3895 100644 --- a/src/AspNet.Security.OAuth.WorkWeixin/WorkWeixinAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.WorkWeixin/WorkWeixinAuthenticationHandler.cs @@ -43,7 +43,7 @@ protected override async Task CreateTicketAsync( var parameters = new Dictionary { ["access_token"] = tokens.AccessToken, - ["userid"] = userId + ["userid"] = userId, }; var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters); @@ -137,7 +137,7 @@ protected override string BuildChallengeUrl([NotNull] AuthenticationProperties p var parameters = new Dictionary { ["access_token"] = tokens.AccessToken, - ["code"] = Request.Query["code"] + ["code"] = Request.Query["code"], }; var address = QueryHelpers.AddQueryString(Options.UserIdentificationEndpoint, parameters); diff --git a/src/AspNet.Security.OAuth.Yahoo/YahooAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Yahoo/YahooAuthenticationHandler.cs index 174fc854f..bfa369bd0 100644 --- a/src/AspNet.Security.OAuth.Yahoo/YahooAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Yahoo/YahooAuthenticationHandler.cs @@ -58,7 +58,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA { ["grant_type"] = "authorization_code", ["redirect_uri"] = context.RedirectUri, - ["code"] = context.Code + ["code"] = context.Code, }; // PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl @@ -97,7 +97,7 @@ private AuthenticationHeaderValue CreateAuthorizationHeader() return Uri.EscapeDataString(value).Replace("%20", "+", StringComparison.Ordinal); } - string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes( + var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes( string.Concat( EscapeDataString(Options.ClientId), ":", diff --git a/src/AspNet.Security.OAuth.Yammer/YammerAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Yammer/YammerAuthenticationHandler.cs index 3526ec92d..9ae1414a5 100644 --- a/src/AspNet.Security.OAuth.Yammer/YammerAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Yammer/YammerAuthenticationHandler.cs @@ -59,7 +59,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA ["redirect_uri"] = context.RedirectUri, ["client_secret"] = Options.ClientSecret, ["code"] = context.Code, - ["grant_type"] = "authorization_code" + ["grant_type"] = "authorization_code", }; // PKCE https://tools.ietf.org/html/rfc7636#section-4.5, see BuildChallengeUrl @@ -84,7 +84,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA // with the OAuth2 generic middleware, a compliant JSON payload is generated manually. // See https://developer.yammer.com/docs/oauth-2 for more information about this process. using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted)); - string? accessToken = payload.RootElement.GetProperty("access_token").GetString("token"); + var accessToken = payload.RootElement.GetProperty("access_token").GetString("token"); var token = new { diff --git a/src/AspNet.Security.OAuth.Yandex/YandexAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Yandex/YandexAuthenticationHandler.cs index 1101b65e4..3da39262d 100644 --- a/src/AspNet.Security.OAuth.Yandex/YandexAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Yandex/YandexAuthenticationHandler.cs @@ -98,7 +98,7 @@ private AuthenticationHeaderValue CreateAuthorizationHeader() return Uri.EscapeDataString(value).Replace("%20", "+", StringComparison.Ordinal); } - string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes( + var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes( string.Concat( EscapeDataString(Options.ClientId), ":", diff --git a/src/AspNet.Security.OAuth.Zalo/ZaloAuthenticationHandler.cs b/src/AspNet.Security.OAuth.Zalo/ZaloAuthenticationHandler.cs index c084adb3d..33ab86c17 100644 --- a/src/AspNet.Security.OAuth.Zalo/ZaloAuthenticationHandler.cs +++ b/src/AspNet.Security.OAuth.Zalo/ZaloAuthenticationHandler.cs @@ -31,11 +31,13 @@ protected override async Task CreateTicketAsync( [NotNull] OAuthTokenResponse tokens) { // See https://developers.zalo.me/docs/api/social-api/tai-lieu/thong-tin-nguoi-dung-post-28 - string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary + var parameters = new Dictionary { ["access_token"] = tokens.AccessToken, - ["fields"] = "id,name,birthday,gender" - }); + ["fields"] = "id,name,birthday,gender", + }; + + var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, parameters); using var request = new HttpRequestMessage(HttpMethod.Get, address); @@ -79,7 +81,7 @@ protected override async Task ExchangeCodeAsync([NotNull] OA context.Properties.Items.Remove(OAuthConstants.CodeVerifierKey); } - string address = QueryHelpers.AddQueryString(Options.TokenEndpoint, tokenRequestParameters); + var address = QueryHelpers.AddQueryString(Options.TokenEndpoint, tokenRequestParameters); using var request = new HttpRequestMessage(HttpMethod.Get, address); using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);