Closed dougbu closed 6 years ago
So... is the suggestion to just add AllowAnonymous to the two pages that should allow anonymous?
Yes, exactly. Sorry for leaving that out.
OK so a 2-line fix? That should be easy in RC1.
It's a 2-line fix unless other pages involved in resetting a password also need to be accessible before user logs in again.
After lowering the lockout attempts to 2
i.e. services.AddDefaultIdentity<IdentityUser>(options => options.Lockout.MaxFailedAccessAttempts = 2)
, I found the /Identity/Account/Lockout page also needs [AllowAnonymous]
on its page model class. Without this, user is redirected to login page again.
Related question: Should the /Identity/Account/AccessDenied page have [AllowAnonymous]
? This page doesn't appear to be used by default and I'm unsure where it would be used.
Might have missed other pages that should allow anonymous access for specific scenarios.
Access denied is for someone whose permissions failed auth - so they are logged in, just they don't have access. So it doesn't need allow anonymous, it's point is that someone is logged in.
Looks like at least one page was missed when fixing #1617
Repro steps
dotnet new mvc --name netcoreIndividualAuth --auth Individual --use-local-db
(doubt--use-local-db
is mandatory)cd netcoreIndividualAuth
Open project in Visual Studio
Edit
Startup.ConfigureServices(...)
to require an authenticated user globally i.e. changeservices.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
toStart app in the debugger
Ensure debug option "Enable Just My Code" is disabled and "Microsoft Symbol Servers" are enabled under "Symbols"
Set C# function breakpoint at
Microsoft.AspNetCore.Identity.UI.Services.EmailSender.SendEmailAsync
In browser, register a new user
In debugger, copy the URL in the
htmlMessage
parameterIn browser, head to the copied URL but change
&code
to&code
In browser, log out, click on "Forgot your password", then enter the new user's email and click Submit
In debugger, copy the URL in the
htmlMessage
parameterIn browser, head to the copied URL
Expected
Actual
Redirected to the login page again in both cases i.e. both page models lack
[AllowAnonymous]
though the lack in /Identity/Account/ResetPassword is more troublesome.This is a small part of #1617 which does not work end-to-end. Found while verifying (aspnet/Release#263) with the 2.1.300-preview2-008523 SDK and Microsoft.AspNetCore.Identity.UI 2.1.0-preview2-30552.