-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[release/8.0-preview4] Add MapIdentityApi<TUser>() #47927
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
[release/8.0-preview4] Add MapIdentityApi<TUser>() #47927
Conversation
Hi @halter73. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge. To learn more about how to prepare a servicing PR click here. |
Hi @halter73. This PR was just approved to be included in the upcoming servicing release. Somebody from the @dotnet/aspnet-build team will get it merged when the branches are open. Until then, please make sure all the CI checks pass and the PR is reviewed. |
@dotnet/aspnet-build Can someone please merge this? Thanks! |
@halter73 Not sure whether this is the best to place to enquire info about this, but here goes nothing. As I understand this change supports scenarios when one would use the "with React" template for a new project with "Individual Login" (which in turn means using Identity). Cool stuff 👏 My question: when rolling our own AccountController or such with a Login endpoint is there/will there be any new features/changes in .NET 8 (preview?) regarding not using Identity only cookie authn? For example, currently using cookie authn in such a scenario builder.Services.AddAuthentication()
.AddCookie(); and having a reeeaallllllly simple an endpoint for login like [HttpPost("Login")]
public async Task<IActionResult> Login([FromForm]string email, [FromForm]string password)
{
if (email != "admin@admin" && password != "admin")
{
return Unauthorized();
}
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
... when protecting endpoints like [HttpGet]
[Authorize]
public string Secret()
{
return "Only can see this after login.";
} one would receive 302 HTTP responses redirecting to Some context: I'm a developer/educator and this particular weirdness trips up newcomers to the .NET/ASP.NET + SPA ecosystem in particular. (Lot of things to trip up upon :D) Thank you for your time! |
Hi @kohanyirobert. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Backport of #47414 to release/8.0-preview4
Add
MapIdentityApi<TUser>()
This adds new API to add Identity API endpoints for user registration and login supporting both cookies and opaque bearer tokens. To support this, this PR also adds a
BearerTokenHandler
for authentication.Description
MapIdentity<TUser>()
adds two new API endpoints (/register
and/login
) to theIEndpointRouteBuilder
(typically aWebApplication
orRouteGroupBuilder
). Additional features like 2fa and email verification will come in preview 5. See https://github.com/dotnet/aspnetcore/issues?q=is%3Aopen+label%3Afeature-token-identity+sort%3Aupdated-desc for a comprehensive list of planned features.Usage Example
Server
Bearer token and cookies enabled
Client
Assume
httpClient
,username
andpassword
are already initialized.Register
Login (Bearer token)
Login (Cookie)
Customer Impact
This allows customers to give feedback on our early work to improve the identity experience for SPA and mobile applications. #42158 which is about improving the is experience is one of aspnetcore's most upvoted issues.
Regression?
Risk
This PR mostly adds new API. The only other impact is adding new assembly to the aspnetcore shared runtime (Microsoft.AspNetCore.Authentication.BearerToken.dll) and marking Microsoft.AspNetCore.Identity.dll as non-trimmable.
Verification
Packaging changes reviewed?
Is there anyone specifically who should review the addition of Microsoft.AspNetCore.Authentication.BearerToken to the aspnetcore shared runtime?