Permalink
Browse files

Added examples of using [Authorize(Roles)] and User.IsInRole

  • Loading branch information...
robdmoore committed Oct 24, 2014
1 parent 5207c99 commit 645adabdc84bc8dc4e82bb98d2621ecb1bcc6824
@@ -203,6 +203,9 @@
<Content Include="Views\Shared\_Layout.cshtml" />
<Content Include="Views\Home\Index.cshtml" />
<Content Include="Views\Logout\Callback.cshtml" />
+ <Content Include="Views\Home\Group1.cshtml" />
+ <Content Include="Views\Home\Group2.cshtml" />
+ <Content Include="Views\Home\Group3.cshtml" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
@@ -8,5 +8,23 @@ public ActionResult Index()
{
return View();
}
+
+ [Authorize(Roles = "Group 1")]
+ public ActionResult Group1()
+ {
+ return View();
+ }
+
+ [Authorize(Roles = "Group 2")]
+ public ActionResult Group2()
+ {
+ return View();
+ }
+
+ [Authorize(Roles = "Group 3")]
+ public ActionResult Group3()
+ {
+ return View();
+ }
}
}
@@ -0,0 +1,5 @@
+@{
+ ViewBag.Title = "Member of Group 1";
+}
+
+<h1>This user is a member of Group 1 in Azure AD</h1>
@@ -0,0 +1,5 @@
+@{
+ ViewBag.Title = "Member of Group 2";
+}
+
+<h1>This user is a member of Group 2 in Azure AD</h1>
@@ -0,0 +1,5 @@
+@{
+ ViewBag.Title = "Member of Group 3";
+}
+
+<h1>This user is a member of Group 3 in Azure AD</h1>
@@ -23,6 +23,18 @@
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
+ @if (User.IsInRole("Group 1"))
+ {
+ <li>@Html.ActionLink("Group 1", "Group1", "Home")</li>
+ }
+ @if (User.IsInRole("Group 2"))
+ {
+ <li>@Html.ActionLink("Group 2", "Group2", "Home")</li>
+ }
+ @if (User.IsInRole("Group 3"))
+ {
+ <li>@Html.ActionLink("Group 3", "Group3", "Home")</li>
+ }
@if (User.Identity.IsAuthenticated)
{
<li>@Html.ActionLink("Logout", "Index", "Logout")</li>
View
@@ -18,4 +18,5 @@ Infrastructure Setup
* Application with realm / audience URL `http://localhost:34999` and client ID `4e84d32e-7c1d-420b-88ac-e5cb655d292f` (matches the IIS Express setting for the local site)
* Application with realm / audience URL `https://azureadmvcexample.azurewebsites.net` and client ID `e4a511a6-f9a2-408c-a4a1-c687bc93e297`
* The following test users:
- * `username1@azureadmvcexample.onmicrosoft.com` with password `P@ssword2`
+ * `username1@azureadmvcexample.onmicrosoft.com` with password `P@ssword2`, which is a member of `Group 1` and `Group 2`
+ * `username2@azureadmvcexample.onmicrosoft.com` with password `P@ssword2`, which is a member of `Group 2` and `Group 3`

0 comments on commit 645adab

Please sign in to comment.