-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change ICurrentClientIdProvider to ICurrentUserProvider (#1660)
- Loading branch information
Showing
19 changed files
with
103 additions
and
88 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
18 changes: 0 additions & 18 deletions
18
.../TeachingRecordSystem.Api/Infrastructure/Security/ClaimsPrincipalCurrentClientProvider.cs
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
...rc/TeachingRecordSystem.Api/Infrastructure/Security/ClaimsPrincipalCurrentUserProvider.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,31 @@ | ||
using System.Security.Claims; | ||
|
||
namespace TeachingRecordSystem.Api.Infrastructure.Security; | ||
|
||
public class ClaimsPrincipalCurrentUserProvider(IHttpContextAccessor httpContextAccessor) : ICurrentUserProvider | ||
{ | ||
public static bool TryGetCurrentClientIdFromHttpContext(HttpContext httpContext, out Guid userId) | ||
{ | ||
var userIdStr = httpContext.User.FindFirstValue("sub"); | ||
|
||
if (userIdStr is null) | ||
{ | ||
userId = default; | ||
return false; | ||
} | ||
|
||
return Guid.TryParse(userIdStr, out userId); | ||
} | ||
|
||
public Guid GetCurrentApplicationUserId() | ||
{ | ||
var httpContext = httpContextAccessor.HttpContext ?? throw new Exception("No HttpContext."); | ||
|
||
if (!TryGetCurrentClientIdFromHttpContext(httpContext, out var userId)) | ||
{ | ||
throw new Exception("Current user has no 'sub' claim."); | ||
} | ||
|
||
return userId; | ||
} | ||
} |
6 changes: 0 additions & 6 deletions
6
...cordSystem/src/TeachingRecordSystem.Api/Infrastructure/Security/ICurrentClientProvider.cs
This file was deleted.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
...RecordSystem/src/TeachingRecordSystem.Api/Infrastructure/Security/ICurrentUserProvider.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,6 @@ | ||
namespace TeachingRecordSystem.Api.Infrastructure.Security; | ||
|
||
public interface ICurrentUserProvider | ||
{ | ||
Guid GetCurrentApplicationUserId(); | ||
} |
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
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
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.