Skip to content

Commit

Permalink
Add minimal StyleCop analyzers
Browse files Browse the repository at this point in the history
Add minimal StyleCop analyzers and fix warnings, such as missing/incorrect license headers and trailing whitespace.
  • Loading branch information
martincostello committed Feb 15, 2020
1 parent 7cd6706 commit 77552be
Show file tree
Hide file tree
Showing 31 changed files with 94 additions and 34 deletions.
20 changes: 20 additions & 0 deletions AspNet.Security.OAuth.Providers.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,24 @@
<Rule Id="CA2208" Action="None" />
<Rule Id="CA2234" Action="None" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="AD0001" Action="None" />
<Rule Id="SA0001" Action="None" />
<Rule Id="SA1100" Action="None" />
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1116" Action="None" />
<Rule Id="SA1129" Action="None" />
<Rule Id="SA1201" Action="None" />
<Rule Id="SA1202" Action="None" />
<Rule Id="SA1203" Action="None" />
<Rule Id="SA1204" Action="None" />
<Rule Id="SA1309" Action="None" />
<Rule Id="SA1413" Action="None" />
<Rule Id="SA1600" Action="None" />
<Rule Id="SA1609" Action="None" />
<Rule Id="SA1623" Action="None" />
<Rule Id="SA1629" Action="None" />
<Rule Id="SA1642" Action="None" />
<Rule Id="SA1652" Action="None" />
</Rules>
</RuleSet>
1 change: 1 addition & 0 deletions AspNet.Security.OAuth.Providers.sln
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
NuGet.config = NuGet.config
package-icon.png = package-icon.png
README.md = README.md
stylecop.json = stylecop.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{3FA3F7B5-5373-4E43-8F45-8EC18249E526}"
Expand Down
7 changes: 7 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="$(RoslynAnalyzersVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="$(RoslynAnalyzersVersion)" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersVersion)" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" />
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersVersion)" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition=" '$(OS)' != 'Windows_NT' ">
Expand Down
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<MicrosoftNETTestSdkVersion>16.5.0</MicrosoftNETTestSdkVersion>
<RoslynAnalyzersVersion>2.9.8</RoslynAnalyzersVersion>
<ShouldlyVersion>3.0.2</ShouldlyVersion>
<StyleCopAnalyzersVersion>1.1.118</StyleCopAnalyzersVersion>
<!--
Cannot use later versions (5.5.0+) due to https://github.com/AzureAD/azure-activedirectory-identitymodel-extensions-for-dotnet/issues/1302.
-->
Expand Down
3 changes: 2 additions & 1 deletion samples/Mvc.Client/Controllers/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public async Task<IActionResult> SignIn([FromForm] string provider)
return Challenge(new AuthenticationProperties { RedirectUri = "/" }, provider);
}

