-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from neozhu/addapiclient
Add apiclient and login / logout
- Loading branch information
Showing
139 changed files
with
5,434 additions
and
748 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
24 changes: 24 additions & 0 deletions
24
src/CleanAspire.Api/IdentityApiAdditionalEndpointsExtensions.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,24 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.AspNetCore.Identity; | ||
|
||
namespace CleanAspire.Api; | ||
|
||
public static class IdentityApiAdditionalEndpointsExtensions | ||
{ | ||
public static IEndpointRouteBuilder MapIdentityApiAdditionalEndpoints<TUser>(this IEndpointRouteBuilder endpoints) | ||
where TUser : class, new() | ||
{ | ||
ArgumentNullException.ThrowIfNull(endpoints); | ||
endpoints.MapPost("/logout", async (SignInManager<TUser> signInManager) => | ||
{ | ||
await signInManager.SignOutAsync(); | ||
return Results.Ok(); | ||
}).RequireAuthorization(); | ||
|
||
return endpoints; | ||
} | ||
} | ||
|
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
22 changes: 10 additions & 12 deletions
22
src/CleanAspire.Application/Common/Interfaces/ICurrentUserAccessor.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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
using System.Security.Claims; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace CleanAspire.Application.Common.Interfaces; | ||
namespace CleanAspire.Application.Common.Services; | ||
|
||
/// <summary> | ||
/// Interface to access the current user's session information. | ||
/// </summary> | ||
public interface ICurrentUserAccessor | ||
{ | ||
string? UserId{ get; } | ||
/// <summary> | ||
/// Gets the current session information of the user. | ||
/// </summary> | ||
ClaimsPrincipal? User { get; } | ||
string? UserId { get; } | ||
string? TenantId { get; } | ||
} | ||
|
15 changes: 15 additions & 0 deletions
15
src/CleanAspire.Application/Common/Interfaces/ICurrentUserContext.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,15 @@ | ||
using System.Security.Claims; | ||
|
||
namespace CleanAspire.Application.Common.Services; | ||
|
||
/// <summary> | ||
/// Interface representing the current user context. | ||
/// </summary> | ||
public interface ICurrentUserContext | ||
{ | ||
|
||
ClaimsPrincipal? GetCurrentUser(); | ||
|
||
void Set(ClaimsPrincipal? user); | ||
void Clear(); | ||
} |
20 changes: 20 additions & 0 deletions
20
src/CleanAspire.Application/Common/Interfaces/ICurrentUserContextSetter.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,20 @@ | ||
using System.Security.Claims; | ||
|
||
namespace CleanAspire.Application.Common.Services; | ||
|
||
/// <summary> | ||
/// Interface for setting and clearing the current user context. | ||
/// </summary> | ||
public interface ICurrentUserContextSetter | ||
{ | ||
/// <summary> | ||
/// Sets the current user context with the provided session information. | ||
/// </summary> | ||
/// <param name="user">The session information of the current user.</param> | ||
void SetCurrentUser(ClaimsPrincipal user); | ||
|
||
/// <summary> | ||
/// Clears the current user context. | ||
/// </summary> | ||
void Clear(); | ||
} |
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,27 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using MediatR.Pipeline; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace CleanAspire.Application; | ||
|
||
public static class DependencyInjection | ||
{ | ||
public static IServiceCollection AddApplication(this IServiceCollection services) | ||
{ | ||
services.AddMediatR(config => | ||
{ | ||
config.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()); | ||
}); | ||
return services; | ||
} | ||
} | ||
|
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,12 @@ | ||
<Router AppAssembly="@typeof(App).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
<FocusOnNavigate RouteData="@routeData" Selector="h1" /> | ||
</Found> | ||
<NotFound> | ||
<PageTitle>Not found</PageTitle> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p role="alert">Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> |
Oops, something went wrong.