Skip to content

Inconsistent refresh token field naming between /login and /refresh in Identity endpoints #49482

@ghost

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Currently, there is a lack of consistency between the /login and /refresh endpoints regarding the naming of the refresh token field. While the /login endpoint returns the field with the name refresh_token, the /refresh endpoint expects the field to be named refreshtoken (without an underscore). This inconsistency in field naming can lead to confusion and may result in errors when attempting to use the /refresh endpoint.

Expected Behavior

Both the /login and /refresh endpoints should consistently use the same field name for the refresh token. It is probably because the JsonPropertyName attribute is missing in the request model of the /refresh endpoint.

internal sealed class RefreshRequest
{
public required string RefreshToken { get; init; }
}

Steps To Reproduce

using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

builder.Services
    .AddAuthentication()
    .AddIdentityBearerToken<IdentityUser>();

builder.Services
    .AddIdentity<IdentityUser, IdentityRole>()
    .AddApiEndpoints()
    .AddEntityFrameworkStores<IdentityDbContext>();

builder.Services.AddDbContext<IdentityDbContext>(options =>
{
    options.UseSqlServer("Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=Identity;Integrated Security=SSPI;", b => b.MigrationsAssembly("WebApplication1"));
});

var app = builder.Build();

app.MapIdentityApi<IdentityUser>();

app.Run();

/login request:

curl --location 'https://localhost:7042/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "username": "john@domain.net",
    "password": "Password1234!"
}'

/login response:

{
    "token_type": "Bearer",
    "access_token": "CfDJ8BWcIFpA3QRIpFn4fo6KC...",
    "expires_in": 3600,
    "refresh_token": "CfDJ8BWcIFpA3QRIpFn4fo6KC..."
}

/refresh request:

curl --location 'https://localhost:7042/refresh' \
--header 'Content-Type: application/json' \
--data '{
    "refreshtoken": "CfDJ8BWcIFpA3QRIpFn4fo6KC..."
}'

Exceptions (if any)

No response

.NET Version

8.0.100-preview.6.23330.14

Anything else?

No response

Metadata

Metadata

Assignees

Labels

area-identityIncludes: Identity and providersbugThis issue describes a behavior which is not expected - a bug.feature-token-identity

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions