diff --git a/src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs b/src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs index 434ad1585f..998f05baa2 100644 --- a/src/AbpDesk/AbpDesk.Web.Mvc/AbpDeskWebMvcModule.cs +++ b/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 => { diff --git a/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/AuthTestController.cs b/src/AbpDesk/AbpDesk.Web.Mvc/Controllers/AuthTestController.cs new file mode 100644 index 0000000000..b4fa507875 --- /dev/null +++ b/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); + } + } +} diff --git a/src/AbpDesk/AbpDesk.Web.Mvc/Pages/App/Tickets/Index.cshtml b/src/AbpDesk/AbpDesk.Web.Mvc/Pages/App/Tickets/Index.cshtml index f289593b38..ad2ea9c211 100644 --- a/src/AbpDesk/AbpDesk.Web.Mvc/Pages/App/Tickets/Index.cshtml +++ b/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 -{ + { } @@ -17,4 +19,19 @@

@ticket.Body

} + + +

+ Roles: @CurrentUser.Roles.JoinAsString(", ")
+ IsInRole Supporter: @User.IsInRole("Supporter")
+ IsInRole Supporter: @CurrentUser.IsInRole("Supporter") +

+ +

Claims

+ + \ No newline at end of file diff --git a/src/Volo.Abp.Authorization/Volo.Abp.Authorization.csproj b/src/Volo.Abp.Authorization/Volo.Abp.Authorization.csproj index 8aadf95fa0..da895d7822 100644 --- a/src/Volo.Abp.Authorization/Volo.Abp.Authorization.csproj +++ b/src/Volo.Abp.Authorization/Volo.Abp.Authorization.csproj @@ -13,6 +13,10 @@ + + + + diff --git a/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationModule.cs b/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationModule.cs index 62ee595e84..63df9f4dfd 100644 --- a/src/Volo.Abp.Authorization/Volo/Abp/Authorization/AbpAuthorizationModule.cs +++ b/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(); } }