© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
1 reply
sonodan.

❔ Authorize attribute automatically triggering oauth scheme

Hi all.

I have a login endpoint that I want to call that will trigger my authenication scheme like so:

    [HttpGet]
    [Route("login")]
    [AllowAnonymous]
    public async Task Login()
    {
      await HttpContext.ChallengeAsync(
        RedditAuthenticationDefaults.AuthenticationScheme, new AuthenticationProperties()
        {
          RedirectUri = "https://localhost:7109/api/Accounts/register"
        });
    }
    [HttpGet]
    [Route("login")]
    [AllowAnonymous]
    public async Task Login()
    {
      await HttpContext.ChallengeAsync(
        RedditAuthenticationDefaults.AuthenticationScheme, new AuthenticationProperties()
        {
          RedirectUri = "https://localhost:7109/api/Accounts/register"
        });
    }


I also have another endpoint,
register
register
, which has an
[Authorize]
[Authorize]
attribute. I want to test that visiting the
Register
Register
controller before being authenticated returns an error code, but instead it automatically triggers a challenge to my auth provider, which isn't the intended behaviour I would like. I want users only to be able to authenticate using the login end point. Is there a way to override this behaviour?

    [HttpGet]
    [Route("register")]
    [Authorize]
    public async Task Register()
    {
      // controller logic
    }
    [HttpGet]
    [Route("register")]
    [Authorize]
    public async Task Register()
    {
      // controller logic
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Asp Net Core Authorize Attribute
C#CC# / help
4y ago
✅[Authorize] Doesn't Recognize Default Authentication Scheme?
C#CC# / help
12mo ago
✅ Authorize() Attribute is not working (SOLVED)
C#CC# / help
3y ago