Skip to content

Commit 9a0b17b

Browse files
committed
Formatting fixed
1 parent a07fe7e commit 9a0b17b

File tree

14 files changed

+139
-139
lines changed

14 files changed

+139
-139
lines changed

README.md

+26-26
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ public class Startup
3737
public void ConfigureServices(IServiceCollection services)
3838
{
3939
// Add the Basic scheme authentication here..
40-
// It requires Realm to be set in the options if SuppressWWWAuthenticateHeader is not set.
41-
// If an implementation of IBasicUserValidationService interface is registered in the dependency register as well as OnValidateCredentials delegete on options.Events is also set then this delegate will be used instead of an implementation of IBasicUserValidationService.
42-
services.AddAuthentication(BasicDefaults.AuthenticationScheme)
40+
// It requires Realm to be set in the options if SuppressWWWAuthenticateHeader is not set.
41+
// If an implementation of IBasicUserValidationService interface is registered in the dependency register as well as OnValidateCredentials delegete on options.Events is also set then this delegate will be used instead of an implementation of IBasicUserValidationService.
42+
services.AddAuthentication(BasicDefaults.AuthenticationScheme)
4343

44-
// The below AddBasic without type parameter will require OnValidateCredentials delegete on options.Events to be set unless an implementation of IBasicUserValidationService interface is registered in the dependency register.
45-
// Please note if both the delgate and validation server are set then the delegate will be used instead of BasicUserValidationService.
46-
//.AddBasic(options => { options.Realm = "My App"; });
44+
// The below AddBasic without type parameter will require OnValidateCredentials delegete on options.Events to be set unless an implementation of IBasicUserValidationService interface is registered in the dependency register.
45+
// Please note if both the delgate and validation server are set then the delegate will be used instead of BasicUserValidationService.
46+
//.AddBasic(options => { options.Realm = "My App"; });
4747
48-
// The below AddBasic with type parameter will add the BasicUserValidationService to the dependency register.
49-
// Please note if OnValidateCredentials delegete on options.Events is also set then this delegate will be used instead of BasicUserValidationService.
50-
.AddBasic<BasicUserValidationService>(options => { options.Realm = "My App"; });
48+
// The below AddBasic with type parameter will add the BasicUserValidationService to the dependency register.
49+
// Please note if OnValidateCredentials delegete on options.Events is also set then this delegate will be used instead of BasicUserValidationService.
50+
.AddBasic<BasicUserValidationService>(options => { options.Realm = "My App"; });
5151

5252
services.AddControllers();
5353

@@ -86,17 +86,17 @@ public class Startup
8686
public void ConfigureServices(IServiceCollection services)
8787
{
8888
// Add the Basic scheme authentication here..
89-
// It requires Realm to be set in the options if SuppressWWWAuthenticateHeader is not set.
90-
// If an implementation of IBasicUserValidationService interface is registered in the dependency register as well as OnValidateCredentials delegete on options.Events is also set then this delegate will be used instead of an implementation of IBasicUserValidationService.
91-
services.AddAuthentication(BasicDefaults.AuthenticationScheme)
89+
// It requires Realm to be set in the options if SuppressWWWAuthenticateHeader is not set.
90+
// If an implementation of IBasicUserValidationService interface is registered in the dependency register as well as OnValidateCredentials delegete on options.Events is also set then this delegate will be used instead of an implementation of IBasicUserValidationService.
91+
services.AddAuthentication(BasicDefaults.AuthenticationScheme)
9292

93-
// The below AddBasic without type parameter will require OnValidateCredentials delegete on options.Events to be set unless an implementation of IBasicUserValidationService interface is registered in the dependency register.
94-
// Please note if both the delgate and validation server are set then the delegate will be used instead of BasicUserValidationService.
95-
//.AddBasic(options => { options.Realm = "My App"; });
93+
// The below AddBasic without type parameter will require OnValidateCredentials delegete on options.Events to be set unless an implementation of IBasicUserValidationService interface is registered in the dependency register.
94+
// Please note if both the delgate and validation server are set then the delegate will be used instead of BasicUserValidationService.
95+
//.AddBasic(options => { options.Realm = "My App"; });
9696
97-
// The below AddBasic with type parameter will add the BasicUserValidationService to the dependency register.
98-
// Please note if OnValidateCredentials delegete on options.Events is also set then this delegate will be used instead of BasicUserValidationService.
99-
.AddBasic<BasicUserValidationService>(options => { options.Realm = "My App"; });
97+
// The below AddBasic with type parameter will add the BasicUserValidationService to the dependency register.
98+
// Please note if OnValidateCredentials delegete on options.Events is also set then this delegate will be used instead of BasicUserValidationService.
99+
.AddBasic<BasicUserValidationService>(options => { options.Realm = "My App"; });
100100

101101
services.AddMvc();
102102

@@ -168,15 +168,15 @@ The application may implement the interface fully, or it may create an instance
168168

169169
- ##### OnAuthenticationSucceeded
170170
A delegate assigned to this property will be invoked when the authentication succeeds. It will not be called if OnValidateCredentials delegate is assigned.
171-
It can be used for adding claims, headers, etc to the response.
171+
It can be used for adding claims, headers, etc to the response.
172172

173173
- ##### OnAuthenticationFailed
174174
A delegate assigned to this property will be invoked when the authentication fails.
175175

176176
- ##### OnHandleChallenge
177177
A delegate assigned to this property will be invoked before a challenge is sent back to the caller when handling unauthorized response.
178178
Only use this if you know what you are doing and if you want to use custom implementation. Set the delegate to deal with 401 challenge concerns, if an authentication scheme in question deals an authentication interaction as part of it's request flow. (like adding a response header, or changing the 401 result to 302 of a login page or external sign-in location.)
179-
Call context.Handled() at the end so that any default logic for this challenge will be skipped.
179+
Call context.Handled() at the end so that any default logic for this challenge will be skipped.
180180

181181
- ##### OnHandleForbidden
182182
A delegate assigned to this property will be invoked if Authorization fails and results in a Forbidden response.
@@ -193,14 +193,14 @@ However, if you want all the requests to challenge authentication by default, de
193193
```C#
194194
services.AddAuthorization(options =>
195195
{
196-
options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
196+
options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build();
197197
});
198198

199199
// OR
200200
201201
services.AddMvc(options =>
202202
{
203-
options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()));
203+
options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()));
204204
});
205205
```
206206

@@ -209,10 +209,10 @@ If you are not using MVC but, using Endpoints on ASP.NET Core 3.0 or newer, you
209209
```C#
210210
app.UseEndpoints(endpoints =>
211211
{
212-
endpoints.MapGet("/", async context =>
213-
{
214-
await context.Response.WriteAsync("Hello World!");
215-
}).RequireAuthorization(); // NOTE THIS HERE!!!!
212+
endpoints.MapGet("/", async context =>
213+
{
214+
await context.Response.WriteAsync("Hello World!");
215+
}).RequireAuthorization(); // NOTE THIS HERE!!!!
216216
});
217217
```
218218

samples/SampleWebApi_2_0/Controllers/ValuesController.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SampleWebApi_2_2.Controllers
66
{
7-
[Route("api/[controller]")]
7+
[Route("api/[controller]")]
88
public class ValuesController : ControllerBase
99
{
1010
// GET api/values
@@ -16,14 +16,14 @@ public IEnumerable<string> Get()
1616

1717
[HttpGet("claims")]
1818
public string Claims()
19-
{
19+
{
2020
var sb = new StringBuilder();
21-
foreach (var claim in User.Claims)
22-
{
21+
foreach (var claim in User.Claims)
22+
{
2323
sb.AppendLine($"{claim.Type}: {claim.Value}");
24-
}
24+
}
2525
return sb.ToString();
26-
}
26+
}
2727

2828
[HttpGet("forbid")]
2929
public new IActionResult Forbid()

samples/SampleWebApi_2_0/Startup.cs

+39-39
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
namespace SampleWebApi
1717
{
1818
public class Startup
19-
{
20-
public Startup(IConfiguration configuration)
21-
{
22-
Configuration = configuration;
23-
}
19+
{
20+
public Startup(IConfiguration configuration)
21+
{
22+
Configuration = configuration;
23+
}
2424

25-
public IConfiguration Configuration { get; }
25+
public IConfiguration Configuration { get; }
2626

27-
// This method gets called by the runtime. Use this method to add services to the container.
28-
public void ConfigureServices(IServiceCollection services)
29-
{
30-
// Add User repository to the dependency container.
31-
services.AddTransient<IUserRepository, InMemoryUserRepository>();
27+
// This method gets called by the runtime. Use this method to add services to the container.
28+
public void ConfigureServices(IServiceCollection services)
29+
{
30+
// Add User repository to the dependency container.
31+
services.AddTransient<IUserRepository, InMemoryUserRepository>();
3232

3333
// Add the Basic scheme authentication here..
3434
// It requires Realm to be set in the options if SuppressWWWAuthenticateHeader is not set.
@@ -148,32 +148,32 @@ public void ConfigureServices(IServiceCollection services)
148148
});
149149

150150
services.AddMvc(options =>
151-
{
152-
// ALWAYS USE HTTPS (SSL) protocol in production when using Basic authentication.
153-
//options.Filters.Add<RequireHttpsAttribute>();
154-
155-
// All the requests will need to be authorized.
156-
// Alternatively, add [Authorize] attribute to Controller or Action Method where necessary.
157-
options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()));
158-
}
159-
); //.AddXmlSerializerFormatters(); // To enable XML along with JSON
160-
}
161-
162-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
163-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
164-
{
165-
if (env.IsDevelopment())
166-
{
167-
app.UseDeveloperExceptionPage();
168-
}
169-
else
170-
{
171-
// ALWAYS USE HTTPS (SSL) protocol in production when using Basic authentication.
172-
app.UseRewriter(new RewriteOptions().AddRedirectToHttpsPermanent());
173-
}
174-
175-
app.UseAuthentication();
176-
app.UseMvc();
177-
}
178-
}
151+
{
152+
// ALWAYS USE HTTPS (SSL) protocol in production when using Basic authentication.
153+
//options.Filters.Add<RequireHttpsAttribute>();
154+
155+
// All the requests will need to be authorized.
156+
// Alternatively, add [Authorize] attribute to Controller or Action Method where necessary.
157+
options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()));
158+
}
159+
); //.AddXmlSerializerFormatters(); // To enable XML along with JSON
160+
}
161+
162+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
163+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
164+
{
165+
if (env.IsDevelopment())
166+
{
167+
app.UseDeveloperExceptionPage();
168+
}
169+
else
170+
{
171+
// ALWAYS USE HTTPS (SSL) protocol in production when using Basic authentication.
172+
app.UseRewriter(new RewriteOptions().AddRedirectToHttpsPermanent());
173+
}
174+
175+
app.UseAuthentication();
176+
app.UseMvc();
177+
}
178+
}
179179
}

samples/SampleWebApi_2_2/Controllers/ValuesController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SampleWebApi_2_2.Controllers
66
{
7-
[Route("api/[controller]")]
7+
[Route("api/[controller]")]
88
[ApiController]
99
public class ValuesController : ControllerBase
1010
{

samples/SampleWebApi_2_2/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "http://json.schemastore.org/launchsettings.json",
33
"iisSettings": {
4-
"windowsAuthentication": false,
4+
"windowsAuthentication": false,
55
"anonymousAuthentication": true,
66
"iisExpress": {
77
"applicationUrl": "http://localhost:3920",

samples/SampleWebApi_2_2/Startup.cs

+41-41
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
namespace SampleWebApi_2_2
1717
{
1818
public class Startup
19-
{
20-
public Startup(IConfiguration configuration)
21-
{
22-
Configuration = configuration;
23-
}
19+
{
20+
public Startup(IConfiguration configuration)
21+
{
22+
Configuration = configuration;
23+
}
2424

25-
public IConfiguration Configuration { get; }
25+
public IConfiguration Configuration { get; }
2626

27-
// This method gets called by the runtime. Use this method to add services to the container.
28-
public void ConfigureServices(IServiceCollection services)
29-
{
30-
// Add User repository to the dependency container.
31-
services.AddTransient<IUserRepository, InMemoryUserRepository>();
27+
// This method gets called by the runtime. Use this method to add services to the container.
28+
public void ConfigureServices(IServiceCollection services)
29+
{
30+
// Add User repository to the dependency container.
31+
services.AddTransient<IUserRepository, InMemoryUserRepository>();
3232

3333
// Add the Basic scheme authentication here..
3434
// It requires Realm to be set in the options if SuppressWWWAuthenticateHeader is not set.
@@ -148,34 +148,34 @@ public void ConfigureServices(IServiceCollection services)
148148
});
149149

150150
services.AddMvc(options =>
151-
{
152-
// ALWAYS USE HTTPS (SSL) protocol in production when using Basic authentication.
153-
//options.Filters.Add<RequireHttpsAttribute>();
154-
155-
// All the requests will need to be authorized.
156-
// Alternatively, add [Authorize] attribute to Controller or Action Method where necessary.
157-
options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()));
158-
})
159-
//.AddXmlSerializerFormatters() // To enable XML along with JSON
160-
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
161-
}
162-
163-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
164-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
165-
{
166-
if (env.IsDevelopment())
167-
{
168-
app.UseDeveloperExceptionPage();
169-
}
170-
else
171-
{
172-
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
173-
app.UseHsts();
174-
}
175-
176-
app.UseHttpsRedirection();
177-
app.UseAuthentication();
178-
app.UseMvc();
179-
}
180-
}
151+
{
152+
// ALWAYS USE HTTPS (SSL) protocol in production when using Basic authentication.
153+
//options.Filters.Add<RequireHttpsAttribute>();
154+
155+
// All the requests will need to be authorized.
156+
// Alternatively, add [Authorize] attribute to Controller or Action Method where necessary.
157+
options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()));
158+
})
159+
//.AddXmlSerializerFormatters() // To enable XML along with JSON
160+
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
161+
}
162+
163+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
164+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
165+
{
166+
if (env.IsDevelopment())
167+
{
168+
app.UseDeveloperExceptionPage();
169+
}
170+
else
171+
{
172+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
173+
app.UseHsts();
174+
}
175+
176+
app.UseHttpsRedirection();
177+
app.UseAuthentication();
178+
app.UseMvc();
179+
}
180+
}
181181
}

samples/SampleWebApi_3_1/Controllers/ValuesController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SampleWebApi_2_2.Controllers
66
{
7-
[Route("api/[controller]")]
7+
[Route("api/[controller]")]
88
[ApiController]
99
public class ValuesController : ControllerBase
1010
{

samples/SampleWebApi_5_0/Controllers/ValuesController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace SampleWebApi_5_0.Controllers
66
{
7-
[Route("api/[controller]")]
7+
[Route("api/[controller]")]
88
[ApiController]
99
public class ValuesController : ControllerBase
1010
{

src/AspNetCore.Authentication.Basic/BasicExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99

1010
namespace AspNetCore.Authentication.Basic
1111
{
12-
/// <summary>
13-
/// Extension methods for basic authentication.
14-
/// </summary>
15-
public static class BasicExtensions
12+
/// <summary>
13+
/// Extension methods for basic authentication.
14+
/// </summary>
15+
public static class BasicExtensions
1616
{
1717
/// <summary>
1818
/// Adds basic authentication scheme to the project.

src/AspNetCore.Authentication.Basic/BasicHandler.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
namespace AspNetCore.Authentication.Basic
1717
{
18-
/// <summary>
19-
/// Inherited from <see cref="AuthenticationHandler{TOptions}"/> for basic authentication.
20-
/// </summary>
21-
internal class BasicHandler : AuthenticationHandler<BasicOptions>
18+
/// <summary>
19+
/// Inherited from <see cref="AuthenticationHandler{TOptions}"/> for basic authentication.
20+
/// </summary>
21+
internal class BasicHandler : AuthenticationHandler<BasicOptions>
2222
{
2323
/// <summary>
2424
/// Basic Handler Constructor.

0 commit comments

Comments
 (0)