From a90470cf28ced42482e20aa8c9073363af1271b6 Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Thu, 16 Jun 2022 16:16:12 +0300 Subject: [PATCH 1/3] Change IdentityServer Index page --- .../Pages/Index.cshtml | 119 ++++++++++++++---- .../Pages/Index.cshtml.cs | 19 ++- 2 files changed, 111 insertions(+), 27 deletions(-) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml index db9f1f100a..c61632e453 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml +++ b/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 L @inject ICurrentUser CurrentUser -@if (CurrentUser.IsAuthenticated) -{ -
+@inject IBrandingProvider BrandingProvider +@inject ITheme Theme + +@{ + Layout = Theme.GetEmptyLayout(); +} + +
+
- - - Logout - - -

@CurrentUser.UserName

-
@CurrentUser.Email
-
- Roles: @CurrentUser.Roles.JoinAsString(", ") -
- Claims:
- @Html.Raw(CurrentUser.GetAllClaims().Select(c => $"{c.Type}={c.Value}").JoinAsString("
")) + + -} + + + + +
+
+
+ +
+
+ @if (CurrentUser.IsAuthenticated) + { + + @L["Welcome"] @CurrentUser.UserName + + @CurrentUser.Email + + } + else + { + @L["Login"] + } +
+
-@if (!CurrentUser.IsAuthenticated) -{ -
-

- Login +
+ + + + @foreach (var client in Model.Clients.Where(x => x.RedirectUris.Count > 0)) + { + + + + + @if (!client.LogoUri.IsNullOrEmpty()) + { +
+ +
+ } + +

@client.ClientName

+ @{ + var redirectUri = new Uri(@client.RedirectUris.First().RedirectUri); + var url = @redirectUri.AbsoluteUri.RemovePostFix(redirectUri.AbsolutePath); + } + @url +
+ Visit +
+
+
+
+ } + +
+
+ + + + +
+ +
-} +
diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml.cs index e8230ee00c..df43e3a798 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml.cs @@ -1,10 +1,25 @@ 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 Clients { get; protected set; } + + // TODO: Consider using IClientStore here. + protected IClientRepository ClientRepository { get; } + + public IndexModel(IClientRepository clientRepository) + { + this.ClientRepository = clientRepository; + } + + public async Task OnGetAsync() { + Clients = await ClientRepository.GetListAsync(includeDetails: true); } -} +} \ No newline at end of file From 9be612f93865290364908c891e4aa05c5fc7be0e Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Thu, 16 Jun 2022 16:16:16 +0300 Subject: [PATCH 2/3] Update IdentityServerDataSeedContributor.cs --- .../IdentityServerDataSeedContributor.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs index da0b56a6d0..466f36658e 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs +++ b/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 scopes, IEnumerable 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) From 0db591f4d1cd6b5b67f91396a67904a8910bcbc4 Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Thu, 16 Jun 2022 16:18:54 +0300 Subject: [PATCH 3/3] Update Index.cshtml.cs --- .../Pages/Index.cshtml.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml.cs index df43e3a798..dee9e692d8 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.IdentityServer/Pages/Index.cshtml.cs @@ -9,8 +9,7 @@ namespace MyCompanyName.MyProjectName.Pages; public class IndexModel : AbpPageModel { public List Clients { get; protected set; } - - // TODO: Consider using IClientStore here. + protected IClientRepository ClientRepository { get; } public IndexModel(IClientRepository clientRepository)