Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit d2526ff

Browse files
committed
Port the introspection/validation middleware to the new ASP.NET Core 2.0 authentication stack
1 parent dcaf26d commit d2526ff

File tree

48 files changed

+1093
-1035
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1093
-1035
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ env:
1414
global:
1515
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
1616
- DOTNET_CLI_TELEMETRY_OPTOUT: 1
17-
- KOREBUILD_DOTNET_VERSION: 2.0.0-preview1-005418
18-
- KOREBUILD_DOTNET_SHARED_RUNTIME_VERSION: 2.0.0-preview1-001919-00
1917
mono: none
2018
os:
2119
- linux

NuGet.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<configuration>
33
<packageSources>
44
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
5+
<add key="aspnetcore" value="https://dotnet.myget.org/F/aspnetcore-ci-dev/api/v3/index.json" />
56
<add key="aspnet-contrib" value="https://www.myget.org/F/aspnet-contrib/api/v3/index.json" />
67
</packageSources>
78
</configuration>

build/common.props

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,14 @@
1212
<DebugType Condition=" '$(OS)' != 'Windows_NT' ">portable</DebugType>
1313
</PropertyGroup>
1414

15+
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' ">
16+
<PackageReference Include="NETStandard.Library.NETFramework" Version="$(NetStandardLibraryNetFrameworkVersion)" />
17+
</ItemGroup>
18+
19+
<Target Name="WorkaroundAppConfigPathTooLong" BeforeTargets="GenerateBindingRedirects">
20+
<PropertyGroup>
21+
<_GenerateBindingRedirectsIntermediateAppConfig>$(IntermediateOutputPath)$(TargetFileName).config</_GenerateBindingRedirectsIntermediateAppConfig>
22+
</PropertyGroup>
23+
</Target>
24+
1525
</Project>

build/dependencies.props

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
<Project>
22

33
<PropertyGroup>
4-
<AspNetCoreVersion>1.0.0</AspNetCoreVersion>
4+
<AspNetCoreVersion>2.0.0-*</AspNetCoreVersion>
5+
<CoreFxVersion>4.4.0-*</CoreFxVersion>
56
<IdentityModelVersion>1.0.4.403061554</IdentityModelVersion>
6-
<IdentityModelCoreVersion>2.0.0</IdentityModelCoreVersion>
7+
<IdentityModelCoreVersion>2.1.3-*</IdentityModelCoreVersion>
78
<JetBrainsVersion>10.3.0</JetBrainsVersion>
8-
<JsonNetVersion>9.0.1</JsonNetVersion>
9-
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
10-
<MoqVersion>4.7.8</MoqVersion>
9+
<JsonNetVersion>10.0.2</JsonNetVersion>
10+
<MoqVersion>4.7.63</MoqVersion>
11+
<NetHttpVersion>4.3.2</NetHttpVersion>
12+
<NetStandardImplicitPackageVersion>2.0.0-*</NetStandardImplicitPackageVersion>
13+
<NetStandardLibraryNetFrameworkVersion>2.0.0-*</NetStandardLibraryNetFrameworkVersion>
1114
<OwinVersion>3.0.1</OwinVersion>
12-
<RuntimeFrameworkVersion>1.0.0</RuntimeFrameworkVersion>
13-
<TestSdkVersion>15.0.0</TestSdkVersion>
14-
<XunitVersion>2.2.0</XunitVersion>
15+
<RuntimeFrameworkVersion>2.0.0-*</RuntimeFrameworkVersion>
16+
<TestSdkVersion>15.3.0-*</TestSdkVersion>
17+
<XunitVersion>2.3.0-*</XunitVersion>
1518
</PropertyGroup>
1619

1720
</Project>

build/version.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project>
22

33
<PropertyGroup>
4-
<VersionPrefix>1.0.0</VersionPrefix>
5-
<VersionSuffix>rtm</VersionSuffix>
4+
<VersionPrefix>2.0.0</VersionPrefix>
5+
<VersionSuffix>preview1</VersionSuffix>
66
<VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
77
</PropertyGroup>
88

src/AspNet.Security.OAuth.Introspection/AspNet.Security.OAuth.Introspection.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Import Project="..\..\build\packages.props" />
44

55
<PropertyGroup>
6-
<TargetFrameworks>net451;netstandard1.4</TargetFrameworks>
6+
<TargetFramework>netstandard2.0</TargetFramework>
77
</PropertyGroup>
88

99
<PropertyGroup>

src/AspNet.Security.OAuth.Introspection/Events/ApplyChallengeContext.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,23 @@
77
using JetBrains.Annotations;
88
using Microsoft.AspNetCore.Authentication;
99
using Microsoft.AspNetCore.Http;
10-
using Microsoft.AspNetCore.Http.Authentication;
1110

1211
namespace AspNet.Security.OAuth.Introspection
1312
{
1413
/// <summary>
1514
/// Allows customization of the challenge process.
1615
/// </summary>
17-
public class ApplyChallengeContext : BaseControlContext
16+
public class ApplyChallengeContext : PropertiesContext<OAuthIntrospectionOptions>
1817
{
1918
public ApplyChallengeContext(
2019
[NotNull] HttpContext context,
20+
[NotNull] AuthenticationScheme scheme,
2121
[NotNull] OAuthIntrospectionOptions options,
2222
[NotNull] AuthenticationProperties properties)
23-
: base(context)
23+
: base(context, scheme, options, properties)
2424
{
25-
Options = options;
26-
Properties = properties;
2725
}
2826

29-
/// <summary>
30-
/// Gets the options used by the introspection middleware.
31-
/// </summary>
32-
public OAuthIntrospectionOptions Options { get; }
33-
34-
/// <summary>
35-
/// Gets the authentication properties associated with the challenge.
36-
/// </summary>
37-
public AuthenticationProperties Properties { get; }
38-
3927
/// <summary>
4028
/// Gets or sets the "error" value returned to the caller as part
4129
/// of the WWW-Authenticate header. This property may be null when
@@ -67,5 +55,15 @@ public ApplyChallengeContext(
6755
/// the caller as part of the WWW-Authenticate header.
6856
/// </summary>
6957
public string Scope { get; set; }
58+
59+
/// <summary>
60+
/// Gets a boolean indicating if the operation was handled from user code.
61+
/// </summary>
62+
public bool Handled { get; private set; }
63+
64+
/// <summary>
65+
/// Marks the operation as handled to prevent the default logic from being applied.
66+
/// </summary>
67+
public void HandleResponse() => Handled = true;
7068
}
7169
}

src/AspNet.Security.OAuth.Introspection/Events/CreateTicketContext.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,26 @@ namespace AspNet.Security.OAuth.Introspection
1515
/// <summary>
1616
/// Allows interception of the AuthenticationTicket creation process.
1717
/// </summary>
18-
public class CreateTicketContext : BaseControlContext
18+
public class CreateTicketContext : ResultContext<OAuthIntrospectionOptions>
1919
{
2020
public CreateTicketContext(
2121
[NotNull] HttpContext context,
22+
[NotNull] AuthenticationScheme scheme,
2223
[NotNull] OAuthIntrospectionOptions options,
2324
[NotNull] AuthenticationTicket ticket,
2425
[NotNull] JObject payload)
25-
: base(context)
26+
: base(context, scheme, options)
2627
{
27-
Options = options;
28-
Ticket = ticket;
28+
Principal = ticket.Principal;
29+
Properties = ticket.Properties;
2930
Payload = payload;
3031
}
3132

32-
/// <summary>
33-
/// Gets the options used by the introspection middleware.
34-
/// </summary>
35-
public OAuthIntrospectionOptions Options { get; }
36-
3733
/// <summary>
3834
/// Gets the identity containing the user claims.
3935
/// </summary>
4036
public ClaimsIdentity Identity => Principal?.Identity as ClaimsIdentity;
4137

42-
/// <summary>
43-
/// Gets the principal containing the user claims.
44-
/// </summary>
45-
public ClaimsPrincipal Principal => Ticket?.Principal;
46-
4738
/// <summary>
4839
/// Gets the payload extracted from the introspection response.
4940
/// </summary>

src/AspNet.Security.OAuth.Introspection/Events/RetrieveTokenContext.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,16 @@ namespace AspNet.Security.OAuth.Introspection
1313
/// <summary>
1414
/// Allows custom parsing of access tokens from requests.
1515
/// </summary>
16-
public class RetrieveTokenContext : BaseControlContext
16+
public class RetrieveTokenContext : ResultContext<OAuthIntrospectionOptions>
1717
{
1818
public RetrieveTokenContext(
1919
[NotNull] HttpContext context,
20+
[NotNull] AuthenticationScheme scheme,
2021
[NotNull] OAuthIntrospectionOptions options)
21-
: base(context)
22+
: base(context, scheme, options)
2223
{
23-
Options = options;
2424
}
2525

26-
/// <summary>
27-
/// Gets the options used by the introspection middleware.
28-
/// </summary>
29-
public OAuthIntrospectionOptions Options { get; }
30-
3126
/// <summary>
3227
/// Gets or sets the access token.
3328
/// </summary>

src/AspNet.Security.OAuth.Introspection/Events/SendIntrospectionRequestContext.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,20 @@ namespace AspNet.Security.OAuth.Introspection
1414
/// <summary>
1515
/// Allows for custom handling of the call to the Authorization Server's Introspection endpoint.
1616
/// </summary>
17-
public class SendIntrospectionRequestContext : BaseControlContext
17+
public class SendIntrospectionRequestContext : BaseContext<OAuthIntrospectionOptions>
1818
{
1919
public SendIntrospectionRequestContext(
2020
[NotNull] HttpContext context,
21+
[NotNull] AuthenticationScheme scheme,
2122
[NotNull] OAuthIntrospectionOptions options,
2223
[NotNull] HttpRequestMessage request,
2324
[NotNull] string token)
24-
: base(context)
25+
: base(context, scheme, options)
2526
{
26-
Options = options;
2727
Request = request;
2828
Token = token;
2929
}
3030

31-
/// <summary>
32-
/// Gets the options used by the introspection middleware.
33-
/// </summary>
34-
public OAuthIntrospectionOptions Options { get; }
35-
3631
/// <summary>
3732
/// An <see cref="HttpClient"/> for use by the application to call the authorization server.
3833
/// </summary>
@@ -52,5 +47,15 @@ public SendIntrospectionRequestContext(
5247
/// The access token parsed from the client request.
5348
/// </summary>
5449
public string Token { get; }
50+
51+
/// <summary>
52+
/// Gets a boolean indicating if the operation was handled from user code.
53+
/// </summary>
54+
public bool Handled { get; private set; }
55+
56+
/// <summary>
57+
/// Marks the operation as handled to prevent the default logic from being applied.
58+
/// </summary>
59+
public void HandleResponse() => Handled = true;
5560
}
5661
}

0 commit comments

Comments
 (0)