Skip to content

Commit 0c0bc01

Browse files
[release/8.0-preview7] Add more MapIdentityApi endpoints (#49559)
Backport of #49498 to release/8.0-preview7 /cc @halter73 # Add more MapIdentityApi endpoints ## Description This adds the following new endpoints: - GET /confirmEmail - POST /resendConfirmationEmail - POST /resetPassword - GET /account/2fa - POST /account/2fa - GET /account/info - POST /account/info Additionally, the existing /login endpoint now accepts 2fa codes and 2fa recovery codes as part of the request body. These can be queried and regenerated from /account/2fa. The /login endpoint now also gives limited failure reasons in the form of application/problem+json instead of empty 401 responses with details such as "LockedOut", "RequiresTwoFactor", "NotAllowed" (usually because lack of email confirmation), and the generic "Failed" statuses. Fixes #47232 (lockout support) Fixes #47231 (reset password support) Fixes #47230 (2fa support) Fixes #47229 (change username and password) Fixes #49404 (Removes AddIdentityBearerToken which is no longer needed) ## Customer Impact This makes the MapIdentityApi API introduced in preview4 more usable. See https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-8-preview-4/#auth where we promised the following. > In addition to user registration and login, the identity API endpoints will support features like two-factor authentication and email verification in upcoming previews. You can find a list of planned features in the issues labeled [feature-token-identity](https://github.com/dotnet/aspnetcore/issues?q=is%3Aopen+label%3Afeature-token-identity+sort%3Aupdated-desc) on the ASP.NET Core GitHub repository. This PR adds all of these features, and it's important to make this available to customers as soon as possible, so we have time to react to any feedback. It appears customers are [excited to give it a go.](https://www.reddit.com/r/programming/comments/13jxcsx/aspnet_core_updates_in_net_8_preview_4_net_blog/jki0p3g/) ## Regression? - [ ] Yes - [x] No ## Risk - [ ] High - [ ] Medium - [x] Low This is primarily new API with minimal changes to SignInManager that should have no impact unless used by the new MapIdentityApi endpoints. ## Verification - [x] Manual (required) - [x] Automated ## Packaging changes reviewed? - [ ] Yes - [ ] No - [x] N/A
1 parent 2922b05 commit 0c0bc01

34 files changed

+1811
-219
lines changed

src/Http/Routing/src/EndpointNameMetadata.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Diagnostics;
45
using Microsoft.AspNetCore.Http;
56
using Microsoft.AspNetCore.Shared;
67

@@ -13,6 +14,7 @@ namespace Microsoft.AspNetCore.Routing;
1314
/// Endpoint names must be unique within an application, and can be used to unambiguously
1415
/// identify a desired endpoint for URI generation using <see cref="LinkGenerator"/>.
1516
/// </remarks>
17+
[DebuggerDisplay("{ToString(),nq}")]
1618
public class EndpointNameMetadata : IEndpointNameMetadata
1719
{
1820
/// <summary>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.AspNetCore.Identity.DTO;
5+
6+
internal sealed class TwoFactorResponse
7+
{
8+
public required string SharedKey { get; init; }
9+
public required int RecoveryCodesLeft { get; init; }
10+
public string[]? RecoveryCodes { get; init; }
11+
public required bool IsTwoFactorEnabled { get; init; }
12+
public required bool IsMachineRemembered { get; init; }
13+
}

src/Identity/Core/src/DTO/IdentityEndpointsJsonSerializerContext.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ namespace Microsoft.AspNetCore.Identity.DTO;
77

88
[JsonSerializable(typeof(RegisterRequest))]
99
[JsonSerializable(typeof(LoginRequest))]
10+
[JsonSerializable(typeof(RefreshRequest))]
11+
[JsonSerializable(typeof(ResetPasswordRequest))]
12+
[JsonSerializable(typeof(ResendEmailRequest))]
13+
[JsonSerializable(typeof(InfoRequest))]
14+
[JsonSerializable(typeof(InfoResponse))]
15+
[JsonSerializable(typeof(TwoFactorRequest))]
16+
[JsonSerializable(typeof(TwoFactorResponse))]
1017
internal sealed partial class IdentityEndpointsJsonSerializerContext : JsonSerializerContext
1118
{
1219
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.AspNetCore.Identity.DTO;
5+
6+
internal sealed class InfoRequest
7+
{
8+
public string? NewUsername { get; init; }
9+
public string? NewEmail { get; init; }
10+
public string? NewPassword { get; init; }
11+
public string? OldPassword { get; init; }
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.AspNetCore.Identity.DTO;
5+
6+
internal sealed class InfoResponse
7+
{
8+
public required string Username { get; init; }
9+
public required string Email { get; init; }
10+
public required IDictionary<string, string> Claims { get; init; }
11+
}

src/Identity/Core/src/DTO/LoginRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ internal sealed class LoginRequest
77
{
88
public required string Username { get; init; }
99
public required string Password { get; init; }
10+
public string? TwoFactorCode { get; init; }
11+
public string? TwoFactorRecoveryCode { get; init; }
1012
}

src/Identity/Core/src/DTO/RegisterRequest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ internal sealed class RegisterRequest
77
{
88
public required string Username { get; init; }
99
public required string Password { get; init; }
10+
public required string Email { get; init; }
1011
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.AspNetCore.Identity.DTO;
5+
6+
internal sealed class ResendEmailRequest
7+
{
8+
public required string Email { get; init; }
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.AspNetCore.Identity.DTO;
5+
6+
internal sealed class ResetPasswordRequest
7+
{
8+
public required string Email { get; init; }
9+
public string? ResetCode { get; init; }
10+
public string? NewPassword { get; init; }
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.AspNetCore.Identity.DTO;
5+
6+
internal sealed class TwoFactorRequest
7+
{
8+
public bool? Enable { get; init; }
9+
public string? TwoFactorCode { get; init; }
10+
11+
public bool ResetSharedKey { get; init; }
12+
public bool ResetRecoveryCodes { get; init; }
13+
public bool ForgetMachine { get; init; }
14+
}

0 commit comments

Comments
 (0)