Skip to content

JwtBearerEvents might be null, despite being marked as not null #43313

@glatzert

Description

@glatzert

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The following code will throw a NullReferenceException:

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                .AddJwtBearer(o =>
                {
                    o.Events.OnMessageReceived += (ctx) => Task.CompletedTask;
                });

It will do so despite o.Events being flagged as not nullable.

Expected Behavior

o.Events is not null

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

6.0.400

Anything else?

/// <summary>
/// The object provided by the application to process events raised by the bearer authentication handler.
/// The application may implement the interface fully, or it may create an instance of JwtBearerEvents
/// and assign delegates only to the events it wants to process.
/// </summary>
public new JwtBearerEvents Events
{
get { return (JwtBearerEvents)base.Events!; }
set { base.Events = value; }
}

This should probably have JwtBearerEvents?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-authIncludes: Authn, Authz, OAuth, OIDC, Bearernullable

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions