cornflourblue / aspnet-core-3-signup-verification-api

ASP.NET Core 3.1 - Boilerplate API with Email Sign Up, Verification, Authentication & Forgot Password
https://jasonwatmore.com/post/2020/07/06/aspnet-core-3-boilerplate-api-with-email-sign-up-verification-authentication-forgot-password
MIT License
226 stars 93 forks source link

How to add the Authentication to other controllers #19

Open hussainsam opened 3 years ago

hussainsam commented 3 years ago

Hi, if we are using another controller, adding [authorize] to the controller or adding app.UseAuthentication or app.UseAuthorization would just wouldn't work. It just throws this error No authenticationScheme was specified, and there was no DefaultChallengeScheme found. Can you tell me how can I pass your AccountsController to my other controllers.

hedgybeats commented 2 years ago

@hussainsam This is because you have an [Authorize] attribute on a controller somewhere that is referencing the Authorize class in 'Microsoft.AspNetCore.Authorization' namespace rather than the namespace of the custom authorize attribute.

Make sure to remove all usings for 'Microsoft.AspNetCore.Authorization' from your controllers and then make sure you are using the namespace where the custom authrorize attribute is located