Browse Source

Added test code.

pull/208/head
Halil İbrahim Kalkan 9 years ago
parent
commit
05470b0676
  1. 8
      src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs
  2. 16
      src/AbpDesk/AbpDesk.Web.Mvc/Controllers/AuthTestController.cs
  3. 19
      src/AbpDesk/AbpDesk.Web.Mvc/Pages/App/Tickets/Index.cshtml
  4. 4
      src/Volo.Abp.Authorization/Volo.Abp.Authorization.csproj
  5. 5
      src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationModule.cs

8
src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs

@ -79,7 +79,13 @@ namespace AbpDesk.Web.Mvc
var authentication = services.AddAuthentication();
services.AddAuthorization();
services.AddAuthorization(options =>
{
options.AddPolicy("RequirePhoneNumber", policy =>
{
policy.RequireClaim("phone_number");
});
});
authentication.AddIdentityServerAuthentication("Bearer", options =>
{

16
src/AbpDesk/AbpDesk.Web.Mvc/Controllers/AuthTestController.cs

@ -0,0 +1,16 @@
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
namespace AbpDesk.Web.Mvc.Controllers
{
public class AuthTestController : AbpController
{
[Authorize(Policy = "RequirePhoneNumber")]
public ContentResult PhoneNumberIsRequired()
{
return Content("OK: " + User.Claims.First(c => c.Type == "phone_number")?.Value);
}
}
}

19
src/AbpDesk/AbpDesk.Web.Mvc/Pages/App/Tickets/Index.cshtml

@ -1,9 +1,11 @@
@page
@using AbpDesk.Web.Mvc.Pages.App.Tickets
@using Volo.Abp.Session
@model AbpDesk.Web.Mvc.Pages.App.Tickets.IndexModel
@inject ICurrentUser CurrentUser;
@section styles
{
{
<link rel="stylesheet" type="text/css" href="~/global-styles.css" />
}
@ -17,4 +19,19 @@
<p>@ticket.Body</p>
</li>
}
</ul>
<p>
Roles: @CurrentUser.Roles.JoinAsString(", ") <br />
IsInRole Supporter: @User.IsInRole("Supporter") <br />
IsInRole Supporter: @CurrentUser.IsInRole("Supporter")
</p>
<h4>Claims</h4>
<ul>
@foreach (var claim in User.Claims)
{
<li>@claim.Type : @claim.Value</li>
}
</ul>

4
src/Volo.Abp.Authorization/Volo.Abp.Authorization.csproj

@ -13,6 +13,10 @@
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="2.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
</ItemGroup>

5
src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationModule.cs

@ -7,6 +7,11 @@ namespace Volo.Abp.Authorization
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddAuthorization(options =>
{
});
services.AddAssemblyOf<AbpAuthorizationModule>();
}
}

Loading…
Cancel
Save