Given the extra info in your comment. This appears to work the same way you should do a password reset.
For a password reset you include a one-time password reset token in the request (along with the password/verified password etc.) I would explicitly decorate the action with [AllowAnonymous]
and validate the token in the before updating any details and cancelling the token.
In your case, I would do the same thing - explicitly decorate the action with [AllowAnonymous]
and validate the one-time token. Your action shouldn't care whether the AllowAnonymous
filter has been applied to the Action via the attribute or options.
UPDATE
Been thinking a bit more and there's an easy way to disable this based on the build configuration. Wrap the attribute in an #if
preprocessor directive and create a build configuration that defines a conditional compliation symbol. See this answer for details
#if DISABLE_ALLOW_ANONYOMOUS
[AllowAnonymous]
#endif
public IActionResult GetPicture(string token){
...
You can then build a test specific version where AllowAnonymous
is disabled.
You could also do the same with MvcOptions:
#if DISABLE_ALLOW_ANONYOMOUS
opts.Filters.Add(new AllowAnonymousFilter());
#endif