|
1 | | -// Copyright (c) Dominick Baier & Brock Allen. All rights reserved. |
| 1 | +// Copyright (c) Dominick Baier & Brock Allen. All rights reserved. |
2 | 2 | // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. |
3 | 3 |
|
4 | 4 | using System; |
@@ -110,7 +110,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync() |
110 | 110 | { |
111 | 111 | Lazy<Task<TokenIntrospectionResponse>> GetTokenIntrospectionResponseLazy(string _) |
112 | 112 | { |
113 | | - return new Lazy<Task<TokenIntrospectionResponse>>(async () => await LoadClaimsForToken(token, Options)); |
| 113 | + return new Lazy<Task<TokenIntrospectionResponse>>(async () => await LoadClaimsForToken(token, Context, Scheme, Events, Options)); |
114 | 114 | } |
115 | 115 |
|
116 | 116 | var response = await IntrospectionDictionary |
@@ -175,10 +175,56 @@ private static async Task<AuthenticateResult> ReportNonSuccessAndReturn( |
175 | 175 | return AuthenticateResult.Fail(error); |
176 | 176 | } |
177 | 177 |
|
178 | | - private static async Task<TokenIntrospectionResponse> LoadClaimsForToken(string token, OAuth2IntrospectionOptions options) |
| 178 | + private static async Task<TokenIntrospectionResponse> LoadClaimsForToken( |
| 179 | + string token, |
| 180 | + HttpContext context, |
| 181 | + AuthenticationScheme scheme, |
| 182 | + OAuth2IntrospectionEvents events, |
| 183 | + OAuth2IntrospectionOptions options) |
179 | 184 | { |
180 | 185 | var introspectionClient = await options.IntrospectionClient.Value.ConfigureAwait(false); |
181 | | - return await introspectionClient.Introspect(token, options.TokenTypeHint).ConfigureAwait(false); |
| 186 | + using var request = CreateTokenIntrospectionRequest(token, context, scheme, events, options); |
| 187 | + return await introspectionClient.IntrospectTokenAsync(request).ConfigureAwait(false); |
| 188 | + } |
| 189 | + |
| 190 | + private static TokenIntrospectionRequest CreateTokenIntrospectionRequest( |
| 191 | + string token, |
| 192 | + HttpContext context, |
| 193 | + AuthenticationScheme scheme, |
| 194 | + OAuth2IntrospectionEvents events, |
| 195 | + OAuth2IntrospectionOptions options) |
| 196 | + { |
| 197 | + if (options.ClientSecret == null && options.ClientAssertionExpirationTime <= DateTime.UtcNow) |
| 198 | + { |
| 199 | + lock (options.AssertionUpdateLockObj) |
| 200 | + { |
| 201 | + if (options.ClientAssertionExpirationTime <= DateTime.UtcNow) |
| 202 | + { |
| 203 | + var updateClientAssertionContext = new UpdateClientAssertionContext(context, scheme, options) |
| 204 | + { |
| 205 | + ClientAssertion = options.ClientAssertion ?? new ClientAssertion() |
| 206 | + }; |
| 207 | + |
| 208 | + events.UpdateClientAssertion(updateClientAssertionContext); |
| 209 | + |
| 210 | + options.ClientAssertion = updateClientAssertionContext.ClientAssertion; |
| 211 | + options.ClientAssertionExpirationTime = |
| 212 | + updateClientAssertionContext.ClientAssertionExpirationTime; |
| 213 | + } |
| 214 | + } |
| 215 | + } |
| 216 | + |
| 217 | + return new TokenIntrospectionRequest |
| 218 | + { |
| 219 | + Token = token, |
| 220 | + TokenTypeHint = options.TokenTypeHint, |
| 221 | + Address = options.IntrospectionEndpoint, |
| 222 | + ClientId = options.ClientId, |
| 223 | + ClientSecret = options.ClientSecret, |
| 224 | + ClientAssertion = options.ClientAssertion ?? new ClientAssertion(), |
| 225 | + ClientCredentialStyle = options.ClientCredentialStyle, |
| 226 | + AuthorizationHeaderStyle = options.AuthorizationHeaderStyle, |
| 227 | + }; |
182 | 228 | } |
183 | 229 |
|
184 | 230 | private static async Task<AuthenticateResult> CreateTicket( |
|
0 commit comments