mirror of https://github.com/abpframework/abp.git
3 changed files with 158 additions and 5 deletions
@ -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 *@ |
|||
|
|||
<div class="grants"> |
|||
<div class="row page-header"> |
|||
<div class="col-sm-10"> |
|||
<h1> |
|||
Client Application Access |
|||
</h1> |
|||
<div>Below is the list of applications you have given access to and the names of the resources they have access to.</div> |
|||
</div> |
|||
</div> |
|||
@if (Model.Grants.Any() == false) |
|||
{ |
|||
<div class="row"> |
|||
<div class="col-sm-8"> |
|||
<div class="alert alert-info"> |
|||
You have not given access to any applications |
|||
</div> |
|||
</div> |
|||
</div> |
|||
} |
|||
else |
|||
{ |
|||
foreach (var grant in Model.Grants) |
|||
{ |
|||
<div class="row grant"> |
|||
<div class="col-sm-2"> |
|||
@if (grant.ClientLogoUrl != null) |
|||
{ |
|||
<img src="@grant.ClientLogoUrl"> |
|||
} |
|||
</div> |
|||
<div class="col-sm-8"> |
|||
<div class="clientname">@grant.ClientName</div> |
|||
<div> |
|||
<span class="created">Created:</span> @grant.Created.ToString("yyyy-MM-dd") |
|||
</div> |
|||
@if (grant.Expires.HasValue) |
|||
{ |
|||
<div> |
|||
<span class="expires">Expires:</span> @grant.Expires.Value.ToString("yyyy-MM-dd") |
|||
</div> |
|||
} |
|||
@if (grant.IdentityGrantNames.Any()) |
|||
{ |
|||
<div> |
|||
<div class="granttype">Identity Grants</div> |
|||
<ul> |
|||
@foreach (var name in grant.IdentityGrantNames) |
|||
{ |
|||
<li>@name</li> |
|||
} |
|||
</ul> |
|||
</div> |
|||
} |
|||
@if (grant.ApiGrantNames.Any()) |
|||
{ |
|||
<div> |
|||
<div class="granttype">API Grants</div> |
|||
<ul> |
|||
@foreach (var name in grant.ApiGrantNames) |
|||
{ |
|||
<li>@name</li> |
|||
} |
|||
</ul> |
|||
</div> |
|||
} |
|||
</div> |
|||
<div class="col-sm-2"> |
|||
<form asp-action="Revoke"> |
|||
<input type="hidden" name="clientId" value="@grant.ClientId"> |
|||
<button class="btn btn-danger">Revoke Access</button> |
|||
</form> |
|||
</div> |
|||
</div> |
|||
} |
|||
} |
|||
</div> |
|||
@ -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<GrantViewModel> 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<GrantViewModel>(); |
|||
|
|||
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<IActionResult> 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<string> IdentityGrantNames { get; set; } |
|||
public IEnumerable<string> ApiGrantNames { get; set; } |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue