Authentication and Authorization are two fundamental security concepts in ASP.NET Core and most modern applications.
Many interviewers ask this question together.
Quick Interview Answer
-
Authentication → Who are you? 🔐
-
Authorization → What can you access? 🛡️
1. Authentication (Who are you?)
Authentication is the process of verifying the user's identity.
Example:
-
Username & Password
-
OTP
-
Fingerprint
-
Login with Google
When you log in to a website:
Enter username + password
System checks:
Is this user valid?
If yes → User is Authenticated ✅
Example
Login to Gmail
Username: sampath@gmail.com
Password: *****
System verifies → You are authenticated
2. Authorization (What can you access?)
After authentication, system checks what user is allowed to do.
Example:
| User | Access |
|---|---|
| Admin | Create users |
| HR | Add candidates |
| Employee | View profile |
This is Authorization.
Real Example
Suppose your ATS application (hiringbegins.com from your previous project):
User logs in:
Step 1 → Authentication
Is this user valid?
Step 2 → Authorization
Is user HR or Admin?
Then show features accordingly.
Example in Code (.NET Core)
Authentication
app.UseAuthentication();
Authorization
app.UseAuthorization();
Order matters
app.UseAuthentication();
app.UseAuthorization();
Visual Flow
User Login
↓
Authentication (Who are you?)
↓
Authorization (What can you access?)
↓
Access Granted
Real World Example
Bank ATM 💳
Authentication:
Insert card + PIN
Authorization:
Check account balance? ✅
Withdraw money? ✅
Close account? ❌
Interview Comparison Table
| Feature | Authentication | Authorization |
|---|---|---|
| Purpose | Verify identity | Check permissions |
| Happens first | ✅ Yes | ❌ No |
| Example | Login | Role-based access |
| Data used | Username/password | Roles/claims |
Common Authentication Methods
-
Cookies
-
JWT Token
-
OAuth
-
OpenID Connect
Examples:
-
JWT
-
OAuth 2.0
-
OpenID Connect
Interview One-Line Answer
Authentication verifies who the user is, while authorization determines what the user is allowed to access.
