Skip to content

Security stamp validation for bearer tokens? #65001

@mguinness

Description

@mguinness

Does security stamp validation occur with bearer tokens when using Identity API endpoints?

For example, consider the following sample setup:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAuthorization();

builder.Services.AddIdentityCore<AppUser>()
    .AddEntityFrameworkStores<AppDbContext>()
    .AddApiEndpoints();

builder.Services.AddAuthentication()
    .AddBearerToken(IdentityConstants.BearerScheme); 

builder.Services.Configure<SecurityStampValidatorOptions>(options => 
{
    options.ValidationInterval = TimeSpan.FromMinutes(1);
});

var app = builder.Build();

app.UseAuthentication();
app.UseAuthorization();

app.MapIdentityApi<AppUser>();

I would anticipate using the following code would prevent this user from accessing endpoints with RequireAuthorization after several minutes with the configured ValidationInterval for SecurityStampValidatorOptions.

await userManager.SetLockoutEndDateAsync(user, DateTimeOffset.UtcNow.AddHours(12));
await userManager.UpdateSecurityStampAsync(user);

However, it doesn't appear to work. Looking at #47228 authored by @halter73 it makes reference to both security stamp validation and bearer tokens. But is that only during token refresh, i.e. ISecurityStampValidator only works with cookies?

Just trying to get my head around the concepts as the documentation is lacking in this respect and possibly needs addressing if my assumptions are incorrect.

Metadata

Metadata

Assignees

Labels

DocsThis issue tracks updating documentationarea-identityIncludes: Identity and providers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions