-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/DanDude0/MilwaukeeMakersp…
- Loading branch information
Showing
45 changed files
with
7,467 additions
and
3,730 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ packages | |
bin | ||
obj | ||
PublishProfiles | ||
appsettings.json | ||
logs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
<Router AppAssembly="@typeof(Program).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
</Found> | ||
<NotFound> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p>Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> | ||
<CascadingAuthenticationState> | ||
<Router AppAssembly="@typeof(Program).Assembly"> | ||
<Found Context="routeData"> | ||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
</Found> | ||
<NotFound> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p>Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> | ||
</CascadingAuthenticationState> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.AspNetCore.Authentication.OAuth; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
using System; | ||
|
||
namespace Mms.Api | ||
{ | ||
public class AuthorizingHandler : DelegatingHandler | ||
{ | ||
private readonly OAuthOptions _options; | ||
public AuthorizingHandler(HttpMessageHandler inner, OAuthOptions options) | ||
: base(inner) | ||
{ | ||
_options = options; | ||
} | ||
|
||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
if (request.RequestUri == new Uri(_options.TokenEndpoint)) { | ||
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(_options.ClientId + ":" + _options.ClientSecret)); | ||
|
||
request.Headers.Add("Authorization", $"Basic {credentials}"); | ||
} | ||
return base.SendAsync(request, cancellationToken); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
MilwaukeeMakerspaceApi/Controllers/AuthenticationController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Microsoft.AspNetCore.Authentication; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authentication.Cookies; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Mvc.Client.Controllers; | ||
|
||
[ApiExplorerSettings(IgnoreApi = true)] | ||
public class AuthenticationController : Controller | ||
{ | ||
[HttpGet("/login")] | ||
[HttpPost("/login")] | ||
public IActionResult SignIn() | ||
{ | ||
// Instruct the middleware corresponding to the requested external identity | ||
// provider to redirect the user agent to its own authorization endpoint. | ||
// Note: the authenticationScheme parameter must match the value configured in Startup.cs | ||
return Challenge(new AuthenticationProperties { RedirectUri = "/" }, "WildApricot"); | ||
} | ||
|
||
[HttpGet("/logout")] | ||
[HttpPost("/logout")] | ||
public IActionResult SignOutCurrentUser() | ||
{ | ||
// Instruct the cookies middleware to delete the local cookie created | ||
// when the user agent is redirected from the external identity provider | ||
// after a successful authentication flow (e.g Google or Facebook). | ||
return SignOut(new AuthenticationProperties { RedirectUri = "/" }, | ||
CookieAuthenticationDefaults.AuthenticationScheme); | ||
} | ||
|
||
private static async Task<AuthenticationScheme[]> GetExternalProvidersAsync(HttpContext context) | ||
{ | ||
ArgumentNullException.ThrowIfNull(context); | ||
|
||
var schemes = context.RequestServices.GetRequiredService<IAuthenticationSchemeProvider>(); | ||
|
||
return (from scheme in await schemes.GetAllSchemesAsync() | ||
where !string.IsNullOrEmpty(scheme.DisplayName) | ||
select scheme).ToArray(); | ||
} | ||
|
||
private static async Task<bool> IsProviderSupportedAsync(HttpContext context, string provider) | ||
{ | ||
ArgumentNullException.ThrowIfNull(context); | ||
|
||
return (from scheme in await GetExternalProvidersAsync(context) | ||
where string.Equals(scheme.Name, provider, StringComparison.OrdinalIgnoreCase) | ||
select scheme).Any(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.