From 3b48e801096ff1d126d9c3308e615013c1e8e616 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 21 Apr 2021 17:14:49 +0200 Subject: [PATCH] refactor(EF)!: remove useless specialized stores BREAKING CHANGE: EF SchemeDefinition doesn't exist any more. ExtenalProvider is used instead. The DB schema changes --- .../DynamicAuthenticationBuilderExtensions.cs | 22 +- .../UserOnlyStore.cs | 23 +- .../Properties/launchSettings.json | 3 +- .../Quickstart/Account/ExternalController.cs | 5 +- src/Aguacongas.TheIdServer/SeedData.cs | 10 +- src/Aguacongas.TheIdServer/Startup.cs | 37 +-- .../AutoCompleteModel.cs | 2 +- .../Abstraction/EntitiesModel.cs | 23 +- .../Models/ExternalProvider.cs | 13 +- .../Components/IdentityProvider.razor.cs | 2 +- .../ExternalProviders.razor | 2 +- .../ExternalProviders.razor.cs | 6 + .../Extensions/MvcBuilderExtensions.cs | 3 +- .../Filters/ExternalProviderFilter.cs | 44 +++ .../Filters/SelectFilter.cs | 116 ------- .../AdminStore.cs | 4 + ...dentityServer.EntityFramework.Store.csproj | 1 - .../ApplicationDbContext.cs | 6 +- .../ConfigurationDbContext.cs | 18 +- .../Extensions/ServiceCollectionExtensions.cs | 6 +- .../SchemeDefinition.cs | 23 -- .../Entity/ExternalProvider.cs | 19 +- ...congas.TheIdServer.Migrations.MySql.csproj | 66 ++-- ...20210420160524_UpdateClaimsKey.Designer.cs | 309 +++++++++++++++++ .../20210420160524_UpdateClaimsKey.cs | 24 ++ .../ApplicationDbContextModelSnapshot.cs | 4 +- ...20210420160524_UpdateClaimsKey.Designer.cs | 309 +++++++++++++++++ .../20210420160524_UpdateClaimsKey.cs | 36 ++ ...20210420160556_UpdateClaimsKey.Designer.cs | 311 +++++++++++++++++ .../20210420160556_UpdateClaimsKey.cs | 39 +++ .../ApplicationDbContextModelSnapshot.cs | 8 +- ...20210420160636_UpdateClaimsKey.Designer.cs | 313 ++++++++++++++++++ .../20210420160636_UpdateClaimsKey.cs | 37 +++ .../ApplicationDbContextModelSnapshot.cs | 8 +- ...20210420160617_UpdateClaimsKey.Designer.cs | 308 +++++++++++++++++ .../20210420160617_UpdateClaimsKey.cs | 37 +++ .../ApplicationDbContextModelSnapshot.cs | 8 +- ...tyServer.EntityFramework.Store.Test.csproj | 1 + .../CorsPolicyServiceTest.cs | 3 +- .../TheIdServerTestFixture.cs | 3 +- .../TheIdServerTestFixture.cs | 4 +- .../ApiFixture.cs | 3 +- .../BlazorApp/Pages/ExternalProviderTest.cs | 9 +- .../BlazorApp/Pages/ExternalProvidersTest.cs | 4 +- .../BlazorApp/Pages/RoleTest.cs | 2 + .../SchemeChangeSubscriberTest.cs | 2 +- .../TestUtils.cs | 6 +- .../ExternalClaimsTransformerTest.cs | 17 +- .../StartupTest.cs | 2 +- 49 files changed, 1955 insertions(+), 306 deletions(-) create mode 100644 src/IdentityServer/Aguacongas.IdentityServer.Admin/Filters/ExternalProviderFilter.cs delete mode 100644 src/IdentityServer/Aguacongas.IdentityServer.Admin/Filters/SelectFilter.cs delete mode 100644 src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/SchemeDefinition.cs create mode 100644 src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Migrations/20210420160524_UpdateClaimsKey.Designer.cs create mode 100644 src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Migrations/20210420160524_UpdateClaimsKey.cs create mode 100644 src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Oracle/Migrations/20210420160524_UpdateClaimsKey.Designer.cs create mode 100644 src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Oracle/Migrations/20210420160524_UpdateClaimsKey.cs create mode 100644 src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.PostgreSQL/Migrations/20210420160556_UpdateClaimsKey.Designer.cs create mode 100644 src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.PostgreSQL/Migrations/20210420160556_UpdateClaimsKey.cs create mode 100644 src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.SqlServer/Migrations/20210420160636_UpdateClaimsKey.Designer.cs create mode 100644 src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.SqlServer/Migrations/20210420160636_UpdateClaimsKey.cs create mode 100644 src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Sqlite/Migrations/20210420160617_UpdateClaimsKey.Designer.cs create mode 100644 src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Sqlite/Migrations/20210420160617_UpdateClaimsKey.cs diff --git a/src/Aguacongas.TheIdServer.Authentication/DynamicAuthenticationBuilderExtensions.cs b/src/Aguacongas.TheIdServer.Authentication/DynamicAuthenticationBuilderExtensions.cs index bf7b74d5b..ae26f5ba8 100644 --- a/src/Aguacongas.TheIdServer.Authentication/DynamicAuthenticationBuilderExtensions.cs +++ b/src/Aguacongas.TheIdServer.Authentication/DynamicAuthenticationBuilderExtensions.cs @@ -18,15 +18,27 @@ public static DynamicAuthenticationBuilder AddTheIdServerHttpStore(this DynamicA public static DynamicAuthenticationBuilder AddTheIdServerHttpStore(this DynamicAuthenticationBuilder builder, Func> getHttpClient = null) where TSchemeDefinition : SchemeDefinitionBase, new() { - var services = builder.Services; - services - .AddTransient, DynamicProviderStore>() - .AddTransient(); + builder.AddTheIdServerStore(); if (getHttpClient != null) { - services.AddIdentityServer4AdminHttpStores(getHttpClient); + builder.Services.AddIdentityServer4AdminHttpStores(getHttpClient); } return builder; } + + public static DynamicAuthenticationBuilder AddTheIdServerStore(this DynamicAuthenticationBuilder builder) + { + return builder.AddTheIdServerStore(); + } + + public static DynamicAuthenticationBuilder AddTheIdServerStore(this DynamicAuthenticationBuilder builder) + where TSchemeDefinition : SchemeDefinitionBase, new() + { + builder.Services + .AddTransient, DynamicProviderStore>() + .AddTransient(); + + return builder; + } } } diff --git a/src/Aguacongas.TheIdServer.Identity/UserOnlyStore.cs b/src/Aguacongas.TheIdServer.Identity/UserOnlyStore.cs index 9f33061bd..ebb01da79 100644 --- a/src/Aguacongas.TheIdServer.Identity/UserOnlyStore.cs +++ b/src/Aguacongas.TheIdServer.Identity/UserOnlyStore.cs @@ -307,10 +307,10 @@ public async override Task RemoveClaimsAsync(TUser user, IEnumerable clai AssertNotNull(claims, nameof(claims)); var userClaims = await GetUserClaimsAsync(user).ConfigureAwait(false); - var toRemove = userClaims.Where(c => claims.Any(cl => cl.Type == c.ClaimType && cl.Value == c.ClaimValue)); + var toRemove = userClaims.Items.Where(c => claims.Any(cl => cl.Type == c.ClaimType && cl.Value == c.ClaimValue)); foreach (var claim in toRemove) { - await _claimStore.DeleteAsync(claim.Id.ToString(), cancellationToken).ConfigureAwait(false); + await _claimStore.DeleteAsync(claim.Id, cancellationToken).ConfigureAwait(false); } } @@ -617,13 +617,12 @@ protected override async Task SaveUserTokensAsync(TUser user, IEnumerable>> GetUserClaimsAsync(TUser user) + protected virtual Task> GetUserClaimsAsync(TUser user) { - var response = await _claimStore.GetAsync(new PageRequest + return _claimStore.GetAsync(new PageRequest { Filter = $"{nameof(UserClaim.UserId)} eq '{user.Id}'" - }).ConfigureAwait(false); - return response.Items.Select(CreateIdentityUserClaim).ToList(); + }); } protected virtual async Task>> GetUserLoginsAsync(string userId) @@ -646,18 +645,6 @@ private IdentityUserToken IdentityUserToken(UserToken entity) }; } - private IdentityUserClaim CreateIdentityUserClaim(UserClaim entity) - { - return new IdentityUserClaim - { - UserId = entity.UserId, - ClaimType = entity.ClaimType, - ClaimValue = entity.ClaimValue, - - Id = int.Parse(entity.Id) - }; - } - private static IdentityUserLogin CreateIdentityUserLogin(UserLogin entity) { return new IdentityUserLogin diff --git a/src/Aguacongas.TheIdServer/Properties/launchSettings.json b/src/Aguacongas.TheIdServer/Properties/launchSettings.json index b726f2e18..71bd3014a 100644 --- a/src/Aguacongas.TheIdServer/Properties/launchSettings.json +++ b/src/Aguacongas.TheIdServer/Properties/launchSettings.json @@ -19,8 +19,7 @@ "commandName": "Project", "launchBrowser": true, "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development", - "LETSENCRYPT": "let's encrypt" + "ASPNETCORE_ENVIRONMENT": "Development" }, "applicationUrl": "https://localhost:5443;http://localhost:5000" }, diff --git a/src/Aguacongas.TheIdServer/Quickstart/Account/ExternalController.cs b/src/Aguacongas.TheIdServer/Quickstart/Account/ExternalController.cs index 873cdfb7f..6670f7aae 100644 --- a/src/Aguacongas.TheIdServer/Quickstart/Account/ExternalController.cs +++ b/src/Aguacongas.TheIdServer/Quickstart/Account/ExternalController.cs @@ -58,7 +58,10 @@ public ExternalController( [HttpGet] public async Task Challenge(string provider, string returnUrl) { - if (string.IsNullOrEmpty(returnUrl)) returnUrl = "~/"; + if (string.IsNullOrEmpty(returnUrl)) + { + returnUrl = "~/"; + } // validate returnUrl - either it is a valid OIDC URL or back to a local page if (!Url.IsLocalUrl(returnUrl) && !_interaction.IsValidReturnUrl(returnUrl)) diff --git a/src/Aguacongas.TheIdServer/SeedData.cs b/src/Aguacongas.TheIdServer/SeedData.cs index bb9f7e6e4..1f38d796f 100644 --- a/src/Aguacongas.TheIdServer/SeedData.cs +++ b/src/Aguacongas.TheIdServer/SeedData.cs @@ -22,8 +22,7 @@ namespace Aguacongas.TheIdServer static class SeedData { public static void EnsureSeedData(IConfiguration configuration) - { - + { var services = new ServiceCollection(); var startup = new Startup(configuration, null); startup.ConfigureServices(services); @@ -44,8 +43,11 @@ public static void EnsureSeedData(IConfiguration configuration) appcontext.Database.Migrate(); } - SeedUsers(scope, configuration); - SeedConfiguration(scope, configuration); + if (configuration.GetValue("Seed")) + { + SeedUsers(scope, configuration); + SeedConfiguration(scope, configuration); + } } public static void SeedConfiguration(IServiceScope scope, IConfiguration configuration) diff --git a/src/Aguacongas.TheIdServer/Startup.cs b/src/Aguacongas.TheIdServer/Startup.cs index c78060198..3f2ec56c3 100644 --- a/src/Aguacongas.TheIdServer/Startup.cs +++ b/src/Aguacongas.TheIdServer/Startup.cs @@ -158,26 +158,8 @@ void configureOptions(IdentityServerOptions options) settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); - if (isProxy) - { - mvcBuilder.AddIdentityServerAdmin() - .AddTheIdServerHttpStore(); - } - else if (DbType == DbTypes.RavenDb) - { - mvcBuilder.AddIdentityServerAdmin() - .AddRavenDbStore(); - } - else if (DbType == DbTypes.MongoDb) - { - mvcBuilder.AddIdentityServerAdmin() - .AddMongoDbStore(); - } - else - { - mvcBuilder.AddIdentityServerAdmin() - .AddEntityFrameworkStore(); - } + mvcBuilder.AddIdentityServerAdmin() + .AddTheIdServerStore(); services.AddRemoteAuthentication(); services.AddScoped() @@ -301,22 +283,17 @@ public void Configure(IApplicationBuilder app) endpoints.MapFallbackToPage("/_Host"); }); - LoadDynamicConfiguration(app, isProxy); + LoadDynamicConfiguration(app); } - private void LoadDynamicConfiguration(IApplicationBuilder app, bool isProxy) + private void LoadDynamicConfiguration(IApplicationBuilder app) { - if (isProxy || DbType == DbTypes.MongoDb) - { - app.LoadDynamicAuthenticationConfiguration(); - return; - } if (DbType == DbTypes.RavenDb) { app.LoadDynamicAuthenticationConfiguration(); return; } - app.LoadDynamicAuthenticationConfiguration(); + app.LoadDynamicAuthenticationConfiguration(); } private void AddForceHttpsSchemeMiddleware(IApplicationBuilder app) @@ -468,9 +445,9 @@ private void AddDefaultServices(IServiceCollection services) } else { - services.AddTransient>() + services.AddTransient>() .AddIdentityServer4AdminEntityFrameworkStores(options => options.UseDatabaseFromConfiguration(Configuration)) - .AddConfigurationEntityFrameworkStores(options => options.UseDatabaseFromConfiguration(Configuration)) + .AddConfigurationEntityFrameworkStores(options => options.UseDatabaseFromConfiguration(Configuration)) .AddOperationalEntityFrameworkStores(options => options.UseDatabaseFromConfiguration(Configuration)); identityBuilder.AddTheIdServerStores(); diff --git a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Components/AutoCompleteModel.cs b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Components/AutoCompleteModel.cs index 066a55170..c5e7af703 100644 --- a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Components/AutoCompleteModel.cs +++ b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Components/AutoCompleteModel.cs @@ -58,7 +58,7 @@ protected async Task SetSelectedValue(string value) protected override void OnParametersSet() { base.OnParametersSet(); - _fieldIdentifier = base.FieldIdentifier; + _fieldIdentifier = FieldIdentifier; } protected override void OnInitialized() diff --git a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Infrastructure/Abstraction/EntitiesModel.cs b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Infrastructure/Abstraction/EntitiesModel.cs index 56641e9cc..e3b5e3608 100644 --- a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Infrastructure/Abstraction/EntitiesModel.cs +++ b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Infrastructure/Abstraction/EntitiesModel.cs @@ -3,6 +3,7 @@ using Aguacongas.IdentityServer.Store; using Aguacongas.IdentityServer.Store.Entity; using Aguacongas.TheIdServer.BlazorApp.Infrastructure.Services; +using Aguacongas.TheIdServer.BlazorApp.Models; using Aguacongas.TheIdServer.BlazorApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Components; @@ -81,13 +82,7 @@ protected Task OnFilterChanged(string filter) return; } - var propertyArray = SelectProperties.Split(','); - var expressionArray = new string[propertyArray.Length]; - for (int i = 0; i < propertyArray.Length; i++) - { - expressionArray[i] = $"contains({propertyArray[i]},'{filter.Replace("'", "''")}')"; - } - _pageRequest.Filter = string.Join(" or ", expressionArray); + _pageRequest.Filter = CreateRequestFilter(filter); var page = await AdminStore.GetAsync(_pageRequest, token) .ConfigureAwait(false); @@ -99,6 +94,17 @@ await InvokeAsync(() => StateHasChanged()) }, TaskScheduler.Default); } + protected virtual string CreateRequestFilter(string filter) + { + var propertyArray = SelectProperties.Split(','); + var expressionArray = new string[propertyArray.Length]; + for (int i = 0; i < propertyArray.Length; i++) + { + expressionArray[i] = $"contains({propertyArray[i]},'{filter.Replace("'", "''")}')"; + } + return string.Join(" or ", expressionArray); + } + protected void OnItemSelected(string id, bool isSelected) { if (isSelected) @@ -136,7 +142,7 @@ private async Task GetEntityList(PageRequest pageRequest) EntityList = page.Items; } - private async Task GridState_OnHeaderClicked(Models.SortEventArgs e) + private async Task GridState_OnHeaderClicked(SortEventArgs e) { _pageRequest.OrderBy = e.OrderBy; await GetEntityList(_pageRequest) @@ -144,7 +150,6 @@ await GetEntityList(_pageRequest) StateHasChanged(); } - #region IDisposable Support private bool disposedValue = false; // To detect redundant calls diff --git a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Infrastructure/Models/ExternalProvider.cs b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Infrastructure/Models/ExternalProvider.cs index 1dfde834d..4e2dfc738 100644 --- a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Infrastructure/Models/ExternalProvider.cs +++ b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Infrastructure/Models/ExternalProvider.cs @@ -1,5 +1,6 @@ // Project: Aguafrommars/TheIdServer // Copyright (c) 2021 @Olivier Lefebvre +using Aguacongas.AspNetCore.Authentication; using Aguacongas.IdentityServer.Store; using System; using System.Collections.Generic; @@ -46,6 +47,11 @@ public ExternalProvider Clone() public static ExternalProvider FromEntity(Entity.ExternalProvider externalProvider) { + if (string.IsNullOrEmpty(externalProvider.KindName)) + { + var handlerTypeName = JsonSerializer.Deserialize(externalProvider.SerializedHandlerType); + externalProvider.KindName = handlerTypeName.Name.Split('.').Last().Replace("Handler", ""); + } var optionsType = GetOptionsType(externalProvider); return new ExternalProvider { @@ -65,10 +71,15 @@ private static TOptions Deserialize(string options, Type optionsType) } private static Type GetOptionsType(Entity.ExternalProvider externalProvider) - { + { var typeName = $"{typeof(RemoteAuthenticationOptions).Namespace}.{externalProvider.KindName}Options"; var assembly = AppDomain.CurrentDomain.GetAssemblies().First(a => a.GetType(typeName) != null); return assembly.GetType(typeName); } + + class HandlerType + { + public string Name { get; set; } + } } } diff --git a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.Client/Components/IdentityProvider.razor.cs b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.Client/Components/IdentityProvider.razor.cs index 71a9acbff..c64eaec2b 100644 --- a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.Client/Components/IdentityProvider.razor.cs +++ b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.Client/Components/IdentityProvider.razor.cs @@ -26,7 +26,7 @@ public partial class IdentityProvider protected override void OnParametersSet() { base.OnParametersSet(); - _isReadOnly = Entity.Provider != null; + _isReadOnly = Entity.Id != null; } protected override async Task OnInitializedAsync() diff --git a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.ExternalProviders/ExternalProviders.razor b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.ExternalProviders/ExternalProviders.razor index f1c3ca6b0..ed6d58221 100644 --- a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.ExternalProviders/ExternalProviders.razor +++ b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.ExternalProviders/ExternalProviders.razor @@ -22,7 +22,7 @@ GridState="GridState" /> - diff --git a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.ExternalProviders/ExternalProviders.razor.cs b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.ExternalProviders/ExternalProviders.razor.cs index 78ca4b54a..2763ff552 100644 --- a/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.ExternalProviders/ExternalProviders.razor.cs +++ b/src/BlazorApp/Aguacongas.TheIdServer.BlazorApp.Pages.ExternalProviders/ExternalProviders.razor.cs @@ -1,5 +1,6 @@ // Project: Aguafrommars/TheIdServer // Copyright (c) 2021 @Olivier Lefebvre +using Aguacongas.TheIdServer.BlazorApp.Models; using Entity = Aguacongas.IdentityServer.Store.Entity; namespace Aguacongas.TheIdServer.BlazorApp.Pages.ExternalProviders @@ -9,5 +10,10 @@ public partial class ExternalProviders protected override string SelectProperties => $"{nameof(Entity.ExternalProvider.Id)},{nameof(Entity.ExternalProvider.DisplayName)},{nameof(Entity.ExternalProvider.KindName)}"; protected override string ExportExpand => $"{nameof(Models.ExternalProvider.ClaimTransformations)}"; + + protected override string CreateRequestFilter(string filter) + { + return base.CreateRequestFilter(filter).Replace(nameof(Entity.ExternalProvider.KindName), nameof(Entity.ExternalProvider.SerializedHandlerType)); + } } } diff --git a/src/IdentityServer/Aguacongas.IdentityServer.Admin/Extensions/MvcBuilderExtensions.cs b/src/IdentityServer/Aguacongas.IdentityServer.Admin/Extensions/MvcBuilderExtensions.cs index f05758e4d..7582324b6 100644 --- a/src/IdentityServer/Aguacongas.IdentityServer.Admin/Extensions/MvcBuilderExtensions.cs +++ b/src/IdentityServer/Aguacongas.IdentityServer.Admin/Extensions/MvcBuilderExtensions.cs @@ -19,7 +19,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Localization; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -219,7 +218,7 @@ public static void AddIdentityServerAdminFilters(this MvcOptions options) { var filters = options.Filters; filters.Add(); - filters.Add(); + filters.Add(); filters.Add(); filters.Add(); diff --git a/src/IdentityServer/Aguacongas.IdentityServer.Admin/Filters/ExternalProviderFilter.cs b/src/IdentityServer/Aguacongas.IdentityServer.Admin/Filters/ExternalProviderFilter.cs new file mode 100644 index 000000000..d3acb7bfa --- /dev/null +++ b/src/IdentityServer/Aguacongas.IdentityServer.Admin/Filters/ExternalProviderFilter.cs @@ -0,0 +1,44 @@ +// Project: Aguafrommars/TheIdServer +// Copyright (c) 2021 @Olivier Lefebvre +using Aguacongas.AspNetCore.Authentication; +using Aguacongas.IdentityServer.Store; +using Aguacongas.IdentityServer.Store.Entity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Filters; +using System; +using System.Threading.Tasks; + +namespace Aguacongas.IdentityServer.Admin.Filters +{ + class ExternalProviderFilter : IAsyncResultFilter + { + private readonly IAuthenticationSchemeOptionsSerializer _serializer; + public ExternalProviderFilter(IAuthenticationSchemeOptionsSerializer serializer) + { + _serializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); + } + public Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) + { + var result = context.Result as ObjectResult; + var value = result?.Value; + if (value is PageResponse page) + { + foreach (var item in page.Items) + { + SetKindName(item); + } + } else if (value is ExternalProvider provider) + { + SetKindName(provider); + } + return next(); + } + + private void SetKindName(ExternalProvider provider) + { + var hanlderType = _serializer.DeserializeType(provider.SerializedHandlerType); + var optionsType = hanlderType.GetAuthenticationSchemeOptionsType(); + provider.KindName = optionsType.Name.Replace("Options", ""); + } + } +} diff --git a/src/IdentityServer/Aguacongas.IdentityServer.Admin/Filters/SelectFilter.cs b/src/IdentityServer/Aguacongas.IdentityServer.Admin/Filters/SelectFilter.cs deleted file mode 100644 index 16aaeabc4..000000000 --- a/src/IdentityServer/Aguacongas.IdentityServer.Admin/Filters/SelectFilter.cs +++ /dev/null @@ -1,116 +0,0 @@ -// Project: Aguafrommars/TheIdServer -// Copyright (c) 2021 @Olivier Lefebvre -using Aguacongas.IdentityServer.Store; -using Aguacongas.IdentityServer.Store.Entity; -using Community.OData.Linq; -using Community.OData.Linq.Json; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.OData.Edm; -using Newtonsoft.Json.Linq; -using Newtonsoft.Json.Serialization; -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Threading.Tasks; - -namespace Aguacongas.IdentityServer.Admin.Filters -{ - class SelectFilter : IAsyncResultFilter - { - public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) - { - var controlerType = context.Controller.GetType(); - var result = context.Result as ObjectResult; - var value = result?.Value; - var query = context.HttpContext.Request.Query; - if (!context.Cancel && - value != null && - query.ContainsKey("select") && - controlerType.FullName - .StartsWith("Aguacongas.IdentityServer.Admin.GenericApiController", - StringComparison.Ordinal)) - { - var valueType = value.GetType(); - var entityType = controlerType.GetGenericArguments()[0]; - var pageResponseType = typeof(PageResponse<>).MakeGenericType(entityType); - if (pageResponseType == valueType) - { - var items = pageResponseType.GetProperty("Items").GetValue(value); - var selectResultType = typeof(SelectResult<>).MakeGenericType(entityType); - var selectResult = selectResultType.GetConstructors()[0] - .Invoke(Array.Empty()) as SelectResult; - var pageResponse = new SelectedPageResponse - { - Items = selectResult.Select(items, query["select"], query["expand"]), - Count = (int)pageResponseType.GetProperty("Count").GetValue(value) - }; - result.Value = pageResponse; - } - } - - await next().ConfigureAwait(false); - } - - class SelectResult: SelectResult - { - [SuppressMessage("Major Code Smell", "S2743:Static fields should not be used in generic types", Justification = "Won't fix")] - private readonly static CamelCasePropertyNamesContractResolver _resolver = new(); - public override JToken Select(object items, string select, string expand) - { - return Select(items as IEnumerable, select, expand); - } - - private static JToken Select(IEnumerable items, string select, string expand) - { - if (typeof(T) == typeof(ExternalProvider)) - { - var list = ((IEnumerable)items).Select(e => new WrapProvider(e)); - return list.AsQueryable().OData(edmModel: WrapProvider.GetEdmModel()).SelectExpand(select, expand).ToJson(options => options.ContractResolver = _resolver); - } - return items.AsQueryable().OData().SelectExpand(select, expand).ToJson(options => options.ContractResolver = _resolver); - } - } - - abstract class SelectResult - { - public abstract JToken Select(object items, string select, string expand); - } - - class SelectedPageResponse - { - public int Count { get; set; } - - public JToken Items { get; set; } - } - - class WrapProvider - { - private static IEdmModel _edmModel; - public static IEdmModel GetEdmModel() - { - if (_edmModel != null) - { - return _edmModel; - } - var builder = new ODataConventionModelBuilder(); - var entitySet = builder.EntitySet(typeof(WrapProvider).Name); - var entityType = entitySet.EntityType; - entityType.HasKey(e => e.Id); - _edmModel = builder.GetEdmModel(); - return _edmModel; - } - public WrapProvider(ExternalProvider provider) - { - Id = provider.Id; - DisplayName = provider.DisplayName; - KindName = provider.KindName; - } - - public string Id { get; set; } - public string DisplayName { get; set; } - public string KindName { get; set; } - } - } -} diff --git a/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/AdminStore.cs b/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/AdminStore.cs index 7d2eda6b4..c66157424 100644 --- a/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/AdminStore.cs +++ b/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/AdminStore.cs @@ -72,6 +72,10 @@ public async Task CreateAsync(TEntity entity, CancellationToken cancell { entity.Id = Guid.NewGuid().ToString(); } + if (entity is IAuditable auditable) + { + auditable.CreatedAt = DateTime.UtcNow; + } await _context.AddAsync(entity, cancellationToken).ConfigureAwait(false); await _context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); _logger.LogInformation("Entity {EntityId} created", entity.Id, entity); diff --git a/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/Aguacongas.IdentityServer.EntityFramework.Store.csproj b/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/Aguacongas.IdentityServer.EntityFramework.Store.csproj index 3f4e542fe..bd8066ef7 100644 --- a/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/Aguacongas.IdentityServer.EntityFramework.Store.csproj +++ b/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/Aguacongas.IdentityServer.EntityFramework.Store.csproj @@ -26,7 +26,6 @@ - diff --git a/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/ApplicationDbContext.cs b/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/ApplicationDbContext.cs index 29b0dccba..91b65950b 100644 --- a/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/ApplicationDbContext.cs +++ b/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/ApplicationDbContext.cs @@ -63,17 +63,13 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .IsUnique(); modelBuilder.Entity().Property(r => r.NormalizedName).HasMaxLength(256); modelBuilder.Entity().Property(r => r.Name).HasMaxLength(256); - - modelBuilder.Entity().Property(c => c.Id).HasConversion(); - + modelBuilder.Entity().HasKey(l => new { l.LoginProvider, l.ProviderKey }); modelBuilder.Entity().HasKey(r => new { r.RoleId, r.UserId }); modelBuilder.Entity().HasKey(t => new { t.UserId, t.LoginProvider, t.Name }); - modelBuilder.Entity().Property(c => c.Id).HasConversion(); - base.OnModelCreating(modelBuilder); } diff --git a/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/ConfigurationDbContext.cs b/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/ConfigurationDbContext.cs index 3ec488d39..647d13cb7 100644 --- a/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/ConfigurationDbContext.cs +++ b/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/ConfigurationDbContext.cs @@ -1,7 +1,9 @@ // Project: Aguafrommars/TheIdServer // Copyright (c) 2021 @Olivier Lefebvre +using Aguacongas.AspNetCore.Authentication; using Aguacongas.IdentityServer.Store.Entity; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking; using System; using System.Diagnostics.CodeAnalysis; using System.Threading; @@ -53,7 +55,7 @@ public ConfigurationDbContext(DbContextOptions options): public virtual DbSet IdentityProperties { get; set; } - public virtual DbSet Providers { get; set; } + public virtual DbSet Providers { get; set; } public virtual DbSet ExternalClaimTransformations { get; set; } @@ -107,7 +109,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasIndex(e => new { e.IdentityId, e.Type }) .IsUnique(true); modelBuilder.Entity() - .HasOne() + .HasOne() .WithMany(e => e.ClaimTransformations) .HasForeignKey(e => e.Scheme); modelBuilder.Entity() @@ -138,15 +140,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .IsRequired(true) .OnDelete(DeleteBehavior.Cascade); - modelBuilder.Entity(b => - { - b.Ignore(p => p.Id) - .Ignore(p => p.Options) - .Ignore(p => p.HandlerType) - .HasKey(p => p.Scheme); - b.Property(p => p.ConcurrencyStamp).IsConcurrencyToken(); - }); - var defaultCulture = new Culture { Id = "en", @@ -154,6 +147,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) }; modelBuilder.Entity().HasData(defaultCulture); + modelBuilder.Entity().Property(e => e.Id).HasColumnName(nameof(SchemeDefinitionBase.Scheme)); + modelBuilder.Entity().Ignore(e => e.KindName); + base.OnModelCreating(modelBuilder); } diff --git a/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/Extensions/ServiceCollectionExtensions.cs b/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/Extensions/ServiceCollectionExtensions.cs index 2cd347c5f..9fef8da34 100644 --- a/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/Extensions/ServiceCollectionExtensions.cs +++ b/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/Extensions/ServiceCollectionExtensions.cs @@ -1,5 +1,6 @@ // Project: Aguafrommars/TheIdServer // Copyright (c) 2021 @Olivier Lefebvre +using Aguacongas.AspNetCore.Authentication; using Aguacongas.IdentityServer.EntityFramework.Store; using Aguacongas.IdentityServer.Store; using Aguacongas.IdentityServer.Store.Entity; @@ -27,11 +28,12 @@ public static IServiceCollection AddIdentityServer4AdminEntityFrameworkStores(th return services.AddDbContext(optionsAction); } - public static IServiceCollection AddConfigurationEntityFrameworkStores(this IServiceCollection services, Action optionsAction = null) + public static IServiceCollection AddConfigurationEntityFrameworkStores(this IServiceCollection services, Action optionsAction = null) + where TSchemeDefinition: SchemeDefinitionBase, new() { AddStoresForContext(services, typeof(ConfigurationDbContext)); return services.AddDbContext(optionsAction) - .AddConfigurationStores(); + .AddConfigurationStores(); } public static IServiceCollection AddOperationalEntityFrameworkStores(this IServiceCollection services, Action optionsAction = null) diff --git a/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/SchemeDefinition.cs b/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/SchemeDefinition.cs deleted file mode 100644 index 4cd0be1f4..000000000 --- a/src/IdentityServer/Aguacongas.IdentityServer.EntityFramework.Store/SchemeDefinition.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Project: Aguafrommars/TheIdServer -// Copyright (c) 2021 @Olivier Lefebvre -using Aguacongas.IdentityServer.Store.Entity; -using System; -using System.Collections.Generic; -using Auth = Aguacongas.AspNetCore.Authentication.EntityFramework; - -namespace Aguacongas.IdentityServer.EntityFramework.Store -{ - public class SchemeDefinition : Auth.SchemeDefinition, IAuditable - { - public string Id { get => Scheme; set => Scheme = value; } - - public bool StoreClaims { get; set; } - - public bool MapDefaultOutboundClaimType { get; set; } - - public virtual ICollection ClaimTransformations { get; set; } - - public DateTime CreatedAt { get; set; } - public DateTime? ModifiedAt { get; set; } - } -} diff --git a/src/IdentityServer/Aguacongas.IdentityServer.Store/Entity/ExternalProvider.cs b/src/IdentityServer/Aguacongas.IdentityServer.Store/Entity/ExternalProvider.cs index 511449bff..a7de02639 100644 --- a/src/IdentityServer/Aguacongas.IdentityServer.Store/Entity/ExternalProvider.cs +++ b/src/IdentityServer/Aguacongas.IdentityServer.Store/Entity/ExternalProvider.cs @@ -1,5 +1,6 @@ // Project: Aguafrommars/TheIdServer // Copyright (c) 2021 @Olivier Lefebvre +using System; using System.Collections.Generic; namespace Aguacongas.IdentityServer.Store.Entity @@ -8,7 +9,7 @@ namespace Aguacongas.IdentityServer.Store.Entity /// SchemeDefinition entity /// /// - public class ExternalProvider : IEntityId + public class ExternalProvider : IAuditable { /// /// Gets the identifier. @@ -73,5 +74,21 @@ public class ExternalProvider : IEntityId /// The claim transformations. /// public virtual ICollection ClaimTransformations { get; set; } + + /// + /// Gets or sets the created at. + /// + /// + /// The created at. + /// + public DateTime CreatedAt { get; set; } + + /// + /// Gets or sets the modified at. + /// + /// + /// The modified at. + /// + public DateTime? ModifiedAt { get; set; } } } diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Aguacongas.TheIdServer.Migrations.MySql.csproj b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Aguacongas.TheIdServer.Migrations.MySql.csproj index 699c79369..7b8b86eac 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Aguacongas.TheIdServer.Migrations.MySql.csproj +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Aguacongas.TheIdServer.Migrations.MySql.csproj @@ -1,41 +1,41 @@  - - net5.0 - Aguacongas.TheIdServer.MySql - Olivier Lefebvre - Copyright (c) 2020 @Olivier Lefebvre - https://raw.githubusercontent.com/Aguafrommars/TheIdServer/master/LICENSE - https://github.com/Aguafrommars/TheIdServer/tree/master/src/Aguacongas.TheIdServer - https://github.com/Aguafrommars/TheIdServer - git - theidserver;mysql - Contains db contexts migrations code for MySql. - package-icon.png - ..\..\..\..\.sonarlint\aguacongas_theidservercsharp.ruleset - + + net5.0 + Aguacongas.TheIdServer.MySql + Olivier Lefebvre + Copyright (c) 2020 @Olivier Lefebvre + https://raw.githubusercontent.com/Aguafrommars/TheIdServer/master/LICENSE + https://github.com/Aguafrommars/TheIdServer/tree/master/src/Aguacongas.TheIdServer + https://github.com/Aguafrommars/TheIdServer + git + theidserver;mysql + Contains db contexts migrations code for MySql. + package-icon.png + ..\..\..\..\.sonarlint\aguacongas_theidservercsharp.ruleset + - - - + + + - - - - PreserveNewest - - + + + + PreserveNewest + + - - - - - - - - - + + + + + + + + + - + diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Migrations/20210420160524_UpdateClaimsKey.Designer.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Migrations/20210420160524_UpdateClaimsKey.Designer.cs new file mode 100644 index 000000000..d86e30efa --- /dev/null +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Migrations/20210420160524_UpdateClaimsKey.Designer.cs @@ -0,0 +1,309 @@ +// Project: Aguafrommars/TheIdServer +// Copyright (c) 2021 @Olivier Lefebvre +using System; +using Aguacongas.TheIdServer.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Aguacongas.TheIdServer.MySql.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210420160524_UpdateClaimsKey")] + partial class UpdateClaimsKey + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 64) + .HasAnnotation("ProductVersion", "5.0.5"); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.Role", b => + { + b.Property("Id") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("ConcurrencyStamp") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("varchar(256) CHARACTER SET utf8mb4"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("varchar(256) CHARACTER SET utf8mb4"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => + { + b.Property("Id") + .HasColumnType("int"); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("varchar(250) CHARACTER SET utf8mb4"); + + b.Property("ClaimValue") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.User", b => + { + b.Property("Id") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("varchar(256) CHARACTER SET utf8mb4"); + + b.Property("EmailConfirmed") + .HasColumnType("tinyint(1)"); + + b.Property("LockoutEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("LockoutEnd") + .HasColumnType("datetime(6)"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("varchar(256) CHARACTER SET utf8mb4"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("varchar(256) CHARACTER SET utf8mb4"); + + b.Property("PasswordHash") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("PhoneNumber") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("tinyint(1)"); + + b.Property("SecurityStamp") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("TwoFactorEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256) CHARACTER SET utf8mb4"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => + { + b.Property("Id") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("varchar(250) CHARACTER SET utf8mb4"); + + b.Property("ClaimValue") + .IsRequired() + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Issuer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("OriginalType") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("ProviderKey") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("Id") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("ProviderDisplayName") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserRole", b => + { + b.Property("RoleId") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("UserId") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("Id") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("RoleId", "UserId"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserToken", b => + { + b.Property("UserId") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("LoginProvider") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("Name") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("Id") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Value") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.Role", "Role") + .WithMany("RoleClaims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany("UserClaims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserLogin", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserRole", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany("UserRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserToken", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.Role", b => + { + b.Navigation("RoleClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.User", b => + { + b.Navigation("UserClaims"); + + b.Navigation("UserRoles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Migrations/20210420160524_UpdateClaimsKey.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Migrations/20210420160524_UpdateClaimsKey.cs new file mode 100644 index 000000000..20f638356 --- /dev/null +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Migrations/20210420160524_UpdateClaimsKey.cs @@ -0,0 +1,24 @@ +// Project: Aguafrommars/TheIdServer +// Copyright (c) 2021 @Olivier Lefebvre +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Aguacongas.TheIdServer.MySql.Migrations +{ + public partial class UpdateClaimsKey : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn("Id", "AspNetUserClaims", type: "varchar(255) CHARACTER SET utf8mb4", defaultValueSql: "(uuid())"); + migrationBuilder.AlterColumn("Id", "AspNetRoleClaims", type: "varchar(255) CHARACTER SET utf8mb4", defaultValueSql: "(uuid())"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn("Id", "AspNetUserClaims", type: "int") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + migrationBuilder.AlterColumn("Id", "AspNetRoleClaims", type: "int") + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn); + } + } +} diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Migrations/ApplicationDbContextModelSnapshot.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Migrations/ApplicationDbContextModelSnapshot.cs index d23ca1be0..a35c3d4ba 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.MySql/Migrations/ApplicationDbContextModelSnapshot.cs @@ -132,8 +132,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => { - b.Property("Id") - .HasColumnType("int"); + b.Property("Id") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); b.Property("ClaimType") .IsRequired() diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Oracle/Migrations/20210420160524_UpdateClaimsKey.Designer.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Oracle/Migrations/20210420160524_UpdateClaimsKey.Designer.cs new file mode 100644 index 000000000..8da055721 --- /dev/null +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Oracle/Migrations/20210420160524_UpdateClaimsKey.Designer.cs @@ -0,0 +1,309 @@ +// Project: Aguafrommars/TheIdServer +// Copyright (c) 2021 @Olivier Lefebvre +using System; +using Aguacongas.TheIdServer.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Aguacongas.TheIdServer.Oracle.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210420160524_UpdateClaimsKey")] + partial class UpdateClaimsKey + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 64) + .HasAnnotation("ProductVersion", "5.0.5"); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.Role", b => + { + b.Property("Id") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("ConcurrencyStamp") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("varchar(256) CHARACTER SET utf8mb4"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("varchar(256) CHARACTER SET utf8mb4"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => + { + b.Property("Id") + .HasColumnType("int"); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("varchar(250) CHARACTER SET utf8mb4"); + + b.Property("ClaimValue") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.User", b => + { + b.Property("Id") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("varchar(256) CHARACTER SET utf8mb4"); + + b.Property("EmailConfirmed") + .HasColumnType("tinyint(1)"); + + b.Property("LockoutEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("LockoutEnd") + .HasColumnType("datetime(6)"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("varchar(256) CHARACTER SET utf8mb4"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("varchar(256) CHARACTER SET utf8mb4"); + + b.Property("PasswordHash") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("PhoneNumber") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("tinyint(1)"); + + b.Property("SecurityStamp") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("TwoFactorEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256) CHARACTER SET utf8mb4"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => + { + b.Property("Id") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("varchar(250) CHARACTER SET utf8mb4"); + + b.Property("ClaimValue") + .IsRequired() + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Issuer") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("OriginalType") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("ProviderKey") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("Id") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("ProviderDisplayName") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserRole", b => + { + b.Property("RoleId") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("UserId") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("Id") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("RoleId", "UserId"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserToken", b => + { + b.Property("UserId") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("LoginProvider") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("Name") + .HasColumnType("varchar(255) CHARACTER SET utf8mb4"); + + b.Property("Id") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Value") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.Role", "Role") + .WithMany("RoleClaims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany("UserClaims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserLogin", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserRole", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany("UserRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserToken", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.Role", b => + { + b.Navigation("RoleClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.User", b => + { + b.Navigation("UserClaims"); + + b.Navigation("UserRoles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Oracle/Migrations/20210420160524_UpdateClaimsKey.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Oracle/Migrations/20210420160524_UpdateClaimsKey.cs new file mode 100644 index 000000000..8c8dd36a3 --- /dev/null +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Oracle/Migrations/20210420160524_UpdateClaimsKey.cs @@ -0,0 +1,36 @@ +// Project: Aguafrommars/TheIdServer +// Copyright (c) 2021 @Olivier Lefebvre +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Aguacongas.TheIdServer.Oracle.Migrations +{ + public partial class UpdateClaimsKey : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims"); + migrationBuilder.DropColumn("Id", "AspNetUserClaims"); + migrationBuilder.AddColumn("Id", "AspNetUserClaims", type: "STRING AS UUID GENERATED BY DEFAULT"); + migrationBuilder.AddPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims", "Id"); + + migrationBuilder.DropPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims"); + migrationBuilder.DropColumn("Id", "AspNetRoleClaims"); + migrationBuilder.AddColumn("Id", "AspNetRoleClaims", type: "STRING AS UUID GENERATED BY DEFAULT"); + migrationBuilder.AddPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims", "Id"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims"); + migrationBuilder.DropColumn("Id", "AspNetUserClaims"); + migrationBuilder.AddColumn("Id", "AspNetUserClaims", type: "NUMBER GENERATED BY DEFAULT AS IDENTITY"); + migrationBuilder.AddPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims", "Id"); + + migrationBuilder.DropPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims"); + migrationBuilder.DropColumn("Id", "AspNetRoleClaims"); + migrationBuilder.AddColumn("Id", "AspNetRoleClaims", type: "NUMBER GENERATED BY DEFAULT AS IDENTITY"); + migrationBuilder.AddPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims", "Id"); + } + } +} diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.PostgreSQL/Migrations/20210420160556_UpdateClaimsKey.Designer.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.PostgreSQL/Migrations/20210420160556_UpdateClaimsKey.Designer.cs new file mode 100644 index 000000000..45a24df21 --- /dev/null +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.PostgreSQL/Migrations/20210420160556_UpdateClaimsKey.Designer.cs @@ -0,0 +1,311 @@ +// Project: Aguafrommars/TheIdServer +// Copyright (c) 2021 @Olivier Lefebvre +using System; +using Aguacongas.TheIdServer.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace Aguacongas.TheIdServer.PostgreSQL.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210420160556_UpdateClaimsKey")] + partial class UpdateClaimsKey + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.5") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.Role", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.User", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp without time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("ClaimValue") + .IsRequired() + .HasColumnType("text"); + + b.Property("Issuer") + .HasColumnType("text"); + + b.Property("OriginalType") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("Id") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserRole", b => + { + b.Property("RoleId") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("text"); + + b.Property("Id") + .HasColumnType("text"); + + b.HasKey("RoleId", "UserId"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Id") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.Role", "Role") + .WithMany("RoleClaims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany("UserClaims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserLogin", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserRole", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany("UserRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserToken", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.Role", b => + { + b.Navigation("RoleClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.User", b => + { + b.Navigation("UserClaims"); + + b.Navigation("UserRoles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.PostgreSQL/Migrations/20210420160556_UpdateClaimsKey.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.PostgreSQL/Migrations/20210420160556_UpdateClaimsKey.cs new file mode 100644 index 000000000..592478228 --- /dev/null +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.PostgreSQL/Migrations/20210420160556_UpdateClaimsKey.cs @@ -0,0 +1,39 @@ +// Project: Aguafrommars/TheIdServer +// Copyright (c) 2021 @Olivier Lefebvre +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace Aguacongas.TheIdServer.PostgreSQL.Migrations +{ + public partial class UpdateClaimsKey : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"); + migrationBuilder.DropPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims"); + migrationBuilder.DropColumn("Id", "AspNetUserClaims"); + migrationBuilder.AddColumn("Id", "AspNetUserClaims", type: "text", defaultValueSql: "uuid_generate_v4()"); + migrationBuilder.AddPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims", "Id"); + + migrationBuilder.DropPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims"); + migrationBuilder.DropColumn("Id", "AspNetRoleClaims"); + migrationBuilder.AddColumn("Id", "AspNetRoleClaims", type: "text", defaultValueSql: "uuid_generate_v4()"); + migrationBuilder.AddPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims", "Id"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims"); + migrationBuilder.DropColumn("Id", "AspNetUserClaims"); + migrationBuilder.AddColumn("Id", "AspNetUserClaims", type: "int") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + migrationBuilder.AddPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims", "Id"); + + migrationBuilder.DropPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims"); + migrationBuilder.DropColumn("Id", "AspNetRoleClaims"); + migrationBuilder.AddColumn("Id", "AspNetRoleClaims", type: "int") + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + migrationBuilder.AddPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims", "Id"); + } + } +} diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.PostgreSQL/Migrations/ApplicationDbContextModelSnapshot.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.PostgreSQL/Migrations/ApplicationDbContextModelSnapshot.cs index c8897f2fb..eb561fa8f 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.PostgreSQL/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.PostgreSQL/Migrations/ApplicationDbContextModelSnapshot.cs @@ -46,8 +46,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => { - b.Property("Id") - .HasColumnType("integer"); + b.Property("Id") + .HasColumnType("text"); b.Property("ClaimType") .IsRequired() @@ -134,8 +134,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => { - b.Property("Id") - .HasColumnType("integer"); + b.Property("Id") + .HasColumnType("text"); b.Property("ClaimType") .IsRequired() diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.SqlServer/Migrations/20210420160636_UpdateClaimsKey.Designer.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.SqlServer/Migrations/20210420160636_UpdateClaimsKey.Designer.cs new file mode 100644 index 000000000..04cbac99c --- /dev/null +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.SqlServer/Migrations/20210420160636_UpdateClaimsKey.Designer.cs @@ -0,0 +1,313 @@ +// Project: Aguafrommars/TheIdServer +// Copyright (c) 2021 @Olivier Lefebvre +using System; +using Aguacongas.TheIdServer.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Aguacongas.TheIdServer.SqlServer.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210420160636_UpdateClaimsKey")] + partial class UpdateClaimsKey + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.5") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.Role", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ConcurrencyStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex") + .HasFilter("[NormalizedName] IS NOT NULL"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.User", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetime2"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex") + .HasFilter("[NormalizedUserName] IS NOT NULL"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => + { + b.Property("Id") + .HasColumnType("nvarchar(450)"); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("nvarchar(250)"); + + b.Property("ClaimValue") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Issuer") + .HasColumnType("nvarchar(max)"); + + b.Property("OriginalType") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(450)"); + + b.Property("Id") + .HasColumnType("nvarchar(max)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserRole", b => + { + b.Property("RoleId") + .HasColumnType("nvarchar(450)"); + + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("Id") + .HasColumnType("nvarchar(max)"); + + b.HasKey("RoleId", "UserId"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserToken", b => + { + b.Property("UserId") + .HasColumnType("nvarchar(450)"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(450)"); + + b.Property("Name") + .HasColumnType("nvarchar(450)"); + + b.Property("Id") + .HasColumnType("nvarchar(max)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.Role", "Role") + .WithMany("RoleClaims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany("UserClaims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserLogin", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserRole", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany("UserRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserToken", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.Role", b => + { + b.Navigation("RoleClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.User", b => + { + b.Navigation("UserClaims"); + + b.Navigation("UserRoles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.SqlServer/Migrations/20210420160636_UpdateClaimsKey.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.SqlServer/Migrations/20210420160636_UpdateClaimsKey.cs new file mode 100644 index 000000000..8bcc9121e --- /dev/null +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.SqlServer/Migrations/20210420160636_UpdateClaimsKey.cs @@ -0,0 +1,37 @@ +// Project: Aguafrommars/TheIdServer +// Copyright (c) 2021 @Olivier Lefebvre +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Aguacongas.TheIdServer.SqlServer.Migrations +{ + public partial class UpdateClaimsKey : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims"); + migrationBuilder.DropColumn("Id", "AspNetUserClaims"); + migrationBuilder.AddColumn("Id", "AspNetUserClaims", type: "nvarchar(450)", defaultValueSql: "newid()"); + migrationBuilder.AddPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims", "Id"); + + migrationBuilder.DropPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims"); + migrationBuilder.DropColumn("Id", "AspNetRoleClaims"); + migrationBuilder.AddColumn("Id", "AspNetRoleClaims", type: "nvarchar(450)", defaultValueSql: "newid()"); + migrationBuilder.AddPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims", "Id"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims"); + migrationBuilder.DropColumn("Id", "AspNetUserClaims"); + migrationBuilder.AddColumn("Id", "AspNetUserClaims", type: "int") + .Annotation("SqlServer:Identity", "1, 1"); + migrationBuilder.AddPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims", "Id"); + + migrationBuilder.DropPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims"); + migrationBuilder.DropColumn("Id", "AspNetRoleClaims"); + migrationBuilder.AddColumn("Id", "AspNetRoleClaims", type: "int") + .Annotation("SqlServer:Identity", "1, 1"); + migrationBuilder.AddPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims", "Id"); + } + } +} diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.SqlServer/Migrations/ApplicationDbContextModelSnapshot.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.SqlServer/Migrations/ApplicationDbContextModelSnapshot.cs index 4da64e0c9..48ff8a355 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.SqlServer/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.SqlServer/Migrations/ApplicationDbContextModelSnapshot.cs @@ -47,8 +47,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => { - b.Property("Id") - .HasColumnType("int"); + b.Property("Id") + .HasColumnType("nvarchar(450)"); b.Property("ClaimType") .IsRequired() @@ -136,8 +136,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => { - b.Property("Id") - .HasColumnType("int"); + b.Property("Id") + .HasColumnType("nvarchar(450)"); b.Property("ClaimType") .IsRequired() diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Sqlite/Migrations/20210420160617_UpdateClaimsKey.Designer.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Sqlite/Migrations/20210420160617_UpdateClaimsKey.Designer.cs new file mode 100644 index 000000000..1797574f0 --- /dev/null +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Sqlite/Migrations/20210420160617_UpdateClaimsKey.Designer.cs @@ -0,0 +1,308 @@ +// Project: Aguafrommars/TheIdServer +// Copyright (c) 2021 @Olivier Lefebvre +using System; +using Aguacongas.TheIdServer.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Aguacongas.TheIdServer.Sqlite.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210420160617_UpdateClaimsKey")] + partial class UpdateClaimsKey + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "5.0.5"); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.Role", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ConcurrencyStamp") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("TEXT"); + + b.Property("ClaimValue") + .HasColumnType("TEXT"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.User", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("AccessFailedCount") + .HasColumnType("INTEGER"); + + b.Property("ConcurrencyStamp") + .HasColumnType("TEXT"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("EmailConfirmed") + .HasColumnType("INTEGER"); + + b.Property("LockoutEnabled") + .HasColumnType("INTEGER"); + + b.Property("LockoutEnd") + .HasColumnType("TEXT"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("PasswordHash") + .HasColumnType("TEXT"); + + b.Property("PhoneNumber") + .HasColumnType("TEXT"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("INTEGER"); + + b.Property("SecurityStamp") + .HasColumnType("TEXT"); + + b.Property("TwoFactorEnabled") + .HasColumnType("INTEGER"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ClaimType") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("TEXT"); + + b.Property("ClaimValue") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Issuer") + .HasColumnType("TEXT"); + + b.Property("OriginalType") + .HasColumnType("TEXT"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("TEXT"); + + b.Property("ProviderKey") + .HasColumnType("TEXT"); + + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ProviderDisplayName") + .HasColumnType("TEXT"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserRole", b => + { + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("Id") + .HasColumnType("TEXT"); + + b.HasKey("RoleId", "UserId"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserToken", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("LoginProvider") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("TEXT"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.Role", "Role") + .WithMany("RoleClaims") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany("UserClaims") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserLogin", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserRole", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.Role", "Role") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany("UserRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserToken", b => + { + b.HasOne("Aguacongas.IdentityServer.Store.Entity.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.Role", b => + { + b.Navigation("RoleClaims"); + }); + + modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.User", b => + { + b.Navigation("UserClaims"); + + b.Navigation("UserRoles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Sqlite/Migrations/20210420160617_UpdateClaimsKey.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Sqlite/Migrations/20210420160617_UpdateClaimsKey.cs new file mode 100644 index 000000000..1fbe8a91b --- /dev/null +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Sqlite/Migrations/20210420160617_UpdateClaimsKey.cs @@ -0,0 +1,37 @@ +// Project: Aguafrommars/TheIdServer +// Copyright (c) 2021 @Olivier Lefebvre +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Aguacongas.TheIdServer.Sqlite.Migrations +{ + public partial class UpdateClaimsKey : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims"); + migrationBuilder.DropColumn("Id", "AspNetUserClaims"); + migrationBuilder.AddColumn("Id", "AspNetUserClaims", type: "TEXT", defaultValueSql: "hex(randomblob(16))"); + migrationBuilder.AddPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims", "Id"); + + migrationBuilder.DropPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims"); + migrationBuilder.DropColumn("Id", "AspNetRoleClaims"); + migrationBuilder.AddColumn("Id", "AspNetRoleClaims", type: "TEXT", defaultValueSql: "hex(randomblob(16))"); + migrationBuilder.AddPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims", "Id"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims"); + migrationBuilder.DropColumn("Id", "AspNetUserClaims"); + migrationBuilder.AddColumn("Id", "AspNetUserClaims", type: "int") + .Annotation("Sqlite:Autoincrement", true); + migrationBuilder.AddPrimaryKey("PK_AspNetUserClaims", "AspNetUserClaims", "Id"); + + migrationBuilder.DropPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims"); + migrationBuilder.DropColumn("Id", "AspNetRoleClaims"); + migrationBuilder.AddColumn("Id", "AspNetRoleClaims", type: "int") + .Annotation("Sqlite:Autoincrement", true); + migrationBuilder.AddPrimaryKey("PK_AspNetRoleClaims", "AspNetRoleClaims", "Id"); + } + } +} diff --git a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Sqlite/Migrations/ApplicationDbContextModelSnapshot.cs b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Sqlite/Migrations/ApplicationDbContextModelSnapshot.cs index 11509042a..ceafb404d 100644 --- a/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Sqlite/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/IdentityServer/Migrations/Aguacongas.TheIdServer.Migrations.Sqlite/Migrations/ApplicationDbContextModelSnapshot.cs @@ -43,8 +43,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.RoleClaim", b => { - b.Property("Id") - .HasColumnType("INTEGER"); + b.Property("Id") + .HasColumnType("TEXT"); b.Property("ClaimType") .IsRequired() @@ -131,8 +131,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("Aguacongas.IdentityServer.Store.Entity.UserClaim", b => { - b.Property("Id") - .HasColumnType("INTEGER"); + b.Property("Id") + .HasColumnType("TEXT"); b.Property("ClaimType") .IsRequired() diff --git a/test/Aguacongas.IdentityServer.EntityFramework.Store.Test/Aguacongas.IdentityServer.EntityFramework.Store.Test.csproj b/test/Aguacongas.IdentityServer.EntityFramework.Store.Test/Aguacongas.IdentityServer.EntityFramework.Store.Test.csproj index d73da8fea..d3bb6d510 100644 --- a/test/Aguacongas.IdentityServer.EntityFramework.Store.Test/Aguacongas.IdentityServer.EntityFramework.Store.Test.csproj +++ b/test/Aguacongas.IdentityServer.EntityFramework.Store.Test/Aguacongas.IdentityServer.EntityFramework.Store.Test.csproj @@ -21,6 +21,7 @@ + diff --git a/test/Aguacongas.IdentityServer.EntityFramework.Store.Test/CorsPolicyServiceTest.cs b/test/Aguacongas.IdentityServer.EntityFramework.Store.Test/CorsPolicyServiceTest.cs index 68a811bd4..9595efe9e 100644 --- a/test/Aguacongas.IdentityServer.EntityFramework.Store.Test/CorsPolicyServiceTest.cs +++ b/test/Aguacongas.IdentityServer.EntityFramework.Store.Test/CorsPolicyServiceTest.cs @@ -1,6 +1,7 @@ // Project: Aguafrommars/TheIdServer // Copyright (c) 2021 @Olivier Lefebvre using Aguacongas.IdentityServer.Store; +using Aguacongas.TheIdServer.Authentication; using IdentityServer4.Services; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; @@ -26,7 +27,7 @@ public async Task IsOriginAllowedAsync_should_return_false() .AddLogging() .Configure(options => options.Caching.CorsExpiration = TimeSpan.FromMinutes(1)) .AddTransient(p => p.GetRequiredService>().Value) - .AddConfigurationEntityFrameworkStores(options => + .AddConfigurationEntityFrameworkStores(options => options.UseInMemoryDatabase(Guid.NewGuid().ToString())) .BuildServiceProvider(); diff --git a/test/Aguacongas.TheIdServer.Authentication..Integration.Test/TheIdServerTestFixture.cs b/test/Aguacongas.TheIdServer.Authentication..Integration.Test/TheIdServerTestFixture.cs index 90474fca7..a29d3dec4 100644 --- a/test/Aguacongas.TheIdServer.Authentication..Integration.Test/TheIdServerTestFixture.cs +++ b/test/Aguacongas.TheIdServer.Authentication..Integration.Test/TheIdServerTestFixture.cs @@ -3,7 +3,6 @@ using Aguacongas.AspNetCore.Authentication; using Aguacongas.IdentityServer.EntityFramework.Store; using Aguacongas.TheIdServer.Data; -using Aguacongas.TheIdServer.Models; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.WsFederation; @@ -32,7 +31,7 @@ public TheIdServerTestFixture() services.AddIdentityServer4AdminEntityFrameworkStores(options => options.UseInMemoryDatabase(dbName)) .AddIdentityProviderStore() - .AddConfigurationEntityFrameworkStores(options => + .AddConfigurationEntityFrameworkStores(options => options.UseInMemoryDatabase(dbName)) .AddOperationalEntityFrameworkStores(options => options.UseInMemoryDatabase(dbName)) diff --git a/test/Aguacongas.TheIdServer.Identity.IntegrationTest/TheIdServerTestFixture.cs b/test/Aguacongas.TheIdServer.Identity.IntegrationTest/TheIdServerTestFixture.cs index 5bf2e1b15..43888b9b9 100644 --- a/test/Aguacongas.TheIdServer.Identity.IntegrationTest/TheIdServerTestFixture.cs +++ b/test/Aguacongas.TheIdServer.Identity.IntegrationTest/TheIdServerTestFixture.cs @@ -1,8 +1,8 @@ // Project: Aguafrommars/TheIdServer // Copyright (c) 2021 @Olivier Lefebvre using Aguacongas.IdentityServer.EntityFramework.Store; +using Aguacongas.TheIdServer.Authentication; using Aguacongas.TheIdServer.Data; -using Aguacongas.TheIdServer.Models; using Microsoft.AspNetCore.TestHost; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; @@ -44,7 +44,7 @@ public TheIdServerTestFixture() .AddIdentityServer4AdminEntityFrameworkStores(options => options.UseInMemoryDatabase(dbName)) .AddIdentityProviderStore() - .AddConfigurationEntityFrameworkStores(options => + .AddConfigurationEntityFrameworkStores(options => options.UseInMemoryDatabase(dbName)) .AddOperationalEntityFrameworkStores(options => options.UseInMemoryDatabase(dbName)); diff --git a/test/Aguacongas.TheIdServer.IntegrationTest/ApiFixture.cs b/test/Aguacongas.TheIdServer.IntegrationTest/ApiFixture.cs index 0a2ca315f..fe9dff529 100644 --- a/test/Aguacongas.TheIdServer.IntegrationTest/ApiFixture.cs +++ b/test/Aguacongas.TheIdServer.IntegrationTest/ApiFixture.cs @@ -1,6 +1,7 @@ // Project: Aguafrommars/TheIdServer // Copyright (c) 2021 @Olivier Lefebvre using Aguacongas.IdentityServer.EntityFramework.Store; +using Aguacongas.TheIdServer.Authentication; using Aguacongas.TheIdServer.Data; using Aguacongas.TheIdServer.Models; using Microsoft.AspNetCore.TestHost; @@ -38,7 +39,7 @@ public ApiFixture() .AddIdentityServer4AdminEntityFrameworkStores(options => options.UseInMemoryDatabase(dbName)) .AddIdentityProviderStore() - .AddConfigurationEntityFrameworkStores(options => + .AddConfigurationEntityFrameworkStores(options => options.UseInMemoryDatabase(dbName)) .AddOperationalEntityFrameworkStores(options => options.UseInMemoryDatabase(dbName)); diff --git a/test/Aguacongas.TheIdServer.IntegrationTest/BlazorApp/Pages/ExternalProviderTest.cs b/test/Aguacongas.TheIdServer.IntegrationTest/BlazorApp/Pages/ExternalProviderTest.cs index 466149971..55b48a586 100644 --- a/test/Aguacongas.TheIdServer.IntegrationTest/BlazorApp/Pages/ExternalProviderTest.cs +++ b/test/Aguacongas.TheIdServer.IntegrationTest/BlazorApp/Pages/ExternalProviderTest.cs @@ -2,6 +2,7 @@ // Copyright (c) 2021 @Olivier Lefebvre using Aguacongas.IdentityServer.EntityFramework.Store; using Aguacongas.IdentityServer.Store; +using Aguacongas.IdentityServer.Store.Entity; using Aguacongas.TheIdServer.BlazorApp; using Microsoft.AspNetCore.Components.Testing; using Microsoft.EntityFrameworkCore; @@ -73,7 +74,7 @@ public async Task SaveClick_should_create_provider() await DbActionAsync(async context => { - var provider = await context.Providers.FirstOrDefaultAsync(r => r.Scheme == providerName); + var provider = await context.Providers.FirstOrDefaultAsync(r => r.Id == providerName); Assert.NotNull(provider); }); } @@ -137,7 +138,7 @@ public async Task DeleteButtonClick_should_delete_Role() await DbActionAsync(async context => { - var provider = await context.Providers.FirstOrDefaultAsync(p => p.Scheme == providerId); + var provider = await context.Providers.FirstOrDefaultAsync(p => p.Id == providerId); Assert.Null(provider); }); } @@ -218,7 +219,7 @@ public async Task RequiredHttpsMetadata_click_should_revalidate_MetadataAddress( var providerId = GenerateId(); await DbActionAsync(async c => { - await c.Providers.AddAsync(new SchemeDefinition + await c.Providers.AddAsync(new ExternalProvider { Id = providerId, DisplayName = GenerateId(), @@ -257,7 +258,7 @@ private async Task CreateProvider() var providerId = GenerateId(); await DbActionAsync(async c => { - await c.Providers.AddAsync(new SchemeDefinition + await c.Providers.AddAsync(new ExternalProvider { Id = providerId, DisplayName = GenerateId(), diff --git a/test/Aguacongas.TheIdServer.IntegrationTest/BlazorApp/Pages/ExternalProvidersTest.cs b/test/Aguacongas.TheIdServer.IntegrationTest/BlazorApp/Pages/ExternalProvidersTest.cs index 203923d87..0e7eacf0b 100644 --- a/test/Aguacongas.TheIdServer.IntegrationTest/BlazorApp/Pages/ExternalProvidersTest.cs +++ b/test/Aguacongas.TheIdServer.IntegrationTest/BlazorApp/Pages/ExternalProvidersTest.cs @@ -22,9 +22,9 @@ protected override Task PopulateList() { return DbActionAsync(async context => { - await context.Providers.AddAsync(new SchemeDefinition + await context.Providers.AddAsync(new ExternalProvider { - Scheme = GenerateId(), + Id = GenerateId(), DisplayName = "filtered", SerializedOptions = "{\"ClientId\":\"818322595124 - h0nd8080luc71ba2i19a5kigackfm8me.apps.googleusercontent.com\",\"ClientSecret\":\"ac_tx - O9XvZGNRi4HYfPerx2\",\"AuthorizationEndpoint\":\"https://accounts.google.com/o/oauth2/v2/auth\",\"TokenEndpoint\":\"https://www.googleapis.com/oauth2/v4/token\",\"UserInformationEndpoint\":\"https://www.googleapis.com/oauth2/v2/userinfo\",\"Events\":{},\"ClaimActions\":[{\"JsonKey\":\"id\",\"ClaimType\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier\",\"ValueType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"JsonKey\":\"name\",\"ClaimType\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name\",\"ValueType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"JsonKey\":\"given_name\",\"ClaimType\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname\",\"ValueType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"JsonKey\":\"family_name\",\"ClaimType\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname\",\"ValueType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"JsonKey\":\"link\",\"ClaimType\":\"urn:google:profile\",\"ValueType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"JsonKey\":\"email\",\"ClaimType\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress\",\"ValueType\":\"http://www.w3.org/2001/XMLSchema#string\"}],\"Scope\":[\"openid\",\"profile\",\"email\"],\"BackchannelTimeout\":\"00:01:00\",\"Backchannel\":{\"DefaultRequestHeaders\":[{\"Key\":\"User-Agent\",\"Value\":[\"Microsoft\",\"ASP.NET\",\"Core\",\"OAuth\",\"handler\"]}],\"DefaultRequestVersion\":\"1.1\",\"Timeout\":\"00:01:00\",\"MaxResponseContentBufferSize\":10485760},\"CallbackPath\":\"/signin-google\",\"ReturnUrlParameter\":\"ReturnUrl\",\"SignInScheme\":\"Identity.External\",\"RemoteAuthenticationTimeout\":\"00:15:00\",\"CorrelationCookie\":{\"Name\":\".AspNetCore.Correlation.\",\"HttpOnly\":true,\"IsEssential\":true}}", SerializedHandlerType = "{\"Name\":\"Microsoft.AspNetCore.Authentication.Google.GoogleHandler\"}" diff --git a/test/Aguacongas.TheIdServer.IntegrationTest/BlazorApp/Pages/RoleTest.cs b/test/Aguacongas.TheIdServer.IntegrationTest/BlazorApp/Pages/RoleTest.cs index b4d497f23..f05ff9a17 100644 --- a/test/Aguacongas.TheIdServer.IntegrationTest/BlazorApp/Pages/RoleTest.cs +++ b/test/Aguacongas.TheIdServer.IntegrationTest/BlazorApp/Pages/RoleTest.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Components.Testing; using Microsoft.EntityFrameworkCore; using RichardSzalay.MockHttp; +using System; using System.Linq; using System.Threading.Tasks; using Xunit; @@ -257,6 +258,7 @@ await DbActionAsync(context => }); context.RoleClaims.Add(new RoleClaim { + Id = Guid.NewGuid().ToString(), RoleId = roleId, ClaimType = "filtered", ClaimValue = "filtered" diff --git a/test/Aguacongas.TheIdServer.IntegrationTest/SchemeChangeSubscriberTest.cs b/test/Aguacongas.TheIdServer.IntegrationTest/SchemeChangeSubscriberTest.cs index c7aecd97b..4313cfea1 100644 --- a/test/Aguacongas.TheIdServer.IntegrationTest/SchemeChangeSubscriberTest.cs +++ b/test/Aguacongas.TheIdServer.IntegrationTest/SchemeChangeSubscriberTest.cs @@ -1,12 +1,12 @@ // Project: Aguafrommars/TheIdServer // Copyright (c) 2021 @Olivier Lefebvre using Aguacongas.AspNetCore.Authentication; -using Aguacongas.AspNetCore.Authentication.EntityFramework; using Aguacongas.IdentityServer.Abstractions; using Aguacongas.IdentityServer.Admin.Http.Store; using Aguacongas.IdentityServer.Admin.Services; using Aguacongas.IdentityServer.Store; using Aguacongas.IdentityServer.Store.Entity; +using Aguacongas.TheIdServer.Authentication; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.Google; using Microsoft.AspNetCore.DataProtection.KeyManagement; diff --git a/test/Aguacongas.TheIdServer.IntegrationTest/TestUtils.cs b/test/Aguacongas.TheIdServer.IntegrationTest/TestUtils.cs index 4266715d6..b3dfcc39b 100644 --- a/test/Aguacongas.TheIdServer.IntegrationTest/TestUtils.cs +++ b/test/Aguacongas.TheIdServer.IntegrationTest/TestUtils.cs @@ -78,11 +78,11 @@ public static TestServer CreateTestServer( using var scope = builder.ApplicationServices.CreateScope(); var dbContext = scope.ServiceProvider.GetService(); - if (dbContext != null && !dbContext.Providers.Any(p => p.Scheme == "Google")) + if (dbContext != null && !dbContext.Providers.Any(p => p.Id == "Google")) { - dbContext.Providers.Add(new SchemeDefinition + dbContext.Providers.Add(new ExternalProvider { - Scheme = "Google", + Id = "Google", DisplayName = "Google", SerializedHandlerType = "{\"Name\":\"Microsoft.AspNetCore.Authentication.Google.GoogleHandler\"}", SerializedOptions = "{\"ClientId\":\"818322595124-h0nd8080luc71ba2i19a5kigackfm8me.apps.googleusercontent.com\",\"ClientSecret\":\"ac_tx-O9XvZGNRi4HYfPerx2\",\"AuthorizationEndpoint\":\"https://accounts.google.com/o/oauth2/v2/auth\",\"TokenEndpoint\":\"https://oauth2.googleapis.com/token\",\"UserInformationEndpoint\":\"https://www.googleapis.com/oauth2/v2/userinfo\",\"Events\":{},\"ClaimActions\":[{\"JsonKey\":\"id\",\"ClaimType\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier\",\"ValueType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"JsonKey\":\"name\",\"ClaimType\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name\",\"ValueType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"JsonKey\":\"given_name\",\"ClaimType\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname\",\"ValueType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"JsonKey\":\"family_name\",\"ClaimType\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname\",\"ValueType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"JsonKey\":\"link\",\"ClaimType\":\"urn:google:profile\",\"ValueType\":\"http://www.w3.org/2001/XMLSchema#string\"},{\"JsonKey\":\"email\",\"ClaimType\":\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress\",\"ValueType\":\"http://www.w3.org/2001/XMLSchema#string\"}],\"Scope\":[\"openid\",\"profile\",\"email\"],\"BackchannelTimeout\":\"00:01:00\",\"Backchannel\":{\"DefaultRequestHeaders\":[{\"Key\":\"User-Agent\",\"Value\":[\"Microsoft\",\"ASP.NET\",\"Core\",\"OAuth\",\"handler\"]}],\"DefaultRequestVersion\":\"1.1\",\"Timeout\":\"00:01:00\",\"MaxResponseContentBufferSize\":10485760},\"CallbackPath\":\"/signin-Google\",\"ReturnUrlParameter\":\"ReturnUrl\",\"SignInScheme\":\"Identity.External\",\"RemoteAuthenticationTimeout\":\"00:15:00\",\"CorrelationCookie\":{\"Name\":\".AspNetCore.Correlation.\",\"HttpOnly\":true,\"IsEssential\":true}}" diff --git a/test/Aguacongas.TheIdServer.Test/ExternalClaimsTransformerTest.cs b/test/Aguacongas.TheIdServer.Test/ExternalClaimsTransformerTest.cs index fd3982213..9a0e28c74 100644 --- a/test/Aguacongas.TheIdServer.Test/ExternalClaimsTransformerTest.cs +++ b/test/Aguacongas.TheIdServer.Test/ExternalClaimsTransformerTest.cs @@ -4,6 +4,7 @@ using Aguacongas.IdentityServer.Admin.Services; using Aguacongas.IdentityServer.EntityFramework.Store; using Aguacongas.IdentityServer.Store.Entity; +using Aguacongas.TheIdServer.Authentication; using Aguacongas.TheIdServer.Data; using Aguacongas.TheIdServer.Models; using IdentityModel; @@ -39,7 +40,7 @@ public async Task TransformPrincipal_should_transform_claims() Scheme = "test" }); var serializer = builder.GetRequiredService(); - configurationDbContext.Providers.Add(new SchemeDefinition + configurationDbContext.Providers.Add(new ExternalProvider { Id = "test", SerializedHandlerType = serializer.SerializeType(typeof(GoogleHandler)), @@ -70,7 +71,7 @@ public async Task TransformPrincipal_should_provision_user(string claimType) using var scope = builder.CreateScope(); var configurationDbContext = scope.ServiceProvider.GetRequiredService(); var serializer = builder.GetRequiredService(); - configurationDbContext.Providers.Add(new SchemeDefinition + configurationDbContext.Providers.Add(new ExternalProvider { Id = "test", StoreClaims = true, @@ -101,7 +102,7 @@ public async Task TransformPrincipal_should_throw_when_id_not_found() using var scope = builder.CreateScope(); var configurationDbContext = scope.ServiceProvider.GetRequiredService(); var serializer = builder.GetRequiredService(); - configurationDbContext.Providers.Add(new SchemeDefinition + configurationDbContext.Providers.Add(new ExternalProvider { Id = "test", StoreClaims = true, @@ -139,7 +140,7 @@ public async Task TransformPrincipal_should_throw_when_cannot_create_user() using var scope = builder.CreateScope(); var configurationDbContext = scope.ServiceProvider.GetRequiredService(); var serializer = builder.GetRequiredService(); - configurationDbContext.Providers.Add(new SchemeDefinition + configurationDbContext.Providers.Add(new ExternalProvider { Id = "test", StoreClaims = true, @@ -191,7 +192,7 @@ public async Task TransformPrincipal_should_throw_when_cannot_create_login() using var scope = builder.CreateScope(); var configurationDbContext = scope.ServiceProvider.GetRequiredService(); var serializer = builder.GetRequiredService(); - configurationDbContext.Providers.Add(new SchemeDefinition + configurationDbContext.Providers.Add(new ExternalProvider { Id = "test", StoreClaims = true, @@ -219,7 +220,7 @@ public async Task TransformPrincipal_should_add_remove_claims() using var scope = builder.CreateScope(); var configurationDbContext = scope.ServiceProvider.GetRequiredService(); var serializer = builder.GetRequiredService(); - configurationDbContext.Providers.Add(new SchemeDefinition + configurationDbContext.Providers.Add(new ExternalProvider { Id = "test", StoreClaims = true, @@ -259,7 +260,7 @@ private static IServiceCollection CreateServices() .AddTransient(p => configuration) .AddLogging() .AddIdentityServer4AdminEntityFrameworkStores(options => options.UseInMemoryDatabase(dbId)) - .AddConfigurationEntityFrameworkStores(options => options.UseInMemoryDatabase(dbId)) + .AddConfigurationEntityFrameworkStores(options => options.UseInMemoryDatabase(dbId)) .AddIdentityProviderStore(); services.AddIdentity() @@ -270,7 +271,7 @@ private static IServiceCollection CreateServices() services.AddControllersWithViews() .AddIdentityServerAdmin() - .AddEntityFrameworkStore(); + .AddTheIdServerStore(); return services; } diff --git a/test/Aguacongas.TheIdServer.Test/StartupTest.cs b/test/Aguacongas.TheIdServer.Test/StartupTest.cs index 7cd0b133a..437e29bbc 100644 --- a/test/Aguacongas.TheIdServer.Test/StartupTest.cs +++ b/test/Aguacongas.TheIdServer.Test/StartupTest.cs @@ -4,10 +4,10 @@ using Aguacongas.IdentityServer.Abstractions; using Aguacongas.IdentityServer.Admin.Configuration; using Aguacongas.IdentityServer.Admin.Services; -using Aguacongas.IdentityServer.EntityFramework.Store; using Aguacongas.IdentityServer.Store; using Aguacongas.IdentityServer.Store.Entity; using Aguacongas.TheIdServer.Admin.Hubs; +using Aguacongas.TheIdServer.Authentication; using Aguacongas.TheIdServer.Models; using Microsoft.AspNetCore; using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;