mirror of https://github.com/abpframework/abp.git
Browse Source
Package contains the 'pass-through' authenticator-implementation which previously was in `Volo.Abp.Http.Client.IdentityModel.IdentityModelRemoteServiceHttpClientAuthenticator`. Since the `IdentityModelRemoteServiceHttpClientAuthenticator` implementation (without requiring `IHttpContextAccessor`) is required for basic clients (which should be able to target net-standard or netfx) this package was splitted into `Volo.Abp.Http.Client.IdentityModel.Relay` to support the known behavior of just passing the token around. WARNING: This commit contains a breaking change for existing backend applications which use automagic C# clients!pull/2867/head
9 changed files with 160 additions and 35 deletions
@ -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,27 @@ |
|||
{ |
|||
"iisSettings": { |
|||
"windowsAuthentication": false, |
|||
"anonymousAuthentication": true, |
|||
"iisExpress": { |
|||
"applicationUrl": "http://localhost:52306/", |
|||
"sslPort": 0 |
|||
} |
|||
}, |
|||
"profiles": { |
|||
"IIS Express": { |
|||
"commandName": "IISExpress", |
|||
"launchBrowser": true, |
|||
"environmentVariables": { |
|||
"ASPNETCORE_ENVIRONMENT": "Development" |
|||
} |
|||
}, |
|||
"Volo.Abp.Http.Client.IdentityModel": { |
|||
"commandName": "Project", |
|||
"launchBrowser": true, |
|||
"environmentVariables": { |
|||
"ASPNETCORE_ENVIRONMENT": "Development" |
|||
}, |
|||
"applicationUrl": "http://localhost:52307/" |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.Web"> |
|||
|
|||
<Import Project="..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp3.1</TargetFramework> |
|||
<AssemblyName>Volo.Abp.Http.Client.IdentityModel.Relay</AssemblyName> |
|||
<PackageId>Volo.Abp.Http.Client.IdentityModel.Relay</PackageId> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<IsPackable>true</IsPackable> |
|||
<OutputType>Library</OutputType> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.Http.Client.IdentityModel\Volo.Abp.Http.Client.IdentityModel.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.IdentityModel; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.Http.Client.IdentityModel.Relay |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpHttpClientIdentityModelModule) |
|||
)] |
|||
public class AbpHttpClientIdentityModelRelayModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
using System.Threading.Tasks; |
|||
using IdentityModel.Client; |
|||
using Microsoft.AspNetCore.Authentication; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Http.Client.Authentication; |
|||
using Volo.Abp.IdentityModel; |
|||
|
|||
namespace Volo.Abp.Http.Client.IdentityModel.Relay |
|||
{ |
|||
[Dependency(ReplaceServices = true)] |
|||
public class IdentityModelRemoteServiceHttpClientRelayAuthenticator : IdentityModelRemoteServiceHttpClientAuthenticator, ITransientDependency |
|||
{ |
|||
public IHttpContextAccessor HttpContextAccessor { get; set; } |
|||
|
|||
public IdentityModelRemoteServiceHttpClientRelayAuthenticator( |
|||
IIdentityModelAuthenticationService identityModelAuthenticationService) |
|||
: base(identityModelAuthenticationService) |
|||
{ |
|||
} |
|||
|
|||
public override async Task Authenticate(RemoteServiceHttpClientAuthenticateContext context) |
|||
{ |
|||
if (context.RemoteService.GetUseCurrentAccessToken() != false) |
|||
{ |
|||
var accessToken = await GetAccessTokenFromHttpContextOrNullAsync(); |
|||
if (accessToken != null) |
|||
{ |
|||
context.Request.SetBearerToken(accessToken); |
|||
return; |
|||
} |
|||
} |
|||
|
|||
await base.Authenticate(context); |
|||
} |
|||
|
|||
protected virtual async Task<string> GetAccessTokenFromHttpContextOrNullAsync() |
|||
{ |
|||
var httpContext = HttpContextAccessor?.HttpContext; |
|||
if (httpContext == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
return await httpContext.GetTokenAsync("access_token"); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue