|
@@ -8,7 +8,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|
|
using System.IdentityModel.Tokens.Jwt;
|
|
|
using System.Linq;
|
|
|
|
|
|
-namespace TEAMModelOS.Controllers.Client
|
|
|
+namespace TEAMModelOS.Filter
|
|
|
{
|
|
|
public class AuthTokenAttribute : Attribute, IFilterFactory
|
|
|
{
|
|
@@ -25,8 +25,8 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
private class InternalAuthTokenFilter : IResourceFilter
|
|
|
{
|
|
|
private readonly Option _option;
|
|
|
- private readonly string _roles ;
|
|
|
- private readonly string _permissions ;
|
|
|
+ private readonly string _roles;
|
|
|
+ private readonly string _permissions;
|
|
|
|
|
|
public InternalAuthTokenFilter(IOptions<Option> option, string roles, string permissions)
|
|
|
{
|
|
@@ -37,10 +37,13 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
public void OnResourceExecuting(ResourceExecutingContext context)
|
|
|
{
|
|
|
bool pass = false;
|
|
|
+ string id = string.Empty, school = string.Empty;
|
|
|
var authtoken = context.HttpContext.GetXAuth("AuthToken");
|
|
|
if (!string.IsNullOrWhiteSpace(authtoken) && JwtAuthExtension.ValidateAuthToken(authtoken, _option.JwtSecretKey))
|
|
|
{
|
|
|
var jwt = new JwtSecurityTokenHandler().ReadJwtToken(authtoken);
|
|
|
+ id = jwt.Payload.Sub;
|
|
|
+ school = jwt.Payload.Azp;
|
|
|
if (!string.IsNullOrWhiteSpace(_roles))
|
|
|
{
|
|
|
var roles = jwt.Claims.Where(c => c.Type == "roles");
|
|
@@ -57,7 +60,7 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
{
|
|
|
var permissions = jwt.Claims.Where(c => c.Type == "permissions");
|
|
|
foreach (var permission in permissions)
|
|
|
- {
|
|
|
+ {
|
|
|
if (_permissions.Contains(permission.Value, StringComparison.Ordinal))
|
|
|
{
|
|
|
pass = true;
|
|
@@ -67,7 +70,13 @@ namespace TEAMModelOS.Controllers.Client
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!pass) context.Result = new BadRequestResult();
|
|
|
+ if (pass)
|
|
|
+ {
|
|
|
+ context.HttpContext.Items.Add("ID", id);
|
|
|
+ context.HttpContext.Items.Add("School", school);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ context.Result = new BadRequestResult();
|
|
|
}
|
|
|
|
|
|
public void OnResourceExecuted(ResourceExecutedContext context)
|