ASP.NET Core Web API Interview Question #51

What is authentication in ASP.NET Core Web API?

Authentication, Authorization, JWT & API Security Mid-Level Intermediate

Quick Interview Answer

Authentication establishes the identity of the caller. ASP.NET Core authentication handlers inspect credentials such as bearer tokens or cookies and, when valid, create a ClaimsPrincipal representing the authenticated user.

Detailed Explanation

Authentication establishes the identity of the caller. ASP.NET Core authentication handlers inspect credentials such as bearer tokens or cookies and, when valid, create a ClaimsPrincipal representing the authenticated user.

Authentication answers “who is calling?” It does not by itself decide whether that caller may perform a particular operation; that is authorization.

Code Example

[Authorize]
[HttpGet("profile")]
public IActionResult Profile()
{
    return Ok(new
    {
        User = User.Identity?.Name
    });
}