Skip to content

Instantly share code, notes, and snippets.

@scottcate
Last active September 23, 2016 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottcate/52d0c09fdf23587b4cb3b789b99c1f5b to your computer and use it in GitHub Desktop.
Save scottcate/52d0c09fdf23587b4cb3b789b99c1f5b to your computer and use it in GitHub Desktop.
namespace definition
{
public class AuthorizationGroup
{
public string[] Groups { get; set; }
}
}
using Newtonsoft.Json;
using definition;
public override async Task ProcessRequestAsync(HttpContext context)
{
///...
///...
var auth = profile.AppMetadata["authorization"];
if (auth !=null)
{
//{{ "authorization": { "groups": [ "Administrator" ] }}}
AuthorizationGroup authorization = JsonConvert.DeserializeObject<AuthorizationGroup>(auth.ToString());
foreach (var role in authorization.Groups)
{
user.Add(new KeyValuePair<string, object>(ClaimTypes.Role, role));
}
}
///...
///...
}
@if (User.IsInRole("Administrator"))
{
<h1>Administrator.FTW</h1>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment