</>

Technology

Rest Assured

Difficulty

Beginner

Interview Question

What is the difference between authentication and authorization in API testing?

Answer

Authentication vs Authorization

This is one of the most frequently asked API security questions in interviews.

Authentication — "Who are you?"

Authentication verifies the identity of a user or system. It answers: "Are you who you claim to be?"

Common Authentication Methods

MethodDescriptionExample
Basic AuthUsername + password (Base64)Authorization: Basic dXNlcjpwYXNz
Bearer TokenJWT token passed in headerAuthorization: Bearer eyJhbG...
API KeyUnique key per clientX-API-Key: abc123key
OAuth 2.0Delegated access via access tokenLogin with Google/GitHub
Session CookieServer-side session IDCookie: session=xyz
Java
// Authentication example in Rest Assured
given()
    .header("Authorization", "Bearer " + getToken())
    .when()
    .get("/api/profile");

Authorization — "What can you do?"

Authorization determines what actions an authenticated user is allowed to perform. It answers: "Do you have permission?"

Common Authorization Patterns

PatternDescription
RBACRole-Based Access Control (admin/user/guest)
ABACAttribute-Based Access Control (department, location)
ACLAccess Control Lists (per-resource permissions)
ScopesOAuth 2.0 scopes (read:users, write:orders)
Java
// Authorization test — user role cannot delete
given()
    .header("Authorization", "Bearer " + userToken) // not admin
    .when()
    .delete("/api/users/123")
    .then()
    .statusCode(403); // Forbidden — not authorized

Key Differences

AspectAuthenticationAuthorization
QuestionWho are you?What can you do?
HappensFirstAfter authentication
Failure code401 Unauthorized403 Forbidden
ExampleLogin with passwordAdmin vs regular user access
Can work alone?YesNo (needs authentication first)

HTTP Status Codes

  • 401 Unauthorized → Authentication failed (no token, wrong password)
  • 403 Forbidden → Authenticated but not authorized (wrong role/permissions)

Interview Answer

"Authentication is verifying identity — like showing your ID at the door. Authorization is determining what you're allowed to do once you're inside — like which rooms you can enter. In API testing, a 401 means the user isn't logged in; a 403 means they're logged in but don't have permission."

Follow AutomateQA

Related Topics