What is Authentication and Authorization in ASP.NET?
ASP.NET authentication and authorization explained through Forms Authentication, Windows Authentication, OAuth 2.0, JWT bearer tokens, and security approach selection.
What is Authentication and Authorization in ASP.NET?
Every application which exposes data needs to answer two questions. Who is making this request, and what is that caller allowed to do? When we are answering only the first question, a known user may still change a resource outside their responsibility. When we are answering neither question, the Application Programming Interface (API) becomes an open front door.
ASP.NET supports several authentication and authorization approaches for different environments. In this article, we are going to see Forms Authentication, Windows Authentication, OAuth 2.0 and JSON Web Token (JWT) bearer tokens, compare them, and discuss when each one is a suitable choice.
TL;DR Summary
- Authentication verifies the identity presented by a caller.
- Authorization decides which resource and action that identity can use.
- Forms Authentication is useful for server-rendered ASP.NET applications with application-managed users.
- Windows Authentication fits intranet applications in a domain-managed environment.
- OAuth 2.0 is for delegated authorization and API access.
- JWT is a token format, it is not a complete authentication protocol by itself.
- Use the simplest secure option which matches the client, trust boundary and business needs.
Challenges
Identity confusion
If an application treats a user identifier from a request body as proof of identity, the caller can impersonate another user. The identity must come from a validated authentication mechanism. Otherwise, an article editor may be treated as another editor simply because a request contained a different name.
Permission growth
An application can start with one user type and later need readers, editors, administrators and service accounts. A single IsAdmin check scattered through controllers becomes difficult to maintain. We should centralize authorization policy and make the consequence of each role clear.
Different client types
A browser rendering server-side pages, a domain-joined intranet client and a mobile application have different security constraints. Selecting one mechanism for every client creates friction or unsafe workarounds. The choice should depend on the client and trust boundary.
What is Authentication?
Authentication is the process of verifying the identity of a user, service or application.
In simple terms, authentication answers “who are you?”. ASP.NET then creates a principal which the application can inspect. Authentication is not permission, a person can be authenticated and still be unauthorized to publish an article.
What is Authorization?
Authorization is the process of deciding whether an authenticated principal can perform a requested action on a resource.
Simply put, authorization answers “what can you do?”. It should check both broad permission, such as the editor role, and resource ownership or business state, such as whether this editor belongs to the article’s publication team.
Authentication options comparison
| Approach | Identity source | Good fit | Watch out |
|---|---|---|---|
| Forms Authentication | Application login and cookie | ASP.NET MVC server-rendered web app | Cookie protection, account lifecycle and CSRF |
| Windows Authentication | Windows/domain identity | Intranet application | Requires trusted domain and compatible clients |
| OAuth 2.0 | Delegated authorization server | APIs and delegated access | OAuth is authorization, not identity by itself |
| JWT bearer token | Signed token presented by client | Stateless API calls | Validate issuer, audience, signature and expiry |
Why authentication and authorization are important?
The authentication mechanism is the first boundary, but authorization protects the business operation. A user may be allowed to read a news article but not to publish it. A fund dashboard may identify the investor but still need to verify that the investor can read the requested portfolio.
The following diagram depicts the request flow,

