Skip to content

Implemented the JWT Token refresh logic through the OpenIdConnectHandler #61861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Authentication.OpenIdConnect.Events;

namespace Microsoft.AspNetCore.Authentication.OpenIdConnect;

/// <summary>
Expand Down Expand Up @@ -66,6 +68,16 @@
/// </summary>
public Func<PushedAuthorizationContext, Task> OnPushAuthorization { get; set; } = context => Task.CompletedTask;

/// <summary>
/// Invoked when the the token needs to be refreshed.
/// </summary>
public Func<TokenRefreshContext, Task> OnTokenRefreshing { get; set; } = context => Task.CompletedTask;

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: macOS x64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,64): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: macOS x64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,69): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,64): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,69): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: macOS arm64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,64): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: macOS arm64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,69): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux ARM)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,64): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux ARM)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,69): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl x64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,64): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl x64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,69): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl ARM64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,64): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl ARM64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,69): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: macOS)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,64): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: macOS)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,69): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl ARM)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,69): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: Ubuntu x64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,64): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: Ubuntu x64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,69): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: Ubuntu x64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,69): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,64): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 74 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L74

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(74,69): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshing.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

/// <summary>
/// Invoked immedaitely after the ticket has been refreshed.
/// </summary>
public Func<TokenRefreshContext, Task> OnTokenRefreshed { get; set; } = context => Task.CompletedTask;

Check failure on line 79 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: macOS x64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L79

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(79,63): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshed.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 79 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L79

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(79,63): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshed.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 79 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: macOS arm64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L79

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(79,63): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshed.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 79 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux ARM)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L79

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(79,63): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshed.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 79 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl x64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L79

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(79,63): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshed.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 79 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl ARM64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L79

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(79,63): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshed.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 79 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl ARM)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L79

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(79,63): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshed.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 79 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl ARM)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L79

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(79,68): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshed.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 79 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: Ubuntu x64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L79

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(79,63): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshed.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 79 in src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: Ubuntu x64)

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs#L79

src/Security/Authentication/OpenIdConnect/src/Events/OpenIdConnectEvents.cs(79,68): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OnTokenRefreshed.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

/// <summary>
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
/// </summary>
Expand Down Expand Up @@ -125,4 +137,8 @@
/// <param name="context"></param>
/// <returns></returns>
public virtual Task PushAuthorization(PushedAuthorizationContext context) => OnPushAuthorization(context);

public virtual Task TokenRefreshing(TokenRefreshContext context) => OnTokenRefreshing(context);

public virtual Task TokenRefreshed(TokenRefreshContext context) => OnTokenRefreshed(context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Security.Claims;
using Microsoft.AspNetCore.Http;

namespace Microsoft.AspNetCore.Authentication.OpenIdConnect.Events;

/// <summary>
/// Represents a context for the TokenRefresh and TokenRefreshing events.
/// </summary>
public class TokenRefreshContext : RemoteAuthenticationContext<OpenIdConnectOptions>

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: macOS x64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux x64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: macOS arm64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux ARM)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux ARM64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl x64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl ARM64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: macOS)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl ARM)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: Ubuntu x64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: Ubuntu x64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 12 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L12

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(12,14): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
{
/// <summary>
/// Gets or sets a value indicating whether the token should be refreshed by the OpenIdConnectHandler or not.
/// </summary>
/// <remarks>
/// The default value of this property is `true`, which indicates,
/// that the OpenIdConnectHandler should be responsible for refreshing the token.
/// However, custom handler can be registered for the <see cref="OpenIdConnectEvents.OnTokenRefreshing"/> event,
/// which may take the responsibility for updating the token. In that case,
/// the handler should set the <see cref="ShouldRefresh"/> to `false` to indicate that the token has already
/// been refreshed and the <see cref="OpenIdConnectHandler"/> shouldn't try to refresh it.
/// </remarks>
public bool ShouldRefresh { get; set; } = true;

Check failure on line 25 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux x64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L25

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(25,33): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'ShouldRefresh.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 25 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux x64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L25

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(25,38): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'ShouldRefresh.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 25 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux ARM64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L25

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(25,33): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'ShouldRefresh.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 25 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux ARM64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L25

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(25,38): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'ShouldRefresh.set' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 25 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L25

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(25,33): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'ShouldRefresh.get' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

/// <summary>
/// Creates a <see cref="TokenValidatedContext"/>
/// </summary>
/// <inheritdoc />
public TokenRefreshContext(HttpContext context, AuthenticationScheme scheme, OpenIdConnectOptions options, ClaimsPrincipal principal, AuthenticationProperties properties)

Check failure on line 31 in src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux ARM64)

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs#L31

