From 86dc1b8a2b4136cbdf16e0024eb17757e4e87672 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 10 Nov 2024 14:30:12 +0000 Subject: [PATCH] re-indentity --- dnx-install.sh | 30 ------ .../Controllers/Consent/ConsentController.cs | 5 +- .../Controllers/Consent/ConsentInputModel.cs | 17 ++++ .../Controllers/Consent/ConsentOptions.cs | 16 +++ .../Controllers/Consent/ConsentViewModel.cs | 19 ++++ .../Consent/ProcessConsentResult.cs | 21 ++++ .../Controllers/Consent/ScopeViewModel.cs | 16 +++ src/Yavsc/Controllers/GrantsController.cs | 99 +++++++++++++++++++ src/Yavsc/Program.cs | 4 +- src/Yavsc/Views/Home/Chat.cshtml | 5 +- src/Yavsc/Views/Home/Index.cshtml | 11 +-- src/Yavsc/Views/Shared/_Layout.cshtml | 15 +-- src/Yavsc/Views/Shared/_LoginPartial.cshtml | 3 +- src/Yavsc/issue-1-mono.md | 8 -- src/Yavsc/sql.pgsql | 6 -- src/Yavsc/wwwroot/css/site.css | 20 +++- src/Yavsc/wwwroot/css/site.scss | 8 ++ 17 files changed, 233 insertions(+), 70 deletions(-) delete mode 100644 dnx-install.sh create mode 100644 src/Yavsc/Controllers/Consent/ConsentInputModel.cs create mode 100644 src/Yavsc/Controllers/Consent/ConsentOptions.cs create mode 100644 src/Yavsc/Controllers/Consent/ConsentViewModel.cs create mode 100644 src/Yavsc/Controllers/Consent/ProcessConsentResult.cs create mode 100644 src/Yavsc/Controllers/Consent/ScopeViewModel.cs create mode 100644 src/Yavsc/Controllers/GrantsController.cs delete mode 100644 src/Yavsc/issue-1-mono.md delete mode 100644 src/Yavsc/sql.pgsql diff --git a/dnx-install.sh b/dnx-install.sh deleted file mode 100644 index 7e57945b..00000000 --- a/dnx-install.sh +++ /dev/null @@ -1,30 +0,0 @@ - -set -e - -# config -export DNX_USER_HOME="`pwd -P`/dnx" - -# rt -mkdir -p dnx/runtimes -cd dnx/runtimes -curl --insecure -sSL https://freespeech.pschneider.fr/files/Paul/dnx-mono.1.0.0-rc1-update2.tar.bz2 |tar xj -cd .. - -# dnvm -mkdir -p dnvm -cd dnvm -curl --insecure -sSL https://freespeech.pschneider.fr/files/Paul/dnvm.sh >dnvm.sh -cd .. - -# alias -mkdir -p alias -echo "dnx-mono.1.0.0-rc1-update2" >alias/default.alias -. dnvm/dnvm.sh - -# end -cd .. - -echo "DNX a été ressucité dans $DNX_USER_HOME" -echo "Pour utiliser dnx et dnu:" -echo " . ${DNX_USER_HOME}/dnvm/dnvm.sh" - diff --git a/src/Yavsc/Controllers/Consent/ConsentController.cs b/src/Yavsc/Controllers/Consent/ConsentController.cs index b85fcad7..e597380f 100644 --- a/src/Yavsc/Controllers/Consent/ConsentController.cs +++ b/src/Yavsc/Controllers/Consent/ConsentController.cs @@ -14,10 +14,10 @@ using System.Threading.Tasks; using IdentityServer4.Validation; using System.Collections.Generic; using System; -using Yavsc.Models.Access; +using Yavsc; using Yavsc.Extensions; -namespace Yavsc.Controllers +namespace IdentityServerHost.Quickstart.UI { /// /// This controller processes the consent UI @@ -69,7 +69,6 @@ namespace Yavsc.Controllers if (result.IsRedirect) { var context = await _interaction.GetAuthorizationContextAsync(model.ReturnUrl); - if (context?.IsNativeClient() == true) { // The client is native, so this change in how to diff --git a/src/Yavsc/Controllers/Consent/ConsentInputModel.cs b/src/Yavsc/Controllers/Consent/ConsentInputModel.cs new file mode 100644 index 00000000..f608fe3b --- /dev/null +++ b/src/Yavsc/Controllers/Consent/ConsentInputModel.cs @@ -0,0 +1,17 @@ +// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. +// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. + + +using System.Collections.Generic; + +namespace IdentityServerHost.Quickstart.UI +{ + public class ConsentInputModel + { + public string Button { get; set; } + public IEnumerable ScopesConsented { get; set; } + public bool RememberConsent { get; set; } + public string ReturnUrl { get; set; } + public string Description { get; set; } + } +} \ No newline at end of file diff --git a/src/Yavsc/Controllers/Consent/ConsentOptions.cs b/src/Yavsc/Controllers/Consent/ConsentOptions.cs new file mode 100644 index 00000000..998c51dc --- /dev/null +++ b/src/Yavsc/Controllers/Consent/ConsentOptions.cs @@ -0,0 +1,16 @@ +// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. +// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. + + +namespace IdentityServerHost.Quickstart.UI +{ + public class ConsentOptions + { + public static bool EnableOfflineAccess = true; + public static string OfflineAccessDisplayName = "Offline Access"; + public static string OfflineAccessDescription = "Access to your applications and resources, even when you are offline"; + + public static readonly string MustChooseOneErrorMessage = "You must pick at least one permission"; + public static readonly string InvalidSelectionErrorMessage = "Invalid selection"; + } +} diff --git a/src/Yavsc/Controllers/Consent/ConsentViewModel.cs b/src/Yavsc/Controllers/Consent/ConsentViewModel.cs new file mode 100644 index 00000000..af4b9c5c --- /dev/null +++ b/src/Yavsc/Controllers/Consent/ConsentViewModel.cs @@ -0,0 +1,19 @@ +// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. +// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. + + +using System.Collections.Generic; + +namespace IdentityServerHost.Quickstart.UI +{ + public class ConsentViewModel : ConsentInputModel + { + public string ClientName { get; set; } + public string ClientUrl { get; set; } + public string ClientLogoUrl { get; set; } + public bool AllowRememberConsent { get; set; } + + public IEnumerable IdentityScopes { get; set; } + public IEnumerable ApiScopes { get; set; } + } +} diff --git a/src/Yavsc/Controllers/Consent/ProcessConsentResult.cs b/src/Yavsc/Controllers/Consent/ProcessConsentResult.cs new file mode 100644 index 00000000..1d331df0 --- /dev/null +++ b/src/Yavsc/Controllers/Consent/ProcessConsentResult.cs @@ -0,0 +1,21 @@ +// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. +// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. + + +using IdentityServer4.Models; + +namespace IdentityServerHost.Quickstart.UI +{ + public class ProcessConsentResult + { + public bool IsRedirect => RedirectUri != null; + public string RedirectUri { get; set; } + public Client Client { get; set; } + + public bool ShowView => ViewModel != null; + public ConsentViewModel ViewModel { get; set; } + + public bool HasValidationError => ValidationError != null; + public string ValidationError { get; set; } + } +} diff --git a/src/Yavsc/Controllers/Consent/ScopeViewModel.cs b/src/Yavsc/Controllers/Consent/ScopeViewModel.cs new file mode 100644 index 00000000..532d1b1a --- /dev/null +++ b/src/Yavsc/Controllers/Consent/ScopeViewModel.cs @@ -0,0 +1,16 @@ +// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. +// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. + + +namespace IdentityServerHost.Quickstart.UI +{ + public class ScopeViewModel + { + public string Value { get; set; } + public string DisplayName { get; set; } + public string Description { get; set; } + public bool Emphasize { get; set; } + public bool Required { get; set; } + public bool Checked { get; set; } + } +} diff --git a/src/Yavsc/Controllers/GrantsController.cs b/src/Yavsc/Controllers/GrantsController.cs new file mode 100644 index 00000000..852f438c --- /dev/null +++ b/src/Yavsc/Controllers/GrantsController.cs @@ -0,0 +1,99 @@ +// Copyright (c) Brock Allen & Dominick Baier. All rights reserved. +// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. + + +using IdentityServer4.Services; +using IdentityServer4.Stores; +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using IdentityServer4.Events; +using IdentityServer4.Extensions; +using Yavsc; +using Yavsc.Models.Access; + +namespace IdentityServerHost.Quickstart.UI +{ + /// + /// This sample controller allows a user to revoke grants given to clients + /// + [SecurityHeaders] + [Authorize] + public class GrantsController : Controller + { + private readonly IIdentityServerInteractionService _interaction; + private readonly IClientStore _clients; + private readonly IResourceStore _resources; + private readonly IEventService _events; + + public GrantsController(IIdentityServerInteractionService interaction, + IClientStore clients, + IResourceStore resources, + IEventService events) + { + _interaction = interaction; + _clients = clients; + _resources = resources; + _events = events; + } + + /// + /// Show list of grants + /// + [HttpGet] + public async Task Index() + { + return View("Index", await BuildViewModelAsync()); + } + + /// + /// Handle postback to revoke a client + /// + [HttpPost] + [ValidateAntiForgeryToken] + public async Task Revoke(string clientId) + { + await _interaction.RevokeUserConsentAsync(clientId); + await _events.RaiseAsync(new GrantsRevokedEvent(User.GetSubjectId(), clientId)); + + return RedirectToAction("Index"); + } + + private async Task BuildViewModelAsync() + { + var grants = await _interaction.GetAllUserGrantsAsync(); + + var list = new List(); + foreach(var grant in grants) + { + var client = await _clients.FindClientByIdAsync(grant.ClientId); + if (client != null) + { + var resources = await _resources.FindResourcesByScopeAsync(grant.Scopes); + + var item = new GrantViewModel() + { + ClientId = client.ClientId, + ClientName = client.ClientName ?? client.ClientId, + ClientLogoUrl = client.LogoUri, + ClientUrl = client.ClientUri, + Description = grant.Description, + Created = grant.CreationTime, + Expires = grant.Expiration, + IdentityGrantNames = resources.IdentityResources.Select(x => x.DisplayName ?? x.Name).ToArray(), + ApiGrantNames = resources.ApiScopes.Select(x => x.DisplayName ?? x.Name).ToArray() + }; + + list.Add(item); + } + } + + return new GrantsViewModel + { + Grants = list + }; + } + } +} diff --git a/src/Yavsc/Program.cs b/src/Yavsc/Program.cs index 58893f8a..93be79cb 100644 --- a/src/Yavsc/Program.cs +++ b/src/Yavsc/Program.cs @@ -10,10 +10,10 @@ namespace Yavsc { var builder = WebApplication.CreateBuilder(args); builder.Configuration - .AddEnvironmentVariables() .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true) - .AddEnvironmentVariables().Build(); + .AddEnvironmentVariables() + .Build(); var app = builder.ConfigureServices().ConfigurePipeline(); app.UseSession(); app.Run(); diff --git a/src/Yavsc/Views/Home/Chat.cshtml b/src/Yavsc/Views/Home/Chat.cshtml index df82f107..e08aa29b 100644 --- a/src/Yavsc/Views/Home/Chat.cshtml +++ b/src/Yavsc/Views/Home/Chat.cshtml @@ -16,8 +16,7 @@ } - - - + + } diff --git a/src/Yavsc/Views/Home/Index.cshtml b/src/Yavsc/Views/Home/Index.cshtml index 93de3dd0..854e4d7b 100755 --- a/src/Yavsc/Views/Home/Index.cshtml +++ b/src/Yavsc/Views/Home/Index.cshtml @@ -70,16 +70,7 @@ } } - @if (multipleact) { - - - Précédent - - - - Suivant - - } + } diff --git a/src/Yavsc/Views/Shared/_Layout.cshtml b/src/Yavsc/Views/Shared/_Layout.cshtml index 09af7af9..0682ddaa 100644 --- a/src/Yavsc/Views/Shared/_Layout.cshtml +++ b/src/Yavsc/Views/Shared/_Layout.cshtml @@ -5,10 +5,14 @@ - - - - + + + + + + @await RenderSectionAsync("header", false) @@ -38,10 +42,9 @@ © 2024 - Yavsc - Privacy - - @await RenderSectionAsync("scripts", false) + diff --git a/src/Yavsc/Views/Shared/_LoginPartial.cshtml b/src/Yavsc/Views/Shared/_LoginPartial.cshtml index 0f67ff0b..a95c1363 100644 --- a/src/Yavsc/Views/Shared/_LoginPartial.cshtml +++ b/src/Yavsc/Views/Shared/_LoginPartial.cshtml @@ -46,7 +46,8 @@ Manage your account -
  • Logout
  • +
  • Your Grants
  • +
  • Logout
  • } diff --git a/src/Yavsc/issue-1-mono.md b/src/Yavsc/issue-1-mono.md deleted file mode 100644 index 102fee0c..00000000 --- a/src/Yavsc/issue-1-mono.md +++ /dev/null @@ -1,8 +0,0 @@ -# using mono > 4.6.2 breaks the dnx behaviour - -```term -SynchronizationLockException: Object synchronization method was called from an unsynchronized block of code. -in (wrapper managed-to-native) System.Threading.Monitor.Exit(object) - - -``` diff --git a/src/Yavsc/sql.pgsql b/src/Yavsc/sql.pgsql deleted file mode 100644 index 178d1b0b..00000000 --- a/src/Yavsc/sql.pgsql +++ /dev/null @@ -1,6 +0,0 @@ --- select * from "AspNetRoles"; --- select * from "AspNetUserRoles"; -select "AspNetUsers"."UserName", "AspNetRoles"."Name" from "AspNetUsers" -inner join "AspNetUserRoles" on "AspNetUserRoles"."UserId" = "AspNetUsers"."Id" -inner join "AspNetRoles" on "AspNetRoles"."Id" = "AspNetUserRoles"."RoleId" -; diff --git a/src/Yavsc/wwwroot/css/site.css b/src/Yavsc/wwwroot/css/site.css index 1e59c4aa..7681dba1 100644 --- a/src/Yavsc/wwwroot/css/site.css +++ b/src/Yavsc/wwwroot/css/site.css @@ -13,4 +13,22 @@ .navbar-dark .navbar-toggler-icon { background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.55%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e"); } -/*# sourceMappingURL=site.css.map */ +/* bootstrap.css | http://localhost:5000/lib/bootstrap/css/bootstrap.css */ +.nav-link { + /* background-color: var(--bs-nav-tabs-link-active-bg); */ + background-color: black; } + +.dropdown-item { + /* background-color: transparent; */ + background-color: black; } + +.dropdown-menu { + /* background-color: var(--bs-dropdown-bg); */ + background-color: black; } + +div.carousel-inner > div.item > div.carousel-caption-s { + margin: .5em; + background-color: rgba(0, 0, 0, 0.6); + color: #ffffc8; + font-weight: bold; + padding: .5em; } diff --git a/src/Yavsc/wwwroot/css/site.scss b/src/Yavsc/wwwroot/css/site.scss index 56280459..93a8d9d7 100644 --- a/src/Yavsc/wwwroot/css/site.scss +++ b/src/Yavsc/wwwroot/css/site.scss @@ -40,3 +40,11 @@ /* background-color: var(--bs-dropdown-bg); */ background-color: black; } + +div.carousel-inner > div.item > div.carousel-caption-s { + margin: .5em; + background-color: rgba(0,0,0,.6); + color: rgb(255,255,200); + font-weight: bold; + padding: .5em; +}