Skip to content

Commit 1369775

Browse files
committed
Adhere to the ASP.NET team coding style guidelines
1 parent b8c6168 commit 1369775

File tree

233 files changed

+2036
-1078
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+2036
-1078
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ AspNet.Security.OAuth.Providers
1212

1313
**Adding social authentication to your application is a breeze** and just requires a few lines in your `Startup` class:
1414

15-
app.UseGitHubAuthentication(options => {
16-
options.ClientId = "49e302895d8b09ea5656";
17-
options.ClientSecret = "98f1bf028608901e9df91d64ee61536fe562064b";
18-
});
15+
```csharp
16+
app.UseGitHubAuthentication(options =>
17+
{
18+
options.ClientId = "49e302895d8b09ea5656";
19+
options.ClientSecret = "98f1bf028608901e9df91d64ee61536fe562064b";
20+
});
21+
```
1922

2023
See [https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/tree/dev/samples/Mvc.Client](https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/tree/dev/samples/Mvc.Client) for a complete sample **using ASP.NET Core MVC and supporting multiple social providers**.
2124

samples/Mvc.Client/Controllers/AuthenticationController.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,25 @@
99
using Microsoft.AspNetCore.Mvc;
1010
using Mvc.Client.Extensions;
1111

12-
namespace Mvc.Client.Controllers {
13-
public class AuthenticationController : Controller {
12+
namespace Mvc.Client.Controllers
13+
{
14+
public class AuthenticationController : Controller
15+
{
1416
[HttpGet("~/signin")]
1517
public IActionResult SignIn() => View("SignIn", HttpContext.GetExternalProviders());
1618

1719
[HttpPost("~/signin")]
18-
public IActionResult SignIn([FromForm] string provider) {
20+
public IActionResult SignIn([FromForm] string provider)
21+
{
1922
// Note: the "provider" parameter corresponds to the external
2023
// authentication provider choosen by the user agent.
21-
if (string.IsNullOrWhiteSpace(provider)) {
24+
if (string.IsNullOrWhiteSpace(provider))
25+
{
2226
return BadRequest();
2327
}
2428

25-
if (!HttpContext.IsProviderSupported(provider)) {
29+
if (!HttpContext.IsProviderSupported(provider))
30+
{
2631
return BadRequest();
2732
}
2833

@@ -33,7 +38,8 @@ public IActionResult SignIn([FromForm] string provider) {
3338
}
3439

3540
[HttpGet("~/signout"), HttpPost("~/signout")]
36-
public IActionResult SignOut() {
41+
public IActionResult SignOut()
42+
{
3743
// Instruct the cookies middleware to delete the local cookie created
3844
// when the user agent is redirected from the external identity provider
3945
// after a successful authentication flow (e.g Google or Facebook).

samples/Mvc.Client/Controllers/HomeController.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
using Microsoft.AspNetCore.Mvc;
88

9-
namespace Mvc.Client.Controllers {
10-
public class HomeController : Controller {
9+
namespace Mvc.Client.Controllers
10+
{
11+
public class HomeController : Controller
12+
{
1113
[HttpGet("~/")]
1214
public ActionResult Index() => View();
1315
}

samples/Mvc.Client/Extensions/HttpContextExtensions.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
using Microsoft.AspNetCore.Http;
1111
using Microsoft.AspNetCore.Http.Authentication;
1212

13-
namespace Mvc.Client.Extensions {
14-
public static class HttpContextExtensions {
15-
public static IEnumerable<AuthenticationDescription> GetExternalProviders(this HttpContext context) {
16-
if (context == null) {
13+
namespace Mvc.Client.Extensions
14+
{
15+
public static class HttpContextExtensions
16+
{
17+
public static IEnumerable<AuthenticationDescription> GetExternalProviders(this HttpContext context)
18+
{
19+
if (context == null)
20+
{
1721
throw new ArgumentNullException(nameof(context));
1822
}
1923

@@ -22,8 +26,10 @@ public static IEnumerable<AuthenticationDescription> GetExternalProviders(this H
2226
select description;
2327
}
2428

25-
public static bool IsProviderSupported(this HttpContext context, string provider) {
26-
if (context == null) {
29+
public static bool IsProviderSupported(this HttpContext context, string provider)
30+
{
31+
if (context == null)
32+
{
2733
throw new ArgumentNullException(nameof(context));
2834
}
2935

samples/Mvc.Client/Program.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
using Microsoft.Extensions.Configuration;
33
using Microsoft.Extensions.Logging;
44

5-
namespace Mvc.Client {
6-
public static class Program {
7-
public static void Main(string[] args) {
5+
namespace Mvc.Client
6+
{
7+
public static class Program
8+
{
9+
public static void Main(string[] args)
10+
{
811
var configuration = new ConfigurationBuilder()
912
.AddEnvironmentVariables()
1013
.AddCommandLine(args)

samples/Mvc.Client/Startup.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,46 @@
1010
using Microsoft.AspNetCore.Http;
1111
using Microsoft.Extensions.DependencyInjection;
1212

13-
namespace Mvc.Client {
14-
public class Startup {
15-
public void ConfigureServices(IServiceCollection services) {
16-
services.AddAuthentication(options => {
13+
namespace Mvc.Client
14+
{
15+
public class Startup
16+
{
17+
public void ConfigureServices(IServiceCollection services)
18+
{
19+
services.AddAuthentication(options =>
20+
{
1721
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
1822
});
1923

2024
services.AddMvc();
2125
}
2226

23-
public void Configure(IApplicationBuilder app) {
27+
public void Configure(IApplicationBuilder app)
28+
{
2429
app.UseStaticFiles();
2530

26-
app.UseCookieAuthentication(new CookieAuthenticationOptions {
31+
app.UseCookieAuthentication(new CookieAuthenticationOptions
32+
{
2733
AutomaticAuthenticate = true,
2834
AutomaticChallenge = true,
2935
LoginPath = new PathString("/signin"),
3036
LogoutPath = new PathString("/signout")
3137
});
3238

33-
app.UseGoogleAuthentication(new GoogleOptions {
39+
app.UseGoogleAuthentication(new GoogleOptions
40+
{
3441
ClientId = "560027070069-37ldt4kfuohhu3m495hk2j4pjp92d382.apps.googleusercontent.com",
3542
ClientSecret = "n2Q-GEw9RQjzcRbU3qhfTj8f"
3643
});
3744

38-
app.UseTwitterAuthentication(new TwitterOptions {
45+
app.UseTwitterAuthentication(new TwitterOptions
46+
{
3947
ConsumerKey = "6XaCTaLbMqfj6ww3zvZ5g",
4048
ConsumerSecret = "Il2eFzGIrYhz6BWjYhVXBPQSfZuS4xoHpSSyD9PI"
4149
});
4250

43-
app.UseGitHubAuthentication(new GitHubAuthenticationOptions {
51+
app.UseGitHubAuthentication(new GitHubAuthenticationOptions
52+
{
4453
ClientId = "49e302895d8b09ea5656",
4554
ClientSecret = "98f1bf028608901e9df91d64ee61536fe562064b",
4655
Scope = { "user:email" }

samples/Mvc.Client/web.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<configuration>
33
<system.webServer>
44
<handlers>
5-
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
5+
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
66
</handlers>
7-
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
7+
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
88
</system.webServer>
99
</configuration>

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

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

77
using Microsoft.AspNetCore.Builder;
8-
using Microsoft.AspNetCore.Authentication.OAuth;
98

10-
namespace AspNet.Security.OAuth.ArcGIS {
9+
namespace AspNet.Security.OAuth.ArcGIS
10+
{
1111
/// <summary>
1212
/// Default values used by the ArcGIS authentication middleware.
1313
/// </summary>
14-
public static class ArcGISAuthenticationDefaults {
14+
public static class ArcGISAuthenticationDefaults
15+
{
1516
/// <summary>
1617
/// Default value for <see cref="AuthenticationOptions.AuthenticationScheme"/>.
1718
/// </summary>

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,31 @@
99
using JetBrains.Annotations;
1010
using Microsoft.Extensions.Options;
1111

12-
namespace Microsoft.AspNetCore.Builder {
12+
namespace Microsoft.AspNetCore.Builder
13+
{
1314
/// <summary>
1415
/// Extension methods to add ArcGIS authentication capabilities to an HTTP application pipeline.
1516
/// </summary>
16-
public static class ArcGISAuthenticationExtensions {
17+
public static class ArcGISAuthenticationExtensions
18+
{
1719
/// <summary>
1820
/// Adds the <see cref="ArcGISAuthenticationMiddleware"/> middleware to the specified
1921
/// <see cref="IApplicationBuilder"/>, which enables ArcGIS authentication capabilities.
2022
/// </summary>
2123
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
22-
/// <param name="options">A <see cref="ArcGISAuthenticationOptions"/> that specifies options for the middleware.</param>
24+
/// <param name="options">A <see cref="ArcGISAuthenticationOptions"/> that specifies options for the middleware.</param>
2325
/// <returns>A reference to this instance after the operation has completed.</returns>
2426
public static IApplicationBuilder UseArcGISAuthentication(
2527
[NotNull] this IApplicationBuilder app,
26-
[NotNull] ArcGISAuthenticationOptions options) {
27-
if (app == null) {
28+
[NotNull] ArcGISAuthenticationOptions options)
29+
{
30+
if (app == null)
31+
{
2832
throw new ArgumentNullException(nameof(app));
2933
}
3034

31-
if (options == null) {
35+
if (options == null)
36+
{
3237
throw new ArgumentNullException(nameof(options));
3338
}
3439

@@ -44,12 +49,15 @@ public static IApplicationBuilder UseArcGISAuthentication(
4449
/// <returns>A reference to this instance after the operation has completed.</returns>
4550
public static IApplicationBuilder UseArcGISAuthentication(
4651
[NotNull] this IApplicationBuilder app,
47-
[NotNull] Action<ArcGISAuthenticationOptions> configuration) {
48-
if (app == null) {
52+
[NotNull] Action<ArcGISAuthenticationOptions> configuration)
53+
{
54+
if (app == null)
55+
{
4956
throw new ArgumentNullException(nameof(app));
5057
}
5158

52-
if (configuration == null) {
59+
if (configuration == null)
60+
{
5361
throw new ArgumentNullException(nameof(configuration));
5462
}
5563

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,36 @@
1919
using Microsoft.Extensions.Logging;
2020
using Newtonsoft.Json.Linq;
2121

22-
namespace AspNet.Security.OAuth.ArcGIS {
23-
public class ArcGISAuthenticationHandler : OAuthHandler<ArcGISAuthenticationOptions> {
22+
namespace AspNet.Security.OAuth.ArcGIS
23+
{
24+
public class ArcGISAuthenticationHandler : OAuthHandler<ArcGISAuthenticationOptions>
25+
{
2426
public ArcGISAuthenticationHandler([NotNull] HttpClient client)
25-
: base(client) {
27+
: base(client)
28+
{
2629
}
2730

2831
protected override async Task<AuthenticationTicket> CreateTicketAsync([NotNull] ClaimsIdentity identity,
29-
[NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens) {
32+
[NotNull] AuthenticationProperties properties, [NotNull] OAuthTokenResponse tokens)
33+
{
3034
// Note: the ArcGIS API doesn't support content negotiation via headers.
31-
var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string> {
35+
var address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, new Dictionary<string, string>
36+
{
3237
["f"] = "json",
3338
["token"] = tokens.AccessToken
3439
});
3540

3641
var request = new HttpRequestMessage(HttpMethod.Get, address);
3742
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
38-
39-
// Request the token
43+
44+
// Request the token
4045
var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
4146
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
4247

4348
// Note: error responses always return 200 status codes.
4449
var error = ArcGISAuthenticationHelper.GetError(payload);
45-
if (error != null) {
50+
if (error != null)
51+
{
4652
// See https://developers.arcgis.com/authentication/server-based-user-logins/ for more information
4753
Logger.LogError("An error occurred while retrieving the user profile: the remote server " +
4854
"returned a response with the following error code: {Code} {Message}.",

0 commit comments

Comments
 (0)