[HttpGet("~/signout"), HttpPost("~/signout")]
[HttpGet("~/signout")]
[HttpPost("~/signout")]
public IActionResult SignOut()
{
// Instruct the cookies middleware to delete the local cookie created
Expand Down
8 changes: 7 additions & 1 deletion samples/Mvc.Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
using Microsoft.AspNetCore.Hosting;
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* for more information concerning the license and the contributors participating to this project.
*/

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace Mvc.Client
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
namespace AspNet.Security.OAuth.BattleNet
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* for more information concerning the license and the contributors participating to this project.
*/

namespace AspNet.Security.OAuth.BattleNet
{
/// <summary>
/// Defines a list of regions used to determine the appropriate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
[NotNull] AuthenticationProperties properties,
[NotNull] OAuthTokenResponse tokens)
{

using var request = new HttpRequestMessage(HttpMethod.Get, Options.UserInformationEndpoint);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ static string EscapeDataString(string value)

string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(
string.Concat(
EscapeDataString(Options.ClientId), ":",
EscapeDataString(Options.ClientId),
":",
EscapeDataString(Options.ClientSecret))));

return new AuthenticationHeaderValue("Basic", credentials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public GiteeAuthenticationOptions()
/// Gets or sets the address of the endpoint exposing
/// the email addresses associated with the logged in user.
/// </summary>
public string UserEmailsEndpoint { get; set; }
public string UserEmailsEndpoint { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* for more information concerning the license and the contributors participating to this project.
*/


using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OAuth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,5 @@ public static class MailRuAuthenticationDefaults
/// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>.
/// </summary>
public const string UserInformationEndpoint = "https://oauth.mail.ru/userinfo";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* for more information concerning the license and the contributors participating to this project.
*/


using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OAuth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ static string EscapeDataString(string value)

string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(
string.Concat(
EscapeDataString(Options.ClientId), ":",
EscapeDataString(Options.ClientId),
":",
EscapeDataString(Options.ClientSecret))));

return new AuthenticationHeaderValue("Basic", credentials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static AuthenticationBuilder AddShopify(
/// <param name="configuration">The delegate used to configure the Shopify options.</param>
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
public static AuthenticationBuilder AddShopify(
[NotNull] this AuthenticationBuilder builder,
[NotNull] this AuthenticationBuilder builder,
[NotNull] string scheme,
[NotNull] Action<ShopifyAuthenticationOptions> configuration)
{
Expand All @@ -68,7 +68,7 @@ public static AuthenticationBuilder AddShopify(
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
public static AuthenticationBuilder AddShopify(
[NotNull] this AuthenticationBuilder builder,
[NotNull] string scheme,
[NotNull] string scheme,
[CanBeNull] string caption,
[NotNull] Action<ShopifyAuthenticationOptions> configuration)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace AspNet.Security.OAuth.Shopify
{
public class ShopifyAuthenticationHandler : OAuthHandler<ShopifyAuthenticationOptions>
{
/// <inheritdoc />
public ShopifyAuthenticationHandler(
[NotNull] IOptionsMonitor<ShopifyAuthenticationOptions> options,
[NotNull] ILoggerFactory logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ShopifyAuthenticationOptions()
AuthorizationEndpoint = ShopifyAuthenticationDefaults.AuthorizationEndpointFormat;
TokenEndpoint = ShopifyAuthenticationDefaults.TokenEndpointFormat;
UserInformationEndpoint = ShopifyAuthenticationDefaults.UserInformationEndpointFormat;

ClaimActions.MapJsonSubKey(ClaimTypes.NameIdentifier, "shop", "myshopify_domain");
ClaimActions.MapJsonSubKey(ClaimTypes.Name, "shop", "name");
ClaimActions.MapJsonSubKey(ClaimTypes.Webpage, "shop", "domain");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class ShopifyAuthenticationProperties : AuthenticationProperties
/// to authorize. This must either be gotten from the user or sent from Shopify during App store
/// installation.
/// </param>
public ShopifyAuthenticationProperties(string shopName) : this(shopName, null)
public ShopifyAuthenticationProperties(string shopName)
: this(shopName, null)
{
}

Expand All @@ -37,7 +38,8 @@ public ShopifyAuthenticationProperties(string shopName) : this(shopName, null)
/// installation.
/// </param>
/// <param name="items">Set Items values.</param>
public ShopifyAuthenticationProperties(string shopName, IDictionary<string, string> items) : base(items)
public ShopifyAuthenticationProperties(string shopName, IDictionary<string, string> items)
: base(items)
{
SetShopName(shopName);
}
Expand All @@ -62,10 +64,9 @@ public bool RequestPerUserToken
return string.Equals(prop, ShopifyAuthenticationDefaults.PerUserAuthenticationPropertyValue, StringComparison.OrdinalIgnoreCase);
}

set => SetProperty(ShopifyAuthenticationDefaults.GrantOptionsAuthenticationProperty,
value ?
ShopifyAuthenticationDefaults.PerUserAuthenticationPropertyValue :
null);
set => SetProperty(
ShopifyAuthenticationDefaults.GrantOptionsAuthenticationProperty,
value ? ShopifyAuthenticationDefaults.PerUserAuthenticationPropertyValue : null);
}

/// <summary>
Expand All @@ -75,7 +76,7 @@ public bool RequestPerUserToken
/// </summary>
private void SetShopName(string shopName)
=> SetProperty(ShopifyAuthenticationDefaults.ShopNameAuthenticationProperty, shopName);

private void SetProperty(string propName, string value)
=> Items[propName] = value;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://SoundCloud.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* for more information concerning the license and the contributors participating to this project.
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public TraktAuthenticationOptions()

/// <summary>
/// Gets or sets the API version used when communicating with Trakt.
/// See <c>https://trakt.docs.apiary.io/#introduction/required-headers</c> for more information.
/// See <c>https://trakt.docs.apiary.io/#introduction/required-headers</c> for more information.
/// </summary>
public string ApiVersion { get; set; } = TraktAuthenticationDefaults.ApiVersion;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://Untappd.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* for more information concerning the license and the contributors participating to this project.
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://VisualStudio.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* for more information concerning the license and the contributors participating to this project.
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ protected override async Task<HandleRequestResult> HandleRemoteAuthenticateAsync
}
}
}

return await base.HandleRemoteAuthenticateAsync();
}

protected override async Task<AuthenticationTicket> CreateTicketAsync(
[NotNull] ClaimsIdentity identity,
[NotNull] AuthenticationProperties properties,
Expand Down Expand Up @@ -128,6 +130,7 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA

return OAuthTokenResponse.Failed(new Exception("An error occurred while retrieving an access token."));
}

return OAuthTokenResponse.Success(payload);
}

Expand All @@ -138,7 +141,7 @@ protected override string BuildChallengeUrl(AuthenticationProperties properties,

if (!IsWeixinAuthorizationEndpointInUse())
{
//Store state in redirectUri when authorizing Wechat Web pages to prevent "too long state parameters" error
// Store state in redirectUri when authorizing Wechat Web pages to prevent "too long state parameters" error
redirectUri = QueryHelpers.AddQueryString(redirectUri, OauthState, stateValue);
addRedirectHash = true;
}
Expand All @@ -157,6 +160,7 @@ protected override string BuildChallengeUrl(AuthenticationProperties properties,
// The parameters necessary for Web Authorization of Wechat
redirectUri += "#wechat_redirect";
}

return redirectUri;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ static string EscapeDataString(string value)

string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(
string.Concat(
EscapeDataString(Options.ClientId), ":",
EscapeDataString(Options.ClientId),
":",
EscapeDataString(Options.ClientSecret))));

return new AuthenticationHeaderValue("Basic", credentials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ static string EscapeDataString(string value)

string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(
string.Concat(
EscapeDataString(Options.ClientId), ":",
EscapeDataString(Options.ClientId),
":",
EscapeDataString(Options.ClientSecret))));

return new AuthenticationHeaderValue("Basic", credentials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public GiteeTests(ITestOutputHelper outputHelper)

protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
builder.AddGitee(options => ConfigureDefaults(builder,options));
builder.AddGitee(options => ConfigureDefaults(builder, options));
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected internal override void RegisterAuthentication(AuthenticationBuilder bu
additionalConfiguration?.Invoke(options);
});
}

protected internal override void ConfigureApplication(IApplicationBuilder app)
{
app.UseRequestLocalization(new RequestLocalizationOptions
Expand Down
4 changes: 3 additions & 1 deletion test/AspNet.Security.OAuth.Providers.Tests/OAuthTests`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ protected OAuthTests()
/// localization scenario.
/// </summary>
/// <param name="app">The application.</param>
protected internal virtual void ConfigureApplication(IApplicationBuilder app) { }
protected internal virtual void ConfigureApplication(IApplicationBuilder app)
{
}

/// <summary>
/// Configures the default authentication options.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
using System;
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* for more information concerning the license and the contributors participating to this project.
*/

using System;
using System.Globalization;
using System.Net.Http;
using System.Web;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public WechatTests(ITestOutputHelper outputHelper)
OutputHelper = outputHelper;
}

public override string DefaultScheme => WeixinAuthenticationDefaults.AuthenticationScheme;
public override string DefaultScheme => WeixinAuthenticationDefaults.AuthenticationScheme;

protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
Expand Down
8 changes: 7 additions & 1 deletion test/AspNet.Security.OAuth.Providers.Tests/Zalo/ZaloTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
using System.Security.Claims;
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* for more information concerning the license and the contributors participating to this project.
*/

using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.DependencyInjection;
Expand Down

0 comments on commit 77552be

Please sign in to comment.