.NET Developer Interview Question

How do you set up authentication and authorisation in an ASP.NET Core API?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

Authentication establishes who the caller is; authorisation decides what they may do. For an API that is usually JWT bearer authentication against an identity provider, validating issuer, audience, signature and lifetime. Authorisation then uses policies built from claims or roles and applied to endpoints, plus resource based checks in code where access depends on the specific record. Deny by default, and never trust identifiers sent in the request body.

Why interviewers ask this

Security bugs in APIs are overwhelmingly authorisation bugs, such as a user reading another customer's order by changing an id in the URL. The interviewer wants a clean distinction between the two concepts, correct token validation, policy based authorisation and resource based checks. Mentioning a fallback policy that requires authentication everywhere shows you design for the endpoint someone forgets to protect.

How to structure your answer

  • Separate authentication from authorisation clearly.
  • Describe token validation for an API.
  • Explain policies, claims and resource based checks.
  • Cover deny by default and testing access rules.

Example answer

Spoken example, first person

Authentication answers who is this, authorisation answers are they allowed to do this, and most real vulnerabilities live in the second. For an API I typically use JWT bearer authentication with an identity provider, so the API never handles passwords. The middleware validates the signature, issuer, audience and expiry. For authorisation I prefer policies over scattered role checks, so a policy like can approve invoices is defined once from claims and applied to endpoints by name. The part that matters most is resource based authorisation. A policy can say this user may view orders, but only code that loads the order can say whether this particular order belongs to the user's account, so I use the authorisation service with the resource, or filter queries by the caller's tenant. I also set a fallback policy requiring an authenticated user on every endpoint, so a new endpoint is protected even if someone forgets the attribute. Integration tests assert the forbidden cases too.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • How would you stop one tenant reading another tenant's data in a shared database?
  • What claims would you put in a token, and what would you keep out?
  • How do you handle revocation when tokens stay valid until they expire?

Related .net developer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot