diff --git a/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Grants.cshtml b/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Grants.cshtml new file mode 100644 index 0000000000..069301af3a --- /dev/null +++ b/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Grants.cshtml @@ -0,0 +1,82 @@ +@page +@using Volo.Abp.Account.Web.Pages.Account +@model GrantsModel + +@* TODO: Should work on the page HTML, copy/pasted from IDS4 samples *@ + +
+ + @if (Model.Grants.Any() == false) + { +
+
+
+ You have not given access to any applications +
+
+
+ } + else + { + foreach (var grant in Model.Grants) + { +
+
+ @if (grant.ClientLogoUrl != null) + { + + } +
+
+
@grant.ClientName
+
+ Created: @grant.Created.ToString("yyyy-MM-dd") +
+ @if (grant.Expires.HasValue) + { +
+ Expires: @grant.Expires.Value.ToString("yyyy-MM-dd") +
+ } + @if (grant.IdentityGrantNames.Any()) + { +
+
Identity Grants
+
    + @foreach (var name in grant.IdentityGrantNames) + { +
  • @name
  • + } +
+
+ } + @if (grant.ApiGrantNames.Any()) + { +
+
API Grants
+
    + @foreach (var name in grant.ApiGrantNames) + { +
  • @name
  • + } +
+
+ } +
+
+
+ + +
+
+
+ } + } +
\ No newline at end of file diff --git a/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Grants.cshtml.cs b/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Grants.cshtml.cs new file mode 100644 index 0000000000..eeb83453a6 --- /dev/null +++ b/src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Grants.cshtml.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using IdentityServer4.Services; +using IdentityServer4.Stores; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.RazorPages; + +namespace Volo.Abp.Account.Web.Pages.Account +{ + public class GrantsModel : AbpPageModel + { + public List Grants { get; set; } + + private readonly IIdentityServerInteractionService _interaction; + private readonly IClientStore _clients; + private readonly IResourceStore _resources; + + public GrantsModel(IIdentityServerInteractionService interaction, + IClientStore clients, + IResourceStore resources) + { + _interaction = interaction; + _clients = clients; + _resources = resources; + } + + public async Task OnGet() + { + Grants = new List(); + + foreach (var consent in await _interaction.GetAllUserConsentsAsync()) + { + var client = await _clients.FindClientByIdAsync(consent.ClientId); + if (client != null) + { + var resources = await _resources.FindResourcesByScopeAsync(consent.Scopes); + + var item = new GrantViewModel + { + ClientId = client.ClientId, + ClientName = client.ClientName ?? client.ClientId, + ClientLogoUrl = client.LogoUri, + ClientUrl = client.ClientUri, + Created = consent.CreationTime, + Expires = consent.Expiration, + IdentityGrantNames = resources.IdentityResources.Select(x => x.DisplayName ?? x.Name).ToArray(), + ApiGrantNames = resources.ApiResources.Select(x => x.DisplayName ?? x.Name).ToArray() + }; + + Grants.Add(item); + } + } + } + + public async Task OnPostRevokeAsync(string clientId) + { + await _interaction.RevokeUserConsentAsync(clientId); + return Redirect("/"); //TODO: ..? + } + + public class GrantViewModel + { + public string ClientId { get; set; } + public string ClientName { get; set; } + public string ClientUrl { get; set; } + public string ClientLogoUrl { get; set; } + public DateTime Created { get; set; } + public DateTime? Expires { get; set; } + public IEnumerable IdentityGrantNames { get; set; } + public IEnumerable ApiGrantNames { get; set; } + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Account.Web.IdentityServer/Volo.Abp.Account.Web.IdentityServer.csproj b/src/Volo.Abp.Account.Web.IdentityServer/Volo.Abp.Account.Web.IdentityServer.csproj index 26958e48e0..32143716e5 100644 --- a/src/Volo.Abp.Account.Web.IdentityServer/Volo.Abp.Account.Web.IdentityServer.csproj +++ b/src/Volo.Abp.Account.Web.IdentityServer/Volo.Abp.Account.Web.IdentityServer.csproj @@ -18,11 +18,7 @@ - - - - - +