Forms Authentication
Forms Authentication is a cookie-based approach commonly used by ASP.NET MVC applications with an application-managed login. After validating credentials, the application issues an authentication ticket and the browser sends the cookie on later requests.
Use it when the application owns the login experience and serves pages to browser users. Protect the cookie, use HTTPS, expire sessions appropriately and protect state-changing actions against cross-site request forgery. Do not treat the cookie value as readable business data, because it is a security credential.
Windows Authentication
Windows Authentication uses the Windows identity provided by IIS, normally for users inside a trusted domain. It is a good fit for an internal operations application where employees already use domain accounts. It is not normally suitable for a public internet application or a mobile client which cannot participate in the same domain trust.
OAuth 2.0 and JWT bearer tokens
OAuth 2.0 allows a client to obtain limited permission to call a resource server. JWT is a compact signed token format which can carry claims such as subject, audience, scope and expiry. A JWT is not automatically safe because it is signed, the API must validate all relevant claims.
Use OAuth 2.0 when multiple clients or services call an API, or when access is delegated by an identity provider. Use bearer tokens over HTTPS and never write them to logs. For OWIN configuration, refer the How to secure ASP.NET Web API with OAuth 2.0 bearer tokens (OWIN)? article for detailed information. For the distinction between OAuth authorization and OpenID Connect authentication, refer the What is OAuth 2.0 and OpenID Connect? article for detailed information.
How should we choose?
Start by listing the clients, the identity source and the data sensitivity. For an intranet application in a domain, Windows Authentication may remove duplicate login work. For a public MVC application with its own users, Forms Authentication can be a simple choice. For a Web API called by other applications, OAuth 2.0 bearer tokens normally give a clearer boundary.
Whatever mechanism we choose, authorization should be tested independently. A test should prove that a reader receives a 403 for a publish operation, not only that the reader can sign in. It is important to measure failed authentication attempts and authorization failures, because a secure system also needs operational visibility.
Authentication and authorization in code
Find below a small Web API example, the browser identity is not being trusted directly and the authorization is being checked at the operation,
[Authorize]
[RoutePrefix("api/articles")]
public class ArticlesController : ApiController
{
[HttpGet]
[Route("{id:int}")]
public IHttpActionResult Get(int id)
{
Article article = repository.Find(id);
if (article == null)
return NotFound();
return Ok(article);
}
[Authorize(Roles = "editor")]
[HttpPost]
[Route("{id:int}/publish")]
public IHttpActionResult Publish(int id)
{
service.Publish(id, User.Identity.Name);
return StatusCode(HttpStatusCode.NoContent);
}
}
The [Authorize] attribute is only one part of authorization. The service should check that the editor is allowed to publish this article, because a role alone may be too broad. It is also important to return 401 when the caller is not authenticated and 403 when the caller is authenticated but is not allowed, otherwise the client cannot take the correct action.
Must Do and Don’ts
- Must Do: Keep authentication at the framework boundary and business authorization in the service.
- Must Do: Use HTTPS for Forms Authentication cookies and bearer tokens.
- Must Do: Expire sessions and provide a clear sign-out path.
- Don’t: Accept user identity from a request body as proof of authentication.
- Don’t: Use Windows Authentication for a public internet client which is not part of the trusted domain.
- Be mindful: JWT is a token format, OAuth 2.0 is an authorization framework, and neither removes the need for authorization rules.
In our case, Forms Authentication is suitable for an ASP.NET MVC application where the application is owning the browser login. Windows Authentication is suitable for internal domain applications. OAuth 2.0 with bearer tokens is suitable for APIs used by many clients, and the final choice is depending on the client and trust boundary.
Refer the “How to secure ASP.NET Web API with OAuth 2.0 bearer tokens (OWIN)?” article for detailed OWIN implementation. Refer the “What is OAuth 2.0 and OpenID Connect?” article for the difference between authorization and authentication.
When authorization is added only after a support issue, the team is taking reactive actions and the customer is discovering the security boundary first. We should be proactive by defining authentication and authorization at the API design stage, then testing the allowed and forbidden paths. The trade-off is between a simple mechanism and the reach of the clients, hence in our case we are choosing Forms for MVC pages, Windows for the domain and OAuth for shared APIs.
Wrap up
In this article, we have looked at authentication, authorization, Forms Authentication, Windows Authentication, OAuth 2.0 and JWT bearer tokens. I hope this article provided you some insights into selecting an ASP.NET security approach. In the next article, I will walk you through getting started with Docker images, containers and commands.
Related Posts
How to secure ASP.NET Web API with OAuth 2.0 bearer tokens (OWIN)?
Securing ASP.NET Web API with OAuth bearer tokens through OWIN, covering token endpoints, external JWT issuers, bearer validation, claims, and authorization roles.
What is OAuth 2.0 and OpenID Connect?
OAuth 2.0 and OpenID Connect explained through roles, grant types, access tokens, authorization versus authentication, and the purpose of an id_token.
Getting started with Docker - Part 1
Getting started with Docker through images, containers, Docker Toolbox, Docker Machine, host addresses, and basic Docker 1.x commands for practical first steps.