Browse Source

Merge pull request #12692 from abpframework/external-user-update

External user update on external login on the client side
pull/12780/head
Enis Necipoglu 4 years ago
committed by GitHub
parent
commit
7e16693e5d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      framework/Volo.Abp.sln
  2. 16
      framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Microsoft/Extensions/DependencyInjection/AbpOpenIdConnectExtensions.cs
  3. 1
      framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj
  4. 5
      framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/AbpAspNetCoreAuthenticationOpenIdConnectModule.cs
  5. 9
      framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/IOpenIdLocalUserCreationClient.cs
  6. 59
      framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/OpenIdLocalUserCreationClient.cs
  7. 32
      framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo/Abp/AspNetCore/Authentication/OpenIdConnect/OpenIdLocalUserCreationClientOptions.cs
  8. 1
      framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj
  9. 7
      framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpHttpClientModule.cs
  10. 3
      framework/src/Volo.Abp.RemoteServices/FodyWeavers.xml
  11. 30
      framework/src/Volo.Abp.RemoteServices/FodyWeavers.xsd
  12. 21
      framework/src/Volo.Abp.RemoteServices/Volo.Abp.RemoteServices.csproj
  13. 0
      framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/AbpRemoteServiceOptions.cs
  14. 0
      framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/IRemoteServiceConfigurationProvider.cs
  15. 0
      framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs
  16. 0
      framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationDictionary.cs
  17. 0
      framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider.cs
  18. 0
      framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationProviderExtensions.cs
  19. 14
      framework/src/Volo.Abp.RemoteServices/Volo/Abp/RemoteServices/AbpRemoteServicesModule.cs
  20. 1
      nupkg/common.ps1

7
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}

16
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<IOpenIdLocalUserCreationClient>();
try
{
await client.CreateOrUpdateAsync(context);
}
catch (Exception ex)
{
var logger = context.HttpContext.RequestServices.GetService<ILogger<AbpAspNetCoreAuthenticationOpenIdConnectModule>>();
logger?.LogException(ex);
}
};
});
}

1
framework/src/Volo.Abp.AspNetCore.Authentication.OpenIdConnect/Volo.Abp.AspNetCore.Authentication.OpenIdConnect.csproj

@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AspNetCore.MultiTenancy\Volo.Abp.AspNetCore.MultiTenancy.csproj" />
<ProjectReference Include="..\Volo.Abp.AspNetCore.Authentication.OAuth\Volo.Abp.AspNetCore.Authentication.OAuth.csproj" />
<ProjectReference Include="..\Volo.Abp.RemoteServices\Volo.Abp.RemoteServices.csproj" />
</ItemGroup>
</Project>

5
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
{

9
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);
}

59
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<OpenIdLocalUserCreationClientOptions> 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();
}
}
}

32
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
{
/// <summary>
/// Can be used to enable/disable request to the server to create/update local users.
/// Default value: false
/// </summary>
public bool IsEnabled { get; set; }
/// <summary>
/// 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 <see cref="Url"/> option.
/// </summary>
public string RemoteServiceName { get; set; } = "AbpIdentity";
/// <summary>
/// URL to make a POST request after the current user successfully authenticated through an OpenIdConnect provider.
/// </summary>
public string Url { get; set; } = "/api/identity-profile/create-or-update";
/// <summary>
/// Can be set to a value if you want to use a named <see cref="HttpClient"/> instance
/// while creating it from <see cref="IHttpClientFactory"/>.
/// Default value: "" (<see cref="Microsoft.Extensions.Options.Options.DefaultName"/>).
/// </summary>
public string HttpClientName { get; } = Microsoft.Extensions.Options.Options.DefaultName;
}

1
framework/src/Volo.Abp.Http.Client/Volo.Abp.Http.Client.csproj

@ -23,6 +23,7 @@
<ProjectReference Include="..\Volo.Abp.ExceptionHandling\Volo.Abp.ExceptionHandling.csproj" />
<ProjectReference Include="..\Volo.Abp.Http\Volo.Abp.Http.csproj" />
<ProjectReference Include="..\Volo.Abp.MultiTenancy\Volo.Abp.MultiTenancy.csproj" />
<ProjectReference Include="..\Volo.Abp.RemoteServices\Volo.Abp.RemoteServices.csproj" />
<ProjectReference Include="..\Volo.Abp.Threading\Volo.Abp.Threading.csproj" />
<ProjectReference Include="..\Volo.Abp.Validation\Volo.Abp.Validation.csproj" />
</ItemGroup>

7
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<AbpRemoteServiceOptions>(configuration);
context.Services.AddTransient(typeof(DynamicHttpProxyInterceptorClientProxy<>));
}
}

3
framework/src/Volo.Abp.RemoteServices/FodyWeavers.xml

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait ContinueOnCapturedContext="false" />
</Weavers>

30
framework/src/Volo.Abp.RemoteServices/FodyWeavers.xsd

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

21
framework/src/Volo.Abp.RemoteServices/Volo.Abp.RemoteServices.csproj

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.RemoteServices</AssemblyName>
<PackageId>Volo.Abp.RemoteServices</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
</ItemGroup>
</Project>

0
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/AbpRemoteServiceOptions.cs → framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/AbpRemoteServiceOptions.cs

0
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/IRemoteServiceConfigurationProvider.cs → framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/IRemoteServiceConfigurationProvider.cs

0
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs → framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs

0
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationDictionary.cs → framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationDictionary.cs

0
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider.cs → framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider.cs

0
framework/src/Volo.Abp.Http.Client/Volo/Abp/Http/Client/RemoteServiceConfigurationProviderExtensions.cs → framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationProviderExtensions.cs

14
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<AbpRemoteServiceOptions>(configuration);
}
}

1
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",

Loading…
Cancel
Save