Skip to content

Commit

Permalink
Run Code Clean Up
Browse files Browse the repository at this point in the history
  • Loading branch information
daohainam committed Nov 14, 2023
1 parent 7650daf commit 92d8bc3
Show file tree
Hide file tree
Showing 243 changed files with 623 additions and 1,944 deletions.
2 changes: 0 additions & 2 deletions Middleware/Authentication/AuthenticationMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using MiniWebServer.MiniApp;
using MiniWebServer.MiniApp.Authentication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
using Microsoft.Extensions.Logging;
using MiniWebServer.MiniApp.Authentication;
using MiniWebServer.MiniApp.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Authentication
{
Expand Down
9 changes: 1 addition & 8 deletions Middleware/Authentication/AuthenticationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using MiniWebServer.MiniApp.Authentication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Authentication
namespace MiniWebServer.Authentication
{
public class AuthenticationOptions
{
Expand Down
13 changes: 4 additions & 9 deletions Middleware/Authentication/CookieAuthenticationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Authentication
namespace MiniWebServer.Authentication
{
public class CookieAuthenticationOptions
{
public const string DefaultCookieName = ".miniWeb.UID";

public CookieAuthenticationOptions(string? cookieName = null) {
public CookieAuthenticationOptions(string? cookieName = null)
{
CookieName = cookieName ?? DefaultCookieName;
if (CookieName.Length == 0)
{
throw new ArgumentException(nameof(cookieName) + " cannot be empty");
}

}
public string CookieName { get; }
public string CookieName { get; }
}
}
8 changes: 1 addition & 7 deletions Middleware/Authentication/CookieAuthenticationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
using MiniWebServer.Abstractions.Http;
using MiniWebServer.MiniApp;
using MiniWebServer.MiniApp.Authentication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Authentication
{
Expand Down Expand Up @@ -105,7 +99,7 @@ public Task SignInAsync(IMiniAppContext context, System.Security.Claims.ClaimsPr

public Task SignOutAsync(IMiniAppContext context)
{
var principal = context.User;
var principal = context.User;
if (principal == null)
return Task.CompletedTask;

Expand Down
8 changes: 1 addition & 7 deletions Middleware/Authentication/CookieDefaults.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Authentication
namespace MiniWebServer.Authentication
{
public sealed class CookieDefaults
{
Expand Down
7 changes: 1 addition & 6 deletions Middleware/Authentication/DefaultPrincipalKeyGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Security.Principal;

namespace MiniWebServer.Authentication
{
Expand Down
7 changes: 1 addition & 6 deletions Middleware/Authentication/IPrincipalKeyGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Security.Principal;

namespace MiniWebServer.Authentication
{
Expand Down
7 changes: 1 addition & 6 deletions Middleware/Authentication/IPrincipalStore.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using System.Security.Claims;

namespace MiniWebServer.Authentication
{
Expand Down
5 changes: 0 additions & 5 deletions Middleware/Authentication/JwtAuthenticationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Authentication
{
Expand Down
20 changes: 7 additions & 13 deletions Middleware/Authentication/JwtAuthenticationService.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Tokens;
using MiniWebServer.MiniApp;
using MiniWebServer.MiniApp.Authentication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
using System.Net.Http.Headers;
using Microsoft.IdentityModel.Tokens;
using System.Security.Claims;
using System.Security.Principal;
using Microsoft.IdentityModel.Logging;

namespace MiniWebServer.Authentication
{
Expand Down Expand Up @@ -77,7 +70,8 @@ public async Task<AuthenticationResult> AuthenticateAsync(IMiniAppContext contex
}
}
}
} catch (Exception ex)
}
catch (Exception ex)
{
logger.LogError(ex, "Error authenticating");
}
Expand All @@ -102,7 +96,7 @@ private async Task<TokenValidationResult> ValidateAsync(string token, JwtSecurit
if (tokenValidationParameters == null)
return new TokenValidationResult() { IsValid = false };


var result = await handler.ValidateTokenAsync(token, tokenValidationParameters);

if (!result.IsValid)
Expand Down
8 changes: 1 addition & 7 deletions Middleware/Authentication/JwtBearerDefaults.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Authentication
namespace MiniWebServer.Authentication
{
public sealed class JwtBearerDefaults
{
Expand Down
12 changes: 4 additions & 8 deletions Middleware/Authentication/MemoryPrincipalStore.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Concurrent;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Authentication
{
Expand All @@ -14,8 +9,9 @@ public class MemoryPrincipalStore : IPrincipalStore

public ClaimsPrincipal? GetPrincipal(string key)
{
if (principals.TryGetValue(key, out ClaimsPrincipal? principal)) {
return principal;
if (principals.TryGetValue(key, out ClaimsPrincipal? principal))
{
return principal;
}

return null;
Expand Down
5 changes: 0 additions & 5 deletions Middleware/Authorization/AuthorizationOptions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using MiniWebServer.MiniApp;
using MiniWebServer.MiniApp.Authorization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Authorization
{
Expand Down
8 changes: 1 addition & 7 deletions Middleware/Authorization/IRouteMatcher.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Authorization
namespace MiniWebServer.Authorization
{
public interface IRouteMatcher
{
Expand Down
8 changes: 1 addition & 7 deletions Middleware/Authorization/RegExRouteMatcher.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Authorization
namespace MiniWebServer.Authorization
{
public class RegExRouteMatcher : IRouteMatcher
{
Expand Down
13 changes: 3 additions & 10 deletions Middleware/Authorization/RouteDictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Authorization
namespace MiniWebServer.Authorization
{
public static class RouteDictionaryExtensions
{
Expand All @@ -16,14 +9,14 @@ public static void Add(this IDictionary<string, string[]> dictionary, string key
value
};

if (values != null )
if (values != null)
{
foreach (string v in values)
{
strings.Add(v);
}
}
dictionary[key] = strings.ToArray();
dictionary[key] = strings.ToArray();
}
}
}
5 changes: 1 addition & 4 deletions Middleware/HstsMiddleware/HstsMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using MiniWebServer.MiniApp;
using MiniWebServer.MiniApp.Content;
using MiniWebServer.MiniApp;
using System.Text;

namespace MiniWebServer.HstsMiddleware
Expand Down
6 changes: 0 additions & 6 deletions Middleware/HstsMiddleware/HstsMiddlewareExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MiniWebServer.MiniApp.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.HstsMiddleware
{
Expand Down
10 changes: 1 addition & 9 deletions Middleware/HstsMiddleware/HstsOptions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
using MiniWebServer.Abstractions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.HstsMiddleware
namespace MiniWebServer.HstsMiddleware
{
public class HstsOptions
{
Expand Down
1 change: 0 additions & 1 deletion Middleware/HttpsRedirection/HttpsRedirectionMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using MiniWebServer.MiniApp;
using MiniWebServer.MiniApp.Content;

namespace MiniWebServer.HttpsRedirection
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MiniWebServer.MiniApp.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.HttpsRedirection
{
Expand Down
5 changes: 0 additions & 5 deletions Middleware/HttpsRedirection/HttpsRedirectionOptions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using MiniWebServer.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.HttpsRedirection
{
Expand Down
10 changes: 6 additions & 4 deletions Middleware/Mvc/CreateParameterValueResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ public static CreateParameterValueResult Success(object? value)
return successEmptyResult;
}

return new CreateParameterValueResult {
Value = value, IsCreated = true
return new CreateParameterValueResult
{
Value = value,
IsCreated = true
};
}

public static CreateParameterValueResult Fail()
{
return failResult;
return failResult;
}


// we have some singleton values here to prevent alloc/free memory blocks
private static readonly CreateParameterValueResult failResult = new()
private static readonly CreateParameterValueResult failResult = new()
{
Value = null,
IsCreated = false
Expand Down
5 changes: 0 additions & 5 deletions Middleware/Mvc/IActionFinder.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using MiniWebServer.MiniApp;
using MiniWebServer.Mvc.Abstraction;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Mvc
{
Expand Down
8 changes: 1 addition & 7 deletions Middleware/Mvc/IRouteMatcher.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniWebServer.Mvc
namespace MiniWebServer.Mvc
{
public interface IRouteMatcher
{
Expand Down
Loading

0 comments on commit 92d8bc3

Please sign in to comment.