|
6 | 6 | // --
|
7 | 7 | // License: MIT
|
8 | 8 | // *************************************************************
|
| 9 | + |
9 | 10 | namespace GraphQL.AspNet.Middleware.SchemaItemSecurity.Components
|
10 | 11 | {
|
11 | 12 | using System;
|
@@ -47,22 +48,25 @@ public SchemaItemAuthenticationMiddleware(IAuthenticationSchemeProvider schemePr
|
47 | 48 | /// <inheritdoc />
|
48 | 49 | public async Task InvokeAsync(SchemaItemSecurityChallengeContext context, GraphMiddlewareInvocationDelegate<SchemaItemSecurityChallengeContext> next, CancellationToken cancelToken = default)
|
49 | 50 | {
|
50 |
| - context.Logger?.SchemaItemAuthenticationChallenge(context); |
51 |
| - |
52 | 51 | // only attempt an authentication
|
53 | 52 | // if no result is already deteremined and if no user has already been authenticated
|
54 |
| - IAuthenticationResult authenticationResult = null; |
| 53 | + // |
| 54 | + // if a piece of middleware has already set an authenticated user |
| 55 | + // just skip this component. |
55 | 56 | if (context.Result == null && context.AuthenticatedUser == null)
|
56 | 57 | {
|
| 58 | + context.Logger?.SchemaItemAuthenticationChallenge(context); |
| 59 | + IAuthenticationResult authenticationResult = null; |
| 60 | + |
57 | 61 | ClaimsPrincipal user;
|
58 | 62 | SchemaItemSecurityChallengeResult challengeResult;
|
59 | 63 |
|
60 | 64 | (user, authenticationResult, challengeResult) = await this.AuthenticateUser(context, cancelToken);
|
61 | 65 | context.AuthenticatedUser = user;
|
62 | 66 | context.Result = challengeResult;
|
63 |
| - } |
64 | 67 |
|
65 |
| - context.Logger?.SchemaItemAuthenticationChallengeResult(context, authenticationResult); |
| 68 | + context.Logger?.SchemaItemAuthenticationChallengeResult(context, authenticationResult); |
| 69 | + } |
66 | 70 |
|
67 | 71 | await next.Invoke(context, cancelToken).ConfigureAwait(false);
|
68 | 72 | }
|
|
0 commit comments