mirror of https://github.com/abpframework/abp.git
committed by
GitHub
20 changed files with 201 additions and 5 deletions
@ -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); |
|||
} |
|||
@ -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(); |
|||
} |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<ConfigureAwait ContinueOnCapturedContext="false" /> |
|||
</Weavers> |
|||
@ -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> |
|||
@ -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,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); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue