Fix claiming

This commit is contained in:
Jordan Brown
2018-04-16 18:41:32 -04:00
parent 410d241a6f
commit a051ee4fe1
3 changed files with 7 additions and 6 deletions
+2 -2
View File
@@ -33,12 +33,12 @@ namespace Tgstation.Server.Api
/// <summary>
/// The JWT authentication header scheme
/// </summary>
const string jwtAuthenticationScheme = "bearer";
const string jwtAuthenticationScheme = "Bearer";
/// <summary>
/// The password authentication header scheme
/// </summary>
const string passwordAuthenticationScheme = "password";
const string passwordAuthenticationScheme = "Password";
/// <summary>
/// The current <see cref="AssemblyName"/>
@@ -46,7 +46,7 @@ namespace Tgstation.Server.Api.Rights
/// <param name="rightsType">The <see cref="RightsType"/></param>
/// <param name="right">The right value</param>
/// <returns>A <see cref="string"/> representing the claim role name</returns>
public static string RoleName(RightsType rightsType, int right)
public static string RoleName(RightsType rightsType, Enum right)
{
var enumType = typeMap[rightsType];
return String.Concat(enumType.Name, '.', Enum.GetName(enumType, right));
@@ -88,10 +88,11 @@ namespace Tgstation.Server.Host.Controllers
foreach (RightsType I in enumerator)
{
var rightInt = authenticationContext.GetRight(I);
var right = (Enum)(ValueType)authenticationContext.GetRight(I);
foreach(Enum J in Enum.GetValues(RightsHelper.RightToType(I)))
var rightEnum = RightsHelper.RightToType(I);
var right = (Enum)Enum.ToObject(rightEnum, authenticationContext.GetRight(I));
foreach(Enum J in Enum.GetValues(rightEnum))
if(right.HasFlag(J))
claims.Add(new Claim(ClaimTypes.Role, RightsHelper.RoleName(I, rightInt)));
claims.Add(new Claim(ClaimTypes.Role, RightsHelper.RoleName(I, J)));
}
context.Principal.AddIdentity(new ClaimsIdentity(claims));