Browse Source

Merge pull request #13026 from abpframework/enisn/5.3-identity-server-index

Identity Server Index Page
pull/13048/head
Alper Ebiçoğlu 4 years ago
committed by GitHub
parent
commit
fa7b3660f5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs
  2. 119
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml
  3. 18
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml.cs

12
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs

@ -152,6 +152,7 @@ public class IdentityServerDataSeedContributor : IDataSeedContributor, ITransien
await CreateClientAsync(
name: webClientId,
clientUri: webClientRootUrl,
scopes: commonScopes,
grantTypes: new[] { "hybrid" },
secret: (configurationSection["MyProjectName_Web:ClientSecret"] ?? "1q2w3e*").Sha256(),
@ -172,6 +173,7 @@ public class IdentityServerDataSeedContributor : IDataSeedContributor, ITransien
await CreateClientAsync(
name: consoleAndAngularClientId,
clientUri: webClientRootUrl,
scopes: commonScopes,
grantTypes: new[] { "password", "client_credentials", "authorization_code" },
secret: (configurationSection["MyProjectName_App:ClientSecret"] ?? "1q2w3e*").Sha256(),
@ -192,6 +194,7 @@ public class IdentityServerDataSeedContributor : IDataSeedContributor, ITransien
await CreateClientAsync(
name: blazorClientId,
clientUri: blazorRootUrl,
scopes: commonScopes,
grantTypes: new[] { "authorization_code" },
secret: configurationSection["MyProjectName_Blazor:ClientSecret"]?.Sha256(),
@ -217,6 +220,7 @@ public class IdentityServerDataSeedContributor : IDataSeedContributor, ITransien
await CreateClientAsync(
name: blazorServerTieredClientId,
clientUri: blazorServerTieredClientRootUrl,
scopes: commonScopes,
grantTypes: new[] { "hybrid" },
secret: (configurationSection["MyProjectName_BlazorServerTiered:ClientSecret"] ?? "1q2w3e*").Sha256(),
@ -237,6 +241,7 @@ public class IdentityServerDataSeedContributor : IDataSeedContributor, ITransien
await CreateClientAsync(
name: swaggerClientId,
clientUri: swaggerRootUrl,
scopes: commonScopes,
grantTypes: new[] { "authorization_code" },
secret: configurationSection["MyProjectName_Swagger:ClientSecret"]?.Sha256(),
@ -251,6 +256,7 @@ public class IdentityServerDataSeedContributor : IDataSeedContributor, ITransien
string name,
IEnumerable<string> scopes,
IEnumerable<string> grantTypes,
string clientUri = null,
string secret = null,
string redirectUri = null,
string postLogoutRedirectUri = null,
@ -270,6 +276,7 @@ public class IdentityServerDataSeedContributor : IDataSeedContributor, ITransien
)
{
ClientName = name,
ClientUri = clientUri,
ProtocolType = "oidc",
Description = name,
AlwaysIncludeUserClaimsInIdToken = true,
@ -287,6 +294,11 @@ public class IdentityServerDataSeedContributor : IDataSeedContributor, ITransien
);
}
if (client.ClientUri != clientUri)
{
client.ClientUri = clientUri;
}
foreach (var scope in scopes)
{
if (client.FindScope(scope) == null)

119
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml

@ -1,34 +1,103 @@
@page
@using Microsoft.AspNetCore.Mvc.Localization
@using MyCompanyName.MyProjectName.Pages
@using MyCompanyName.MyProjectName.Localization
@using Volo.Abp.Users
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@using Volo.Abp.Ui.Branding
@model IndexModel
@inject IHtmlLocalizer<MyProjectNameResource> L
@inject ICurrentUser CurrentUser
@if (CurrentUser.IsAuthenticated)
{
<div>
@inject IBrandingProvider BrandingProvider
@inject ITheme Theme
@{
Layout = Theme.GetEmptyLayout();
}
<div class="d-flex align-items-center" style="min-height: 100vh;">
<div class="container">
<abp-row>
<abp-column size-md="_3" class="text-center">
<i class="fa fa-user d-block" style="font-size: 10em; color: #12b900"></i>
<a abp-button="Primary" href="/Account/Logout">Logout</a>
</abp-column>
<abp-column size-md="_9">
<h2>@CurrentUser.UserName</h2>
<h5 class="text-muted">@CurrentUser.Email</h5>
<div>
<strong>Roles</strong>: @CurrentUser.Roles.JoinAsString(", ")
<br />
<strong>Claims</strong>: <br />
@Html.Raw(CurrentUser.GetAllClaims().Select(c => $"{c.Type}={c.Value}").JoinAsString(" <br /> "))
<div class="col mx-auto account-column">
<div class="account-brand p-4 text-center mb-1">
@if (!BrandingProvider.LogoUrl.IsNullOrEmpty())
{
<a class="navbar-brand" href="/" alt="@BrandingProvider.AppName"></a>
}
else
{
<h1>@BrandingProvider.AppName</h1>
}
</div>
</abp-column>
</abp-row>
</div>
}
<abp-card>
<abp-card-body>
<div class="container">
<div class="d-flex align-items-center">
<div class="me-3">
<i class="fa fa-user d-block" style="font-size: 10em; color: #12b900"></i>
</div>
<div>
@if (CurrentUser.IsAuthenticated)
{
<span class="fs-16">
@L["Welcome"] <span class="fw-7">@CurrentUser.UserName</span>
</span>
<span class="fs-14 d-block text-dark-800 opacity-75 mb-1">@CurrentUser.Email</span>
<div class="d-grid gap-2">
<a abp-button="Outline_Primary" asp-controller="Manage" asp-action="Index" asp-area="Account">@L["MyAccount"]</a>
<a abp-button="Primary" asp-controller="Logout" asp-action="Index" asp-area="Account">@L["Logout"]</a>
</div>
}
else
{
<a abp-button="Primary" asp-controller="Login" asp-action="Index" asp-area="Account">@L["Login"]</a>
}
</div>
</div>
@if (!CurrentUser.IsAuthenticated)
{
<div class="text-center">
<i class="fa fa-user d-block" style="font-size: 10em; color: #aaa"></i><br/><br />
<a abp-button="Primary" asp-page="/Account/Login">Login</a>
<hr class="m-4" />
<abp-row>
@foreach (var client in Model.Clients.Where(x => x.RedirectUris.Count > 0))
{
<abp-column size-md="_4" class="mb-2">
<abp-card>
<abp-card-body>
@if (!client.LogoUri.IsNullOrEmpty())
{
<div class="mx-auto text-center">
<img src="@client.LogoUri" />
</div>
}
<h4>@client.ClientName</h4>
@{
var redirectUri = new Uri(@client.RedirectUris.First().RedirectUri);
var url = @redirectUri.AbsoluteUri.RemovePostFix(redirectUri.AbsolutePath);
}
<span class="text-muted">@url</span>
<div class="mt-1">
<a abp-button="Outline_Secondary" href="@url">Visit</a>
</div>
</abp-card-body>
</abp-card>
</abp-column>
}
</abp-row>
</div>
</abp-card-body>
</abp-card>
</div>
</abp-row>
</div>
}
</div>

18
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml.cs

@ -1,10 +1,24 @@
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using IdentityServer4.Stores;
using Volo.Abp.IdentityServer.Clients;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace MyCompanyName.MyProjectName.Pages;
public class IndexModel : AbpPageModel
{
public void OnGet()
public List<Client> Clients { get; protected set; }
protected IClientRepository ClientRepository { get; }
public IndexModel(IClientRepository clientRepository)
{
this.ClientRepository = clientRepository;
}
}
public async Task OnGetAsync()
{
Clients = await ClientRepository.GetListAsync(includeDetails: true);
}
}
Loading…
Cancel
Save