hardmultiple choiceObjective-mapped

You are designing an ASP.NET Core web API that authenticates users via Microsoft Entra ID. The application needs to authorize access to resources based on custom roles (e.g., 'Admin', 'Editor') that are not defined in Microsoft Entra ID app roles or groups. The role mappings are dynamic and stored in an application database. How should you implement authorization in the API?

Question 1hardmultiple choice
Full question →

You are designing an ASP.NET Core web API that authenticates users via Microsoft Entra ID. The application needs to authorize access to resources based on custom roles (e.g., 'Admin', 'Editor') that are not defined in Microsoft Entra ID app roles or groups. The role mappings are dynamic and stored in an application database. How should you implement authorization in the API?

Answer choices

Why each option matters

Good practice is not just finding the correct option. The wrong answers often show the exact trap the exam wants you to fall into.

A

Distractor review

Define the roles as Microsoft Entra ID app roles and assign them to users. This is the standard way to handle roles.

The scenario explicitly states that roles are not defined in Microsoft Entra ID and are dynamic. Relying on app roles would not work because the roles are not in the token.

B

Best answer

Use the OnTokenValidated event in OpenID Connect middleware to query the database and add custom role claims to the identity.

Correct. By subscribing to the OnTokenValidated event, you can retrieve roles from the database and add them as claims to the principal. Then you can use standard authorization policies based on those claims.

C

Distractor review

Store the roles in the Microsoft Entra ID token by customizing the token issuance in Microsoft Entra ID.

You cannot dynamically change the Microsoft Entra ID token contents from your application. Token customization is done at Microsoft Entra ID level and is not suitable for dynamic, application-specific roles.

D

Distractor review

Use the [Authorize] attribute with a custom authorization filter that checks the database on every request without modifying the claims.

While this could work, it is less efficient and does not integrate well with claims-based authorization. Adding the roles as claims is the recommended pattern because it allows policies to work declaratively.

Common exam trap

Common exam trap: authentication is not authorization

Logging in proves the user can authenticate. It does not automatically mean the user is allowed to enter privileged or configuration mode. Watch for AAA authorization, privilege level and command authorization details.

Technical deep dive

How to think about this question

This kind of question is testing the difference between identity and permission. A user may successfully log in to a router because authentication is working, but still fail to enter configuration mode because authorization is missing, misconfigured or mapped to a lower privilege level.

KKey Concepts to Remember

  • Authentication checks who the user is.
  • Authorization controls what the user is allowed to do after login.
  • Privilege levels affect access to EXEC and configuration commands.
  • AAA, TACACS+ and RADIUS can separate login success from command access.

TExam Day Tips

  • Do not assume successful login means full administrative access.
  • Look for words such as cannot enter configuration mode, privilege level, authorization or command access.
  • Separate login problems from permission problems before choosing the answer.

Related practice questions

Related AZ-204 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

More questions from this exam

Keep practising from the same exam bank, or move into a focused topic page if this question exposed a weak area.

Question 1

An application stores customer invoices in Azure Blob Storage. Deleted blobs must be recoverable for 14 days. What should be enabled?

Question 2

You are deploying a containerized application to Azure Container Instances. The application requires a custom domain name and SSL/TLS termination. You need to configure these features. Which resource should you create alongside the container group?

Question 3

A developer needs to run a Kusto query against application request data to identify 95th percentile latency by operation. Where should the query be run? The architecture review board prefers a managed AWS-native control.

Question 4

You are developing a web app that authenticates users via Microsoft Entra ID. The app needs to read the user's profile and send emails on their behalf. You want to minimize user consent prompts. Which OAuth 2.0 grant type should you use?

Question 5

You are developing an Azure Function that processes messages from an Azure Service Bus queue. The function uses a Service Bus queue trigger and runs on a Consumption Plan. The queue receives a high volume of messages in bursts. You need to ensure that the function scales out to handle the load but does not exceed 10 concurrent instances. Which configuration should you apply?

Question 6

You are monitoring an Azure App Service using Application Insights. You notice that the server response time is high for certain requests. You need to drill down to see which external dependencies (like databases or APIs) are causing the delay. Which Application Insights feature should you use?

FAQ

Questions learners often ask

What does this AZ-204 question test?

Authentication checks who the user is.

What is the correct answer to this question?

The correct answer is: Use the OnTokenValidated event in OpenID Connect middleware to query the database and add custom role claims to the identity. — When roles are not coming from Microsoft Entra ID tokens, you cannot rely on claims-based authorization from the identity provider. Instead, you should implement custom authorization logic that loads roles from the application database after authentication. Using a custom middleware or a custom AuthorizationHandler allows you to add custom claims to the principal after the token is validated, enabling the use of standard [Authorize] attributes with policies.

What should I do if I get this AZ-204 question wrong?

Then try more questions from the same exam bank and focus on understanding why the wrong options are tempting.

Discussion

Loading comments…

Sign in to join the discussion.