ASP.NET Core Web API Interview

Authentication, Authorization, JWT & API Security

ASP.NET Core Web API interview questions covering authentication, authorization, JWT bearer tokens and API security.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
51
Mid-LevelIntermediate

What is authentication in ASP.NET Core Web API?

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.

52
Mid-LevelIntermediate

What is authorization in ASP.NET Core Web API?

Authorization determines whether an authenticated or anonymous caller is allowed to access a resource or perform an operation. ASP.NET Core supports role-based, claims-based, policy-based, and resource-based authorization.

53
Mid-LevelIntermediate

What is the difference between authentication and authorization?

Authentication verifies or establishes the caller's identity, while authorization determines what that identity is permitted to do. Authentication generally happens before authorization.

54
Mid-LevelIntermediate

What is JWT?

JWT stands for JSON Web Token. It is a compact token format that can carry claims and can be cryptographically signed so a server can verify that the token has not been altered.

55
Mid-LevelIntermediate

What are the main parts of a JWT?

A JWT commonly consists of three Base64URL-encoded sections separated by dots: header, payload, and signature. The header identifies metadata such as the signing algorithm, the payload contains claims, and the signature protects integrity.

56
Mid-LevelIntermediate

What is bearer token authentication?

Bearer authentication means possession of the access token is sufficient to present it as a credential. The client normally sends the token in the HTTP Authorization header using the Bearer scheme.

57
Mid-LevelIntermediate

How do you configure JWT bearer authentication in ASP.NET Core?

Register the JWT bearer authentication handler and configure token-validation parameters that match the trusted token issuer. The request pipeline must also execute authentication and authorization middleware before protected endpoints.

58
Mid-LevelIntermediate

What should an API validate in a JWT access token?

The API should validate the token's cryptographic signature and the security properties required by its trust model. Common checks include the expected issuer, intended audience, expiration/lifetime, and signing key.

59
Mid-LevelIntermediate

What are claims in API authentication?

Claims are statements about an identity, such as a user identifier, name, role, tenant, or permission. After authentication, ASP.NET Core exposes claims through the current ClaimsPrincipal.

60
Mid-LevelIntermediate

How does the [Authorize] attribute work in a Web API?

Authorize requires the request to satisfy the applicable authorization policy. With no additional parameters, it normally requires an authenticated user under the configured authorization rules.

61
Mid-LevelIntermediate

What does [AllowAnonymous] do?

AllowAnonymous permits an endpoint to be accessed without satisfying Authorize requirements that would otherwise apply to it. It is useful for intentionally public endpoints such as login, registration, or selected public content.

62
Mid-LevelIntermediate

What is role-based authorization?

Role-based authorization grants access according to roles associated with the authenticated identity, such as Admin or Manager. ASP.NET Core can enforce role requirements through Authorize attributes or policies.

63
Mid-LevelIntermediate

What is policy-based authorization?

Policy-based authorization defines named authorization rules composed of requirements. Policies can check claims, roles, authentication schemes, custom requirements, or combinations of conditions.

64
Mid-LevelIntermediate

What is a custom authorization requirement and handler?

A custom authorization requirement represents an authorization condition that cannot be expressed adequately with built-in role or claim checks. An AuthorizationHandler evaluates that requirement using the current authorization context.

65
Mid-LevelIntermediate

What is resource-based authorization?

Resource-based authorization evaluates permission against a particular resource instance rather than only endpoint metadata. It is useful for rules such as “users may edit only records they own.”

66
Mid-LevelIntermediate

What is the difference between 401 Unauthorized and 403 Forbidden in secured APIs?

401 indicates that valid authentication credentials are missing or were not accepted. 403 indicates that the caller is authenticated but does not have permission to perform the requested operation.

67
Mid-LevelIntermediate

What is a refresh token?

A refresh token is a credential used to obtain a new access token without requiring the user to perform the full authentication flow again. Access tokens are typically shorter-lived, while refresh tokens require stronger storage and lifecycle controls.

68
Mid-LevelIntermediate

Should JWT access tokens be stored in localStorage?

There is no universally correct browser storage choice because the security trade-offs depend on the architecture. JavaScript-accessible storage such as localStorage is exposed if an attacker achieves script execution through XSS.

69
Mid-LevelIntermediate

What is CORS in ASP.NET Core Web API?

CORS, or Cross-Origin Resource Sharing, is a browser security mechanism that controls whether frontend code from one origin may access resources from another origin. The API declares allowed origins, methods, headers, and credential behavior through CORS response headers.

70
Mid-LevelIntermediate

Why should AllowAnyOrigin be used carefully?

AllowAnyOrigin permits browser JavaScript from any origin to make permitted cross-origin requests to the API. That may be appropriate for intentionally public APIs, but it is usually too broad for private browser applications.

71
Mid-LevelIntermediate

What is HTTPS and why is it essential for APIs?

HTTPS uses TLS to protect HTTP traffic against passive reading and tampering while in transit and to authenticate the server according to the certificate trust model. Credentials, bearer tokens, cookies, and application data should not travel over unprotected HTTP on untrusted networks.

72
Mid-LevelIntermediate

How should API secrets and signing keys be stored?

Secrets should not be committed to source control or embedded in application code. Development can use mechanisms such as .NET User Secrets, while production commonly uses environment-specific secret stores, managed identity, environment variables, or platform key-management services.

73
Mid-LevelIntermediate

What is rate limiting and why is it useful for APIs?

Rate limiting controls how many requests a client or partition may make within defined limits. It can protect service capacity, reduce accidental overload, limit some forms of abuse, and enforce product usage policies.

74
Mid-LevelIntermediate

How should sensitive information be handled in API logs and error responses?

Do not expose secrets, access tokens, passwords, connection strings, stack traces, or unnecessary personal information in client-facing errors. Production errors should provide safe, useful ProblemDetails responses while detailed diagnostics remain in protected server-side telemetry.

75
Mid-LevelIntermediate

What are best practices for authentication, authorization, JWT, and API security?

Use a trusted authentication system and validate tokens completely, including signature, issuer, audience, and lifetime. Keep authorization server-side and prefer reusable policies or resource-based checks for meaningful permissions. Apply least privilege and distinguish authentication failures from authorization failures.