Skip to content

Commit

Permalink
Imported analyzer rules from MSAL. Added StyleCop analyzers and relat…
Browse files Browse the repository at this point in the history
…ed config. Cleaned up GlobalSuppression files. (#150)

Warning fixes for the following rules: CA1305, CA2007, SA1001, SA1003, SA1004, SA1005, SA1028, SA1208, SA1413, SA1503, SA1600, SA1629.
  • Loading branch information
pmaytak authored May 10, 2020
1 parent c04f27c commit 3151e1c
Show file tree
Hide file tree
Showing 94 changed files with 1,466 additions and 803 deletions.
480 changes: 477 additions & 3 deletions .editorconfig

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Microsoft.Identity.Web.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2B919DEC-2539-4357-8E89-8C0CC9889FB4}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
stylecop.json = stylecop.json
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetCoreMicrosoftIdentityWebProjectTemplates", "ProjectTemplates\AspNetCoreMicrosoftIdentityWebProjectTemplates.csproj", "{893905EA-94D6-4F71-957A-43B194751DC7}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Threading.Tasks;

namespace Microsoft.Identity.Web.UI.Areas.MicrosoftIdentity.Controllers
{
/// <summary>
/// Controller used in web apps to manage accounts
/// Controller used in web apps to manage accounts.
/// </summary>
[NonController]
[AllowAnonymous]
Expand All @@ -24,19 +24,19 @@ public class AccountController : Controller

/// <summary>
/// Constructor of <see cref="AccountController"/> from <see cref="MicrosoftIdentityOptions"/>
/// This constructor is used by dependency injection
/// This constructor is used by dependency injection.
/// </summary>
/// <param name="microsoftIdentityOptions">Configuration options</param>
/// <param name="microsoftIdentityOptions">Configuration options.</param>
public AccountController(IOptionsMonitor<MicrosoftIdentityOptions> microsoftIdentityOptions)
{
_options = microsoftIdentityOptions;
}

/// <summary>
/// Handles user sign in
/// Handles user sign in.
/// </summary>
/// <param name="scheme">Authentication scheme</param>
/// <returns>Challenge generating a redirect to Azure AD to sign in the user</returns>
/// <param name="scheme">Authentication scheme.</param>
/// <returns>Challenge generating a redirect to Azure AD to sign in the user.</returns>
[HttpGet("{scheme?}")]
public IActionResult SignIn([FromRoute] string scheme)
{
Expand All @@ -48,10 +48,10 @@ public IActionResult SignIn([FromRoute] string scheme)
}

/// <summary>
/// Handles the user sign-out
/// Handles the user sign-out.
/// </summary>
/// <param name="scheme">Authentication scheme</param>
/// <returns>Sign out result</returns>
/// <param name="scheme">Authentication scheme.</param>
/// <returns>Sign out result.</returns>
[HttpGet("{scheme?}")]
public IActionResult SignOut([FromRoute] string scheme)
{
Expand All @@ -60,17 +60,17 @@ public IActionResult SignOut([FromRoute] string scheme)
return SignOut(
new AuthenticationProperties
{
RedirectUri = callbackUrl
RedirectUri = callbackUrl,
},
CookieAuthenticationDefaults.AuthenticationScheme,
scheme);
}

/// <summary>
/// In B2C applications handles the Reset password policy
/// In B2C applications handles the Reset password policy.
/// </summary>
/// <param name="scheme">Authentication scheme</param>
/// <returns>Challenge generating a redirect to Azure AD B2C</returns>
/// <param name="scheme">Authentication scheme.</param>
/// <returns>Challenge generating a redirect to Azure AD B2C.</returns>
[HttpGet("{scheme?}")]
public IActionResult ResetPassword([FromRoute] string scheme)
{
Expand All @@ -83,10 +83,10 @@ public IActionResult ResetPassword([FromRoute] string scheme)
}

/// <summary>
/// In B2C applications, handles the Edit Profile policy
/// In B2C applications, handles the Edit Profile policy.
/// </summary>
/// <param name="scheme">Authentication scheme</param>
/// <returns>Challenge generating a redirect to Azure AD B2C</returns>
/// <param name="scheme">Authentication scheme.</param>
/// <returns>Challenge generating a redirect to Azure AD B2C.</returns>
[HttpGet("{scheme?}")]
public async Task<IActionResult> EditProfile([FromRoute] string scheme)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Microsoft.Identity.Web.UI.Areas.MicrosoftIdentity.Pages.Account
{
/// <summary>
/// Page presenting the Access denied error
/// Page presenting the Access denied error.
/// </summary>
[AllowAnonymous]
public class AccessDeniedModel : PageModel
{
/// <summary>
/// Method handling the Get Http verb
/// Method handling the HTTP GET method.
/// </summary>
public void OnGet()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Diagnostics;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;

namespace Microsoft.Identity.Web.UI.Areas.MicrosoftIdentity.Pages.Account
{
/// <summary>
/// Model for the Error page
/// Model for the Error page.
/// </summary>
[AllowAnonymous]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public class ErrorModel : PageModel
{
/// <summary>
/// This API supports infrastructure and is not intended to be used
/// directly from your code.This API may change or be removed in future releases
/// directly from your code.This API may change or be removed in future releases.
/// </summary>
public string RequestId { get; set; }

/// <summary>
/// This API supports infrastructure and is not intended to be used
/// directly from your code.This API may change or be removed in future releases
/// directly from your code.This API may change or be removed in future releases.
/// </summary>
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

/// <summary>
/// This API supports infrastructure and is not intended to be used
/// directly from your code.This API may change or be removed in future releases
/// directly from your code.This API may change or be removed in future releases.
/// </summary>
public void OnGet()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Microsoft.Identity.Web.UI.Areas.MicrosoftIdentity.Pages.Account
{
/// <summary>
/// Model for the SignOut page
/// Model for the SignOut page.
/// </summary>
[AllowAnonymous]
public class SignedOutModel : PageModel
{
#pragma warning disable CS1591 // Imposed by the Blazor framework
/// <summary>
/// Method handling the HTTP GET method.
/// </summary>
/// <returns></returns>
public IActionResult OnGet()
#pragma warning restore CS1591 // // Imposed by the Blazor framework
{
if (User.Identity.IsAuthenticated)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="..\..\stylecop.json" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
Expand Down Expand Up @@ -57,6 +61,10 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Collections.Generic;
using System.Reflection;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.Identity.Web.UI.Areas.MicrosoftIdentity.Controllers;
using System.Collections.Generic;
using System.Reflection;

namespace Microsoft.Identity.Web.UI
{
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Identity.Web.UI/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace Microsoft.Identity.Web.UI
{
/// <summary>
/// Extension method on <see cref="IMvcBuilder"/> to add UI
/// for Microsoft.Identity.Web
/// for Microsoft.Identity.Web.
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds a controller and Razor pages for the accounts management.
/// </summary>
/// <param name="builder">MVC Builder</param>
/// <param name="builder">MVC Builder.</param>
public static IMvcBuilder AddMicrosoftIdentityUI(this IMvcBuilder builder)
{
builder.ConfigureApplicationPartManager(apm =>
Expand Down
15 changes: 7 additions & 8 deletions src/Microsoft.Identity.Web/AccountExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Identity.Client;
using System.Security.Claims;
using Microsoft.Identity.Client;

namespace Microsoft.Identity.Web
{
Expand All @@ -12,11 +12,11 @@ namespace Microsoft.Identity.Web
public static class AccountExtensions
{
/// <summary>
/// Creates the <see cref="ClaimsPrincipal"/> from the values found
/// in an <see cref="IAccount"/>
/// Creates the <see cref="ClaimsPrincipal"/> from the values found
/// in an <see cref="IAccount"/>.
/// </summary>
/// <param name="account">The IAccount instance</param>
/// <returns>A <see cref="ClaimsPrincipal"/> built from IAccount</returns>
/// <param name="account">The IAccount instance.</param>
/// <returns>A <see cref="ClaimsPrincipal"/> built from IAccount.</returns>
public static ClaimsPrincipal ToClaimsPrincipal(this IAccount account)
{
if (account != null)
Expand All @@ -26,9 +26,8 @@ public static ClaimsPrincipal ToClaimsPrincipal(this IAccount account)
{
new Claim(ClaimConstants.Oid, account.HomeAccountId?.ObjectId),
new Claim(ClaimConstants.Tid, account.HomeAccountId?.TenantId),
new Claim(ClaimTypes.Upn, account.Username)
})
);
new Claim(ClaimTypes.Upn, account.Username),
}));
}

return null;
Expand Down
7 changes: 5 additions & 2 deletions src/Microsoft.Identity.Web/AuthorityHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.AspNetCore.Http;
using System;
using Microsoft.AspNetCore.Http;

namespace Microsoft.Identity.Web
{
Expand All @@ -15,7 +15,7 @@ internal static string BuildAuthority(MicrosoftIdentityOptions options)
var domain = options.Domain;
var tenantId = options.TenantId;

// If there are user flows, then it must build a B2C authority
// If there are user flows, then it must build a B2C authority
if (options.IsB2C)
{
var userFlow = options.DefaultUserFlow;
Expand All @@ -31,7 +31,10 @@ internal static string EnsureAuthorityIsV2(string authority)
{
authority = authority.Trim().TrimEnd('/');
if (!authority.EndsWith("v2.0", StringComparison.InvariantCulture))
{
authority += "/v2.0";
}

return authority;
}
}
Expand Down
Loading

0 comments on commit 3151e1c

Please sign in to comment.