private static string GetScope(Scopes scopes) { var values = new List <string>(); if (scopes.HasFlag(Scopes.ReadPublic)) { values.Add("read_public"); } if (scopes.HasFlag(Scopes.WritePublic)) { values.Add("write_public"); } if (scopes.HasFlag(Scopes.ReadRelationships)) { values.Add("read_relationships"); } if (scopes.HasFlag(Scopes.WriteRelationships)) { values.Add("write_relationships"); } return(string.Join(",", values)); }
protected override bool IsAuthorized(HttpActionContext actionContext) { if (!base.IsAuthorized(actionContext)) { return(false); } var claimsPrincipal = actionContext.RequestContext.Principal as ClaimsPrincipal; if (claimsPrincipal == null) { return(false); } var scopesInPrincipal = claimsPrincipal.Claims.Where(c => c.Type == "scope").Select(c => c.Value.ToLowerInvariant()); var scopesInFilter = Enum.GetValues(typeof(Scopes)) .Cast <Enum>() .Where(x => _scope.HasFlag(x)) .Cast <Scopes>() .Select(x => x.ToString().ToLowerInvariant()); return(scopesInPrincipal.Intersect(scopesInFilter).Any()); }
private static string GetScope(Scopes scopes) { var values = new List<string>(); if (scopes.HasFlag(Scopes.ReadPublic)) values.Add("read_public"); if (scopes.HasFlag(Scopes.WritePublic)) values.Add("write_public"); if (scopes.HasFlag(Scopes.ReadRelationships)) values.Add("read_relationships"); if (scopes.HasFlag(Scopes.WriteRelationShips)) values.Add("write_relationships"); return string.Join(",", values); }