Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure AD allow anonymous

Is it possible to use the AllowAnonymous attribute with Windows Azure AD?

I need a part of my web api to be anonymous, but not the actual website.

Any ideas?

like image 606
Knerd Avatar asked May 05 '26 07:05

Knerd


1 Answers

Azure AD does not need to support anonymous auth for you to be able to use the AllowAnonymous attribute in your WebAPI.

I believe what you desire is unauthenticated access to some controllers of the WebAPI. It is possible. See this .Net sample: https://github.com/AzureADSamples/WebAPI-ManuallyValidateJwt-DotNet/blob/master/TodoListService-ManualJwt/Global.asax.cs. It validates the token and sets the Thread.CurrentPrincipal if the token is valid and returns an error if it can't find a token.

For your WebAPI

  • you wont return an error here - but instead not set the Thread.CurrentPrincipal when no token is present.
  • then you will decorate your controllers with Authorize and AllowAnonymous attributes to disallow or allow anonymous access.
like image 191
Dushyant Gill Avatar answered May 08 '26 00:05

Dushyant Gill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!