Added test code.

pull/208/head
Halil İbrahim Kalkan 7 years ago
parent b50cee6bd0
commit 05470b0676

@ -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 =>
{

@ -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);
}
}
}

@ -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>

@ -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>

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

Loading…
Cancel
Save