Browse Source

Added grants page.

pull/217/head
Halil İbrahim Kalkan 8 years ago
parent
commit
81ceed974f
  1. 82
      src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Grants.cshtml
  2. 75
      src/Volo.Abp.Account.Web.IdentityServer/Pages/Account/Grants.cshtml.cs
  3. 6
      src/Volo.Abp.Account.Web.IdentityServer/Volo.Abp.Account.Web.IdentityServer.csproj

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

75
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<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; }
}
}
}

6
src/Volo.Abp.Account.Web.IdentityServer/Volo.Abp.Account.Web.IdentityServer.csproj

@ -18,11 +18,7 @@
<ItemGroup>
<EmbeddedResource Include="Pages\**\*.*" Exclude="*.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="Pages\_ViewImports.cshtml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Account.Web\Volo.Abp.Account.Web.csproj" />
<ProjectReference Include="..\Volo.Abp.IdentityServer.Domain\Volo.Abp.IdentityServer.Domain.csproj" />

Loading…
Cancel
Save