diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index 94a2e79415..f92a9d336b 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -405,6 +405,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.BackgroundWorkers. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Gdpr.Abstractions", "src\Volo.Abp.Gdpr.Abstractions\Volo.Abp.Gdpr.Abstractions.csproj", "{3683340D-92F5-4B14-B77B-34A163333309}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.RemoteServices", "src\Volo.Abp.RemoteServices\Volo.Abp.RemoteServices.csproj", "{EDFFDA74-090D-439C-A58D-06CCF86D4423}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1207,6 +1209,10 @@ Global {3683340D-92F5-4B14-B77B-34A163333309}.Debug|Any CPU.Build.0 = Debug|Any CPU {3683340D-92F5-4B14-B77B-34A163333309}.Release|Any CPU.ActiveCfg = Release|Any CPU {3683340D-92F5-4B14-B77B-34A163333309}.Release|Any CPU.Build.0 = Release|Any CPU + {EDFFDA74-090D-439C-A58D-06CCF86D4423}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EDFFDA74-090D-439C-A58D-06CCF86D4423}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EDFFDA74-090D-439C-A58D-06CCF86D4423}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EDFFDA74-090D-439C-A58D-06CCF86D4423}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1411,6 +1417,7 @@ Global {C4F54FB5-C828-414D-BA03-E8E7A10C784D} = {447C8A77-E5F0-4538-8687-7383196D04EA} {E5FCE710-C5A3-4F94-B9C9-BD1E99252BFB} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {3683340D-92F5-4B14-B77B-34A163333309} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} + {EDFFDA74-090D-439C-A58D-06CCF86D4423} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs index 894ba470a8..2a2d0a712d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs @@ -3,8 +3,10 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.OAuth.Claims; using Microsoft.AspNetCore.Authentication.OpenIdConnect; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.IdentityModel.Protocols.OpenIdConnect; +using Volo.Abp.AspNetCore.Authentication.OpenIdConnect; using Volo.Abp.AspNetCore.MultiTenancy; namespace Microsoft.Extensions.DependencyInjection; @@ -47,6 +49,20 @@ public static class AbpOpenIdConnectExtensions } return Task.CompletedTask; }; + + options.Events.OnTokenValidated = async (context) => + { + var client = context.HttpContext.RequestServices.GetRequiredService(); + try + { + await client.CreateOrUpdateAsync(context); + } + catch (Exception ex) + { + var logger = context.HttpContext.RequestServices.GetService>(); + logger?.LogException(ex); + } + }; }); } diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj index d441613119..e7810f6e37 100644 --- a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj @@ -15,6 +15,7 @@ + diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs index 8670fbea17..6b66a105d3 100644 --- a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs @@ -1,12 +1,15 @@ using Volo.Abp.AspNetCore.Authentication.OAuth; using Volo.Abp.Modularity; using Volo.Abp.MultiTenancy; +using Volo.Abp.RemoteServices; namespace Volo.Abp.AspNetCore.Authentication.OpenIdConnect; [DependsOn( typeof(AbpMultiTenancyModule), - typeof(AbpAspNetCoreAuthenticationOAuthModule))] + typeof(AbpAspNetCoreAuthenticationOAuthModule), + typeof(AbpRemoteServicesModule) + )] public class AbpAspNetCoreAuthenticationOpenIdConnectModule : AbpModule { diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/IOpenIdLocalUserCreationClient.cs b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/IOpenIdLocalUserCreationClient.cs new file mode 100644 index 0000000000..5b6b8ee61d --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/IOpenIdLocalUserCreationClient.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication.OpenIdConnect; + +namespace Volo.Abp.AspNetCore.Authentication.OpenIdConnect; + +public interface IOpenIdLocalUserCreationClient +{ + Task CreateOrUpdateAsync(TokenValidatedContext tokenValidatedContext); +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/OpenIdLocalUserCreationClient.cs b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/OpenIdLocalUserCreationClient.cs new file mode 100644 index 0000000000..d0d71ca6d4 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/OpenIdLocalUserCreationClient.cs @@ -0,0 +1,59 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authentication.OpenIdConnect; +using Microsoft.Extensions.Options; +using Microsoft.Net.Http.Headers; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Http.Client; + +namespace Volo.Abp.AspNetCore.Authentication.OpenIdConnect; + +public class OpenIdLocalUserCreationClient : IOpenIdLocalUserCreationClient, ITransientDependency +{ + protected OpenIdLocalUserCreationClientOptions Options { get; } + protected IHttpClientFactory HttpClientFactory { get; } + protected IRemoteServiceConfigurationProvider RemoteServiceConfigurationProvider { get; } + + public OpenIdLocalUserCreationClient( + IOptions options, + IHttpClientFactory httpClientFactory, + IRemoteServiceConfigurationProvider remoteServiceConfigurationProvider) + { + HttpClientFactory = httpClientFactory; + RemoteServiceConfigurationProvider = remoteServiceConfigurationProvider; + Options = options.Value; + } + + public virtual async Task CreateOrUpdateAsync(TokenValidatedContext context) + { + if (!Options.IsEnabled) + { + return; + } + + using (var httpClient = HttpClientFactory.CreateClient(Options.HttpClientName)) + { + if (!Options.RemoteServiceName.IsNullOrWhiteSpace()) + { + var configuration = await RemoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync(Options.RemoteServiceName); + if (configuration.BaseUrl != null) + { + httpClient.BaseAddress = new Uri(configuration.BaseUrl); + } + } + + httpClient.DefaultRequestHeaders.Add( + HeaderNames.Authorization, + "Bearer " + context.SecurityToken.RawData + ); + + var response = await httpClient.PostAsync( + Options.Url, + new StringContent(string.Empty) + ); + + response.EnsureSuccessStatusCode(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/OpenIdLocalUserCreationClientOptions.cs b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/OpenIdLocalUserCreationClientOptions.cs new file mode 100644 index 0000000000..02bbae675a --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/OpenIdLocalUserCreationClientOptions.cs @@ -0,0 +1,32 @@ +using System.Net.Http; + +namespace Volo.Abp.AspNetCore.Authentication.OpenIdConnect; + +public class OpenIdLocalUserCreationClientOptions +{ + /// + /// Can be used to enable/disable request to the server to create/update local users. + /// Default value: false + /// + public bool IsEnabled { get; set; } + + /// + /// Default value: "AbpIdentity". + /// Fallbacks to the "Default" remote service configuration, if "AbpIdentity" configuration is not available. + /// Set to null if you don't want to use a remote service configuration. In this case, you can set an + /// absolute URL in the option. + /// + public string RemoteServiceName { get; set; } = "AbpIdentity"; + + /// + /// URL to make a POST request after the current user successfully authenticated through an OpenIdConnect provider. + /// + public string Url { get; set; } = "/api/identity-profile/create-or-update"; + + /// + /// Can be set to a value if you want to use a named instance + /// while creating it from . + /// Default value: "" (). + /// + public string HttpClientName { get; } = Microsoft.Extensions.Options.Options.DefaultName; +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj b/framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj index 92d4cc81b7..67aef7dd89 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj +++ b/framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj @@ -23,6 +23,7 @@ + diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientModule.cs b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientModule.cs index 6dbdcb221f..8bca3702c5 100644 --- a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientModule.cs +++ b/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientModule.cs @@ -6,6 +6,7 @@ using Volo.Abp.Threading; using Volo.Abp.Validation; using Volo.Abp.ExceptionHandling; using Volo.Abp.Http.Client.DynamicProxying; +using Volo.Abp.RemoteServices; namespace Volo.Abp.Http.Client; @@ -15,15 +16,13 @@ namespace Volo.Abp.Http.Client; typeof(AbpThreadingModule), typeof(AbpMultiTenancyModule), typeof(AbpValidationModule), - typeof(AbpExceptionHandlingModule) + typeof(AbpExceptionHandlingModule), + typeof(AbpRemoteServicesModule) )] public class AbpHttpClientModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { - var configuration = context.Services.GetConfiguration(); - Configure(configuration); - context.Services.AddTransient(typeof(DynamicHttpProxyInterceptorClientProxy<>)); } } diff --git a/framework/src/Volo.Abp.RemoteServices/FodyWeavers.xml b/framework/src/Volo.Abp.RemoteServices/FodyWeavers.xml new file mode 100644 index 0000000000..be0de3a908 --- /dev/null +++ b/framework/src/Volo.Abp.RemoteServices/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.RemoteServices/FodyWeavers.xsd b/framework/src/Volo.Abp.RemoteServices/FodyWeavers.xsd new file mode 100644 index 0000000000..3f3946e282 --- /dev/null +++ b/framework/src/Volo.Abp.RemoteServices/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.RemoteServices/Volo.Abp.RemoteServices.csproj b/framework/src/Volo.Abp.RemoteServices/Volo.Abp.RemoteServices.csproj new file mode 100644 index 0000000000..74ad1df500 --- /dev/null +++ b/framework/src/Volo.Abp.RemoteServices/Volo.Abp.RemoteServices.csproj @@ -0,0 +1,21 @@ + + + + + + + netstandard2.0 + Volo.Abp.RemoteServices + Volo.Abp.RemoteServices + $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; + false + false + false + + + + + + + + diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpRemoteServiceOptions.cs b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/AbpRemoteServiceOptions.cs similarity index 100% rename from framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpRemoteServiceOptions.cs rename to framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/AbpRemoteServiceOptions.cs diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/IRemoteServiceConfigurationProvider.cs b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/IRemoteServiceConfigurationProvider.cs similarity index 100% rename from framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/IRemoteServiceConfigurationProvider.cs rename to framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/IRemoteServiceConfigurationProvider.cs diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs similarity index 100% rename from framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs rename to framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationDictionary.cs b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationDictionary.cs similarity index 100% rename from framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationDictionary.cs rename to framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationDictionary.cs diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider.cs b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider.cs similarity index 100% rename from framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider.cs rename to framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider.cs diff --git a/framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationProviderExtensions.cs b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationProviderExtensions.cs similarity index 100% rename from framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationProviderExtensions.cs rename to framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationProviderExtensions.cs diff --git a/framework/src/Volo.Abp.RemoteServices/Volo/Abp/RemoteServices/AbpRemoteServicesModule.cs b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/RemoteServices/AbpRemoteServicesModule.cs new file mode 100644 index 0000000000..dba4842597 --- /dev/null +++ b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/RemoteServices/AbpRemoteServicesModule.cs @@ -0,0 +1,14 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Http.Client; +using Volo.Abp.Modularity; + +namespace Volo.Abp.RemoteServices; + +public class AbpRemoteServicesModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + Configure(configuration); + } +} \ No newline at end of file diff --git a/nupkg/common.ps1 b/nupkg/common.ps1 index 6d1214918c..d0dc8e9359 100644 --- a/nupkg/common.ps1 +++ b/nupkg/common.ps1 @@ -202,6 +202,7 @@ $projects = ( "framework/src/Volo.Abp.ObjectMapping", "framework/src/Volo.Abp.Quartz", "framework/src/Volo.Abp.RabbitMQ", + "framework/src/Volo.Abp.RemoteServices", "framework/src/Volo.Abp.Security", "framework/src/Volo.Abp.Serialization", "framework/src/Volo.Abp.Settings",