-
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.
Better authorization for Management API using JWT tokens.
- Loading branch information
1 parent
153c78d
commit ff4493e
Showing
6 changed files
with
113 additions
and
13 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
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,23 @@ | ||
#if MANAGEMENT_API | ||
using Microsoft.AspNetCore.Http; | ||
using NomadIIS.Services; | ||
using System; | ||
|
||
namespace NomadIIS.ManagementApi; | ||
|
||
public static class Authorization | ||
{ | ||
public static bool IsAuthorized ( this IisTaskHandle taskHandle, HttpContext httpContext ) | ||
{ | ||
var jobName = taskHandle.TaskConfig?.JobName ?? throw new InvalidOperationException(); | ||
var allocId = taskHandle.TaskConfig?.AllocId ?? throw new InvalidOperationException(); | ||
|
||
if ( !httpContext.User.HasClaim( "job", jobName ) && !httpContext.User.HasClaim( "job", "*" ) ) | ||
return false; | ||
if ( !httpContext.User.HasClaim( "allocId", allocId ) && !httpContext.User.HasClaim( "allocId", "*" ) ) | ||
return false; | ||
|
||
return true; | ||
} | ||
} | ||
#endif |
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