src/Security/Authentication/OpenIdConnect/src/Events/TokenRefreshContext.cs(31,12): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'TokenRefreshContext' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
: base(context, scheme, options, properties)
=> Principal = principal;

/// <summary>
/// Called to replace the claims principal. The supplied principal will replace the value of the
/// Principal property, which determines the identity of the authenticated request.
/// </summary>
/// <param name="principal">The <see cref="ClaimsPrincipal"/> used as the replacement</param>
public void ReplacePrincipal(ClaimsPrincipal principal) => Principal = principal;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Authentication.OAuth" />
<Reference Include="Microsoft.AspNetCore.Authentication.Cookies" />
<Reference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OAuth;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Primitives;
Expand Down Expand Up @@ -1531,4 +1533,113 @@
ex.Data["error_uri"] = errorUri;
return ex;
}

/// <summary>
/// Handles the `ValidatePrincipal event fired from the underlying CookieAuthenticationHandler.
/// This is used for refreshing OIDC auth. token if needed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Suggested change
/// This is used for refreshing OIDC auth. token if needed.
/// This is used for refreshing OIDC auth token if needed.

/// </summary>
/// <param name="context">The CookieValidatePrincipalContext passed as part of the event.</param>
internal static async Task ValidatePrincipal(CookieValidatePrincipalContext context)
{
var authHandlerProvider = context.HttpContext.RequestServices.GetRequiredService<IAuthenticationHandlerProvider>();
var handler = await authHandlerProvider.GetHandlerAsync(context.HttpContext, context.Scheme.Name);
if (handler is OpenIdConnectHandler oidcHandler)
{
await oidcHandler.HandleValidatePrincipalAsync(context);
}
}

private async Task HandleValidatePrincipalAsync(CookieValidatePrincipalContext validateContext)
{
var accessTokenExpirationText = validateContext.Properties.GetTokenValue("expires_at");
if (!DateTimeOffset.TryParse(accessTokenExpirationText, out var accessTokenExpiration))
{
return;
}

var oidcOptions = this.OptionsMonitor.Get(validateContext.Scheme.Name);
var now = oidcOptions.TimeProvider!.GetUtcNow();
if (now + TimeSpan.FromMinutes(5) < accessTokenExpiration)
{
return;
}

var tokenRefreshContext = new Events.TokenRefreshContext(Context, Scheme, oidcOptions, validateContext.Principal!, validateContext.Properties);
await Options.Events.TokenRefreshing(tokenRefreshContext);
if (tokenRefreshContext.ShouldRefresh)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the tokenRefreshContext.Result be checked like the most of the events? Something like this:

if (tokenRefreshContext.Result != null)
{
    if (tokenRefreshContext.Result.Handled)
    {
        Logger.TokenRefreshingHandledResponse();
    }
    else if (tokenRefreshContext.Result.Skipped)
    {
        Logger.TokenRefreshingSkipped();
    }
}

{
var oidcConfiguration = await oidcOptions.ConfigurationManager!.GetConfigurationAsync(validateContext.HttpContext.RequestAborted);
var tokenEndpoint = oidcConfiguration.TokenEndpoint ?? throw new InvalidOperationException("Cannot refresh cookie. TokenEndpoint missing!");

using var refreshResponse = await oidcOptions.Backchannel.PostAsync(tokenEndpoint,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the TokenResponseReceived Event get called after getting a new token here?
As a user do I care if a token is generated with code or refresh_token grant type?

new FormUrlEncodedContent(new Dictionary<string, string?>()
{
["grant_type"] = "refresh_token",
["client_id"] = oidcOptions.ClientId,
["client_secret"] = oidcOptions.ClientSecret,
["scope"] = string.Join(" ", oidcOptions.Scope),
["refresh_token"] = validateContext.Properties.GetTokenValue("refresh_token"),
}));

if (!refreshResponse.IsSuccessStatusCode)
{
validateContext.RejectPrincipal();
return;
}

var refreshJson = await refreshResponse.Content.ReadAsStringAsync();
var message = new OpenIdConnectMessage(refreshJson);

var validationParameters = oidcOptions.TokenValidationParameters.Clone();
if (oidcOptions.ConfigurationManager is BaseConfigurationManager baseConfigurationManager)
{
validationParameters.ConfigurationManager = baseConfigurationManager;
}
else
{
validationParameters.ValidIssuer = oidcConfiguration.Issuer;
validationParameters.IssuerSigningKeys = oidcConfiguration.SigningKeys;
Comment on lines +1600 to +1601
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the other parameters need to be added like here?

var issuer = new[] { _configuration.Issuer };
validationParameters.ValidIssuers = validationParameters.ValidIssuers?.Concat(issuer) ?? issuer;
validationParameters.IssuerSigningKeys = validationParameters.IssuerSigningKeys?.Concat(_configuration.SigningKeys)
?? _configuration.SigningKeys;

}

var validationResult = await oidcOptions.TokenHandler.ValidateTokenAsync(message.IdToken, validationParameters);

if (!validationResult.IsValid)
{
validateContext.RejectPrincipal();
return;
}

var validatedIdToken = JwtSecurityTokenConverter.Convert(validationResult.SecurityToken as JsonWebToken);
validatedIdToken.Payload["nonce"] = null;
Options.ProtocolValidator.ValidateTokenResponse(new()
{
ProtocolMessage = message,
ClientId = oidcOptions.ClientId,
ValidatedIdToken = validatedIdToken,
});

var principal = new ClaimsPrincipal(validationResult.ClaimsIdentity);
validateContext.ReplacePrincipal(principal);
tokenRefreshContext.ReplacePrincipal(principal);

var expiresIn = int.Parse(message.ExpiresIn, NumberStyles.Integer, CultureInfo.InvariantCulture);
var expiresAt = now + TimeSpan.FromSeconds(expiresIn);
validateContext.Properties.StoreTokens([
new() { Name = "access_token", Value = message.AccessToken },
new() { Name = "id_token", Value = message.IdToken },
new() { Name = "refresh_token", Value = message.RefreshToken },
new() { Name = "token_type", Value = message.TokenType },
new() { Name = "expires_at", Value = expiresAt.ToString("o", CultureInfo.InvariantCulture) },
]);
}
else
{
// a handler for the `OpenIdConnectOptions.Events.TokenRefreshing` event has updated the principal,
// so we need to pass that down through the validateContext.
validateContext.ReplacePrincipal(tokenRefreshContext.Principal);

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: macOS x64)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux x64)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: macOS)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: macOS arm64)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux ARM)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux ARM64)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl x64)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl ARM64)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: macOS)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux Musl ARM)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr (Tests: Ubuntu x64)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: Ubuntu x64)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-quarantined-pr

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.

Check failure on line 1639 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs#L1639

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectHandler.cs(1639,46): error CS8604: (NETCORE_ENGINEERING_TELEMETRY=Build) Possible null reference argument for parameter 'principal' in 'void CookieValidatePrincipalContext.ReplacePrincipal(ClaimsPrincipal principal)'.
}

validateContext.ShouldRenew = true;
await Options.Events.TokenRefreshed(tokenRefreshContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Net.Http;
using System.Text;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Protocols;
Expand All @@ -16,14 +17,18 @@
public class OpenIdConnectPostConfigureOptions : IPostConfigureOptions<OpenIdConnectOptions>
{
private readonly IDataProtectionProvider _dp;
private readonly CookieAuthenticationOptions _cookieAuthenticationOptions;
private readonly IAuthenticationHandlerProvider _handlerProvider;

/// <summary>
/// Initializes a new instance of <see cref="OpenIdConnectPostConfigureOptions"/>.
/// </summary>
/// <param name="dataProtection">The <see cref="IDataProtectionProvider"/>.</param>
public OpenIdConnectPostConfigureOptions(IDataProtectionProvider dataProtection)
public OpenIdConnectPostConfigureOptions(IDataProtectionProvider dataProtection, CookieAuthenticationOptions cookieAuthenticationOptions, IAuthenticationHandlerProvider handlerProvider)

Check failure on line 27 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectPostConfigureOptions.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Build: Linux x64)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectPostConfigureOptions.cs#L27

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectPostConfigureOptions.cs(27,12): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OpenIdConnectPostConfigureOptions' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 27 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectPostConfigureOptions.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci (Build Test: macOS)

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectPostConfigureOptions.cs#L27

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectPostConfigureOptions.cs(27,12): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OpenIdConnectPostConfigureOptions' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Check failure on line 27 in src/Security/Authentication/OpenIdConnect/src/OpenIdConnectPostConfigureOptions.cs

View check run for this annotation

Azure Pipelines / aspnetcore-ci

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectPostConfigureOptions.cs#L27

src/Security/Authentication/OpenIdConnect/src/OpenIdConnectPostConfigureOptions.cs(27,12): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build) Symbol 'OpenIdConnectPostConfigureOptions' is not part of the declared API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)
{
_dp = dataProtection;
_cookieAuthenticationOptions = cookieAuthenticationOptions;
_handlerProvider = handlerProvider;
}

/// <summary>
Expand Down Expand Up @@ -105,6 +110,8 @@
};
}
}

_cookieAuthenticationOptions?.Events.OnValidatePrincipal = OpenIdConnectHandler.ValidatePrincipal;
}

private sealed class StringSerializer : IDataSerializer<string>
Expand Down
Loading