Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 9e9e5be

Browse files
Added code comments
1 parent 9ca5684 commit 9e9e5be

8 files changed

+86
-4
lines changed

src/IdentityModel.AspNetCore.OAuth2Introspection/IdentityModel.AspNetCore.OAuth2Introspection.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>ASP.NET Core 2.0 Middleware for validating tokens using OAuth 2.0 introspection</Description>
5-
<VersionPrefix>3.0.0</VersionPrefix>
5+
<VersionPrefix>3.0.1</VersionPrefix>
66
<!--<VersionSuffix>rc2</VersionSuffix>-->
77
<Authors>Dominick Baier;Brock Allen</Authors>
88
<TargetFrameworks>netstandard2.0</TargetFrameworks>
@@ -15,6 +15,14 @@
1515
<RepositoryUrl>git://github.com/identitymodel/identitymodel.aspnetcore.oauth2introspection</RepositoryUrl>
1616
</PropertyGroup>
1717

18+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
19+
<DocumentationFile>bin\Release\netstandard2.0\IdentityModel.AspNetCore.OAuth2Introspection.xml</DocumentationFile>
20+
</PropertyGroup>
21+
22+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
23+
<DocumentationFile>bin\Debug\netstandard2.0\IdentityModel.AspNetCore.OAuth2Introspection.xml</DocumentationFile>
24+
</PropertyGroup>
25+
1826
<ItemGroup>
1927
<PackageReference Include="SourceLink.Embed.AllSourceFiles" Version="2.4.0" PrivateAssets="all" />
2028
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.0.0" />

src/IdentityModel.AspNetCore.OAuth2Introspection/Infrastructure/AsyncLazy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
namespace IdentityModel.AspNetCore.OAuth2Introspection.Infrastructure
88
{
9-
public class AsyncLazy<T> : Lazy<Task<T>>
9+
internal class AsyncLazy<T> : Lazy<Task<T>>
1010
{
1111
public AsyncLazy(Func<Task<T>> taskFactory) :
1212
base(() => Task.Factory.StartNew(taskFactory).Unwrap())
1313
{ }
1414
}
15-
}
15+
}

src/IdentityModel.AspNetCore.OAuth2Introspection/Infrastructure/TokenRetrieval.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@
77

88
namespace IdentityModel.AspNetCore.OAuth2Introspection
99
{
10+
/// <summary>
11+
/// Defines some common token retrieval strategies
12+
/// </summary>
1013
public static class TokenRetrieval
1114
{
15+
/// <summary>
16+
/// Reads the token from the authrorization header.
17+
/// </summary>
18+
/// <param name="scheme">The scheme (defaults to Bearer).</param>
19+
/// <returns></returns>
1220
public static Func<HttpRequest, string> FromAuthorizationHeader(string scheme = "Bearer")
1321
{
1422
return (request) =>
@@ -29,6 +37,11 @@ public static Func<HttpRequest, string> FromAuthorizationHeader(string scheme =
2937
};
3038
}
3139

40+
/// <summary>
41+
/// Reads the token from a query string parameter.
42+
/// </summary>
43+
/// <param name="name">The name (defaults to access_token).</param>
44+
/// <returns></returns>
3245
public static Func<HttpRequest, string> FromQueryString(string name = "access_token")
3346
{
3447
return (request) => request.Query[name].FirstOrDefault();

src/IdentityModel.AspNetCore.OAuth2Introspection/OAuth2IntrospectionDefaults.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33

44
namespace IdentityModel.AspNetCore.OAuth2Introspection
55
{
6+
/// <summary>
7+
/// Defaults for OAuth 2.0 introspection authentication
8+
/// </summary>
69
public class OAuth2IntrospectionDefaults
710
{
11+
/// <summary>
12+
/// Gets the default authentication scheme.
13+
/// </summary>
14+
/// <value>
15+
/// The authentication scheme.
16+
/// </value>
817
public static string AuthenticationScheme => "Bearer";
918
}
1019
}

src/IdentityModel.AspNetCore.OAuth2Introspection/OAuth2IntrospectionExtensions.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,45 @@
1010

1111
namespace Microsoft.Extensions.DependencyInjection
1212
{
13+
/// <summary>
14+
/// Extensions for registering the OAuth 2.0 introspection authentication handler
15+
/// </summary>
1316
public static class OAuth2IntrospectionExtensions
1417
{
18+
/// <summary>
19+
/// Adds the OAuth 2.0 introspection handler.
20+
/// </summary>
21+
/// <param name="builder">The builder.</param>
22+
/// <returns></returns>
1523
public static AuthenticationBuilder AddOAuth2Introspection(this AuthenticationBuilder builder)
1624
=> builder.AddOAuth2Introspection(OAuth2IntrospectionDefaults.AuthenticationScheme);
1725

26+
/// <summary>
27+
/// Adds the OAuth 2.0 introspection handler.
28+
/// </summary>
29+
/// <param name="builder">The builder.</param>
30+
/// <param name="authenticationScheme">The authentication scheme.</param>
31+
/// <returns></returns>
1832
public static AuthenticationBuilder AddOAuth2Introspection(this AuthenticationBuilder builder, string authenticationScheme)
1933
=> builder.AddOAuth2Introspection(authenticationScheme, configureOptions: null);
2034

35+
/// <summary>
36+
/// Adds the OAuth 2.0 introspection handler.
37+
/// </summary>
38+
/// <param name="services">The services.</param>
39+
/// <param name="configureOptions">The configure options.</param>
40+
/// <returns></returns>
2141
public static AuthenticationBuilder AddOAuth2Introspection(this AuthenticationBuilder services, Action<OAuth2IntrospectionOptions> configureOptions)
2242
=> services.AddOAuth2Introspection(OAuth2IntrospectionDefaults.AuthenticationScheme, configureOptions: configureOptions);
2343

44+
45+
/// <summary>
46+
/// Adds the OAuth 2.0 introspection handler.
47+
/// </summary>
48+
/// <param name="builder">The builder.</param>
49+
/// <param name="authenticationScheme">The authentication scheme.</param>
50+
/// <param name="configureOptions">The configure options.</param>
51+
/// <returns></returns>
2452
public static AuthenticationBuilder AddOAuth2Introspection(this AuthenticationBuilder builder, string authenticationScheme, Action<OAuth2IntrospectionOptions> configureOptions)
2553
{
2654
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<OAuth2IntrospectionOptions>, PostConfigureOAuth2IntrospectionOptions>());

src/IdentityModel.AspNetCore.OAuth2Introspection/OAuth2IntrospectionHandler.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,22 @@
1616

1717
namespace IdentityModel.AspNetCore.OAuth2Introspection
1818
{
19+
/// <summary>
20+
/// Authentication handler for OAuth 2.0 introspection
21+
/// </summary>
1922
public class OAuth2IntrospectionHandler : AuthenticationHandler<OAuth2IntrospectionOptions>
2023
{
2124
private readonly IDistributedCache _cache;
2225
private readonly ILogger<OAuth2IntrospectionHandler> _logger;
2326

27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="OAuth2IntrospectionHandler"/> class.
29+
/// </summary>
30+
/// <param name="options">The options.</param>
31+
/// <param name="urlEncoder">The URL encoder.</param>
32+
/// <param name="clock">The clock.</param>
33+
/// <param name="loggerFactory">The logger factory.</param>
34+
/// <param name="cache">The cache.</param>
2435
public OAuth2IntrospectionHandler(
2536
IOptionsMonitor<OAuth2IntrospectionOptions> options,
2637
UrlEncoder urlEncoder,
@@ -33,6 +44,10 @@ public OAuth2IntrospectionHandler(
3344
_cache = cache;
3445
}
3546

47+
/// <summary>
48+
/// Tries to authenticate a reference token on the current request
49+
/// </summary>
50+
/// <returns></returns>
3651
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
3752
{
3853
string token = Options.TokenRetriever(Context.Request);

src/IdentityModel.AspNetCore.OAuth2Introspection/OAuth2IntrospectionOptions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ public class OAuth2IntrospectionOptions : AuthenticationSchemeOptions
102102
internal AsyncLazy<IntrospectionClient> IntrospectionClient { get; set; }
103103
internal ConcurrentDictionary<string, AsyncLazy<IntrospectionResponse>> LazyIntrospections { get; set; }
104104

105+
/// <summary>
106+
/// Check that the options are valid. Should throw an exception if things are not ok.
107+
/// </summary>
108+
/// <exception cref="InvalidOperationException">
109+
/// You must either set Authority or IntrospectionEndpoint
110+
/// or
111+
/// You must either set a ClientId or set an introspection HTTP handler
112+
/// </exception>
113+
/// <exception cref="ArgumentException">TokenRetriever must be set - TokenRetriever</exception>
105114
public override void Validate()
106115
{
107116
base.Validate();

src/IdentityModel.AspNetCore.OAuth2Introspection/PostConfigureOAuth2IntrospectionOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace IdentityModel.AspNetCore.OAuth2Introspection
1414
{
15-
public class PostConfigureOAuth2IntrospectionOptions : IPostConfigureOptions<OAuth2IntrospectionOptions>
15+
internal class PostConfigureOAuth2IntrospectionOptions : IPostConfigureOptions<OAuth2IntrospectionOptions>
1616
{
1717
private readonly IDistributedCache _cache;
1818

0 commit comments

Comments
 (0)