Building Secure Power Apps Code Apps for Dynamics 365 with Dataverse

By | November 25, 2026

If you’ve built business apps on the Power Platform, you’ve probably hit this wall. Canvas apps and model-driven apps are great for getting something running quickly, but once a client asks for a very custom interface, a specific design system, or a front end your team can build and test like any other web project, you start fighting the tool.

The usual workaround was a separate web app in React or Angular, connected to Dataverse by hand. That works, but it puts security in your hands. You set up app registrations, deal with sign-in and tokens, decide where the API calls run, and figure out how to share the app with the right people. All of that is yours to build, secure and maintain.

There was a second trap as well. Because the front end was custom code, it was tempting to put the permission checks there too. You check the user’s role, hide the Edit or Delete button, and call it done.

Power Apps Code Apps take a different route. You build the app in React and TypeScript with the Power Apps SDK and CLI, and the app runs inside the Power Platform. Your team keeps full control of the UI and a normal web development workflow, and you get managed platform capabilities such as signing in with a Microsoft work account, sharing the app with users, and reaching Dataverse and other connectors through the platform instead of a hand-built API layer.

In practice, the app talks to Dataverse as the signed-in user. You aren’t wiring up your own login and token handling just to read a Case record, which takes a lot of security work off your plate.

That doesn’t mean you can stop thinking about permissions. It just changes where they belong. Hiding a button is a design choice, not a security control.

In this article we’ll build a small Case Management Code App that relies on Dataverse for enforcement. We’ll set up least-privilege security roles, connect the app to the Case table, keep the React logic focused on user experience, and handle “Access denied” responses gracefully instead of letting the app break.

Applying Role-Based Security in Dataverse

Consider a Use Case: A customer service team wants a Case Management app built as a Code App. Access to Case records should depend on the user’s role:

  • Sales Representatives see only the Cases Dataverse allows them to see.
  • Customer Service Agents can update Cases they have the privilege and access for.
  • Administrators get broader access based on their security role.
  • Unauthorized actions fail safely, and the app shows a plain-language message.
Operation Sales Representative Customer Service Agent Administrator
View permitted Cases Yes Yes Yes
Create Cases Based on assigned privilege Based on assigned privilege Based on assigned privilege
Update permitted Cases No by default in this scenario Yes when granted Yes when granted
Delete Cases No No by default Yes when granted

Prerequisites

Here’s what you’ll need to build and test the Case Management Code App:

  • A Power Platform environment with Dataverse, with Code Apps enabled
  • js (LTS version) and Git
  • The Power Apps CLI and the @microsoft/power-apps SDK package. The Code Apps tooling has changed a fair bit between releases, so follow Microsoft’s latest quickstart for the install steps.
  • Access to the Case table (incident), or a similar custom table if you prefer
  • Permission to create and assign Dataverse security roles
  • Three test users, one for each role in the scenario
  • A dev or test environment. Please don’t experiment with security roles in production.

Step 1: Understanding Authentication, Authorization, and Data Security

These three ideas get mixed up a lot, so let’s separate them.

Authentication is about who the user is. Users sign in with Microsoft Entra ID through the normal Power Platform sign-in experience.

Authorization is about what that signed-in user is allowed to do.

Data security is about which Dataverse records and operations the user can reach. In Dataverse that comes down to security roles, table privileges, access levels, record ownership, teams and record sharing.

Here’s how the layers divide the work:

Layer Responsibility
Microsoft Entra ID Authenticates the user
Power Platform application/environment controls Controls applicable application and environment access
Dataverse security Enforces data privileges and record access
React UI Improves the user experience by showing relevant actions

Step 2: Configure Security Roles for Different Users

Start in the Power Platform admin center. Open your environment, go to Settings > Users + permissions > Security roles, and create (or copy) a role for each type of user, for example “Case – Sales Rep” and “Case – Service Agent”. On the Case table, these are the privileges you’ll care about:

Privilege What it controls
Read Viewing Case records
Create Creating new Cases
Write Updating existing Cases
Delete Deleting Cases
Append / Append To Linking records together, such as attaching a Case to a Contact or Account

Every privilege also has an access level: None, User, Business Unit, Parent: Child Business Units, or Organization. This matters more than people expect. Read on the Case table doesn’t mean the user can see every Case. With User-level Read, they see the Cases they own, plus anything shared with them or owned by a team they belong to.

Two things to keep in mind while you set this up. First, stick to least privilege, which means giving people only what their job needs. Second, remember that privileges add up. If a user has several roles, or gets access through a team, their effective access is the combination of all of it.

Figure 1: Configuring Dataverse privileges for the Case table

Figure 1 shows where these settings live: the Case row with an access level for each privilege. For the Sales Representative role in our scenario, you would set Read to User or Business Unit and leave Write and Delete as None. With that in place, even if someone makes a mistake in the React code, Dataverse will turn down an update or delete request from that user.

Step 3: Connect the Power Apps Code App to Dataverse

If you’re starting from scratch, Microsoft’s quickstart creates the project from a Vite template and initializes it like this:

npx degit github:microsoft/PowerAppsCodeApps/templates/vite case-management-app

cd case-management-app

npm install --global @microsoft/power-apps-cli

npm install --global @microsoft/power-apps

npm install

pa app init --display-name "Case Management" --environment-id <environment-id

The CLI asks you to sign in with your Power Platform account if you aren’t already. Next, add the Case table using its logical name, incident:

pa app add data-source --connector dataverse --table incident

If you’re still on the older PAC CLI (Microsoft has said it will be deprecated in a future release), the equivalent is:

pac code add-data-source -a dataverse -t incident

The CLI may ask for your organization URL. Either way, the command generates model and service files under src/generated/, in the models and services folders.

Figure 2: Adding the Dataverse Case table as a data source

Generated names follow the table. In Microsoft’s own examples the Accounts table produces AccountsModel.ts and AccountsService.ts. In our project the Case table produced IncidentsModel.ts and IncidentsService.ts, so that’s the service we’ll call in the snippets below. Yours may differ, so look at what was generated in your own project instead of guessing.

Figure 3: Generated files created for Dataverse integration

A quick note on SDK setup. Some Microsoft samples show an explicit initialize() call before any data request. Our demo doesn’t add its own initialization code. It uses the generated service once the app loads through Power Apps (more on that in Step 6). Check the docs for your template version and follow what they recommend.

Step 4: Build a User-Friendly Case Management Interface

Now for the UI. It’s perfectly fine to show or hide actions to keep the screen clean. Here’s a small component that takes two flags and decides which buttons to render:

interface CaseActionsProps {
canEdit: boolean;

canDelete: boolean;

onEdit: () => void;

onDelete: () => void;

}

/**

* UI ONLY - controls what the user sees. This is NOT a security boundary.

* Hiding or showing these buttons does not grant or remove any access:

* Dataverse enforces update and delete based on the user's security role.

*/

export function CaseActions({ canEdit, canDelete, onEdit, onDelete }: CaseActionsProps) {
return (

<div>

{canEdit && <button type="button" onClick={onEdit}>Edit</button>}

{canDelete && <button type="button" onClick={onDelete}>Delete</button>}

</div>

);

}

It’s worth being clear about what this does. It controls what the user sees, and nothing else.

Figure 4: The CaseActions component, marked clearly as UI only

The canEdit and canDelete values must not be treated as the security boundary.

If a browser-side boolean flipping to true were enough to get at sensitive data, there would be no security at all. Whatever the UI shows, Dataverse still checks the request against the signed-in user’s effective permissions.

A quick note on where canEdit and canDelete come from. In this article they’re conceptual UI state, driven by a clearly labelled demo setting. We’re not calling a Power Apps SDK method to read the user’s Dataverse privileges, because we couldn’t find one documented. That’s okay. If the flags are wrong, the worst case is a button that shows up and then fails safely, which is what Step 5 handles.

By default the demo app hides Edit and Delete (the limited view). A Demo mode switch turns them on, so we can show that Dataverse refuses the request even when the buttons are visible.

Figure 5: Case Management interface for a user with limited access (Demo mode off, view only)

Figure 6: The same app with Demo mode on, showing Edit and Delete for testing

Step 5: Read, Update and Delete with the Generated Service, and Handle Denials Safely

 Reading data goes through the generated service. Microsoft’s docs show getAll accepting select, filter, orderBy and top:

import

{ IncidentsService } from "./generated/services/IncidentsService";

 

const loadCases = async () => {

try {

const result = await IncidentsService.getAll({

select: ["title", "ticketnumber", "statuscode", "createdon"],

orderBy: ["createdon desc"],

top: 50,

});

return result.data ?? [];

} catch (err) {

console.error("Failed to load cases:", err);

return [];

}

};

Notice there’s no role-based filtering here. The user gets back the rows Dataverse lets them read, and that’s the point.

For updates, send only the columns you’re actually changing. Microsoft specifically warns that sending unchanged values can fire business logic and muddy your audit data. There’s one more catch: the generated service returns an operation result with success and error fields, so a denied call might come back as a failed result instead of throwing an error. Handle both:

type Result = { ok: true } | { ok: false; message: string };

const UPDATE_DENIED =

"You don't have permission to update this case, or it can't be changed right now.";

export async function updateCase(

id: string,

changes: Partial<Pick<Incidents, "title">>

): Promise<Result> {

try {

const res = await IncidentsService.update(id, changes);

if (!res.success) {

console.error("updateCase failed (result):", res.error);

return { ok: false, message: UPDATE_DENIED };

}

return { ok: true };

} catch (err) {

console.error("updateCase failed (thrown):", err);

return { ok: false, message: UPDATE_DENIED };

}

}

The function returns a small result object instead of throwing into the UI, so the screen can show a plain-language message and the technical detail stays in the console.

Figure 7: The update handler checks both a failed result and a thrown error

Deleting needs a bit more care. In our project the generated IncidentsService.delete returns nothing, so there’s no result to check. If Dataverse refused the delete and the call came back quietly, the app would think it had worked. To avoid that, the app confirms the outcome by trying to read the record again: const DELETE_DENIED = “You don’t have permission to delete this case, or it can’t be deleted right now.”;   export async function deleteCase(id: string): Promise<Result> { try { await IncidentsService.delete(id); } catch (err) { console.error(“deleteCase failed (thrown):”, err); return { ok: false, message: DELETE_DENIED }; }   // delete returns nothing, so check whether the record is really gone let stillThere = false; try { const check = await IncidentsService.get(id); stillThere = check.success && !!check.data; } catch { stillThere = false; // can’t be read any more, so it was deleted }   if (stillThere) { console.error(“deleteCase: record is still readable after delete”); return { ok: false, message: DELETE_DENIED }; } return { ok: true }; } Whichever operation you call, the same two habits apply. Catch the failure and show a friendly message, while logging the technical detail for yourself. And don’t treat a denied request as a bug. It means the security model did its job, so test for it on purpose with each of your test users. Step 6: Run the App and Test Each Role   Start the app locally: pa app run The output includes a URL labelled Local Play. Open that URL, not localhost directly, in a browser profile that’s signed in to your Power Platform tenant. If you open the localhost address on its own, the app can’t reach the platform and will sit on “Loading cases…”. If Chrome or Edge asks about local network access, allow it. If port 3000 is busy, run pa app run –port <port>. Local Play uses whoever is signed in in that browser profile. To test each role, use a separate browser profile or an InPrivate window per test user. Alternatively, publish with npm run build and pa app push, share the app from make.powerapps.com, and open it as each user. First, a user who has Write access edits a Case. Dataverse accepts the change, and the app shows a confirmation:

Figure 8: A successful update by a user with Write access

Now a limited-privilege user turns on Demo mode and tries to edit. The button is visible, but Dataverse refuses the update, and the app shows a friendly message while the title stays as it was:

Figure 9: Handling a denied Dataverse update gracefully

The same user then tries Delete. Dataverse refuses again, and the Case stays in the list:

Figure 10: A denied delete: the app shows a message and the Case stays in the list

Those two screenshots are the whole point of the article. The UI offered the action, and the platform still said no.

Conclusion

Code Apps let you build exactly the interface you want, but they don’t change who’s responsible for protecting the data. In our Case Management app, React decides what to show, and Dataverse decides what each person can actually read, update or delete. So set up least-privilege roles, test with real users, handle denied requests gracefully, and think of the UI as a convenience rather than a gatekeeper. Do that, and a mistake in the front end won’t turn into a data problem.

Frequently Asked Questions

1. What are Power Apps Code Apps in Dynamics 365?

Power Apps Code Apps allow developers to build custom applications using React and TypeScript with the Power Apps SDK and CLI. They run within the Power Platform and connect to Dataverse and other connectors while providing flexibility over the user interface and development workflow.

2. How does Dataverse security work in Power Apps Code Apps?

Dataverse enforces data security based on users’ security roles, table privileges, access levels, record ownership, teams, and record sharing. The app accesses Dataverse as the signed-in user, so users can only perform operations and access records permitted by their effective permissions.

3. How does authentication work in Power Apps Code Apps?

Power Apps Code Apps use Microsoft Entra ID to authenticate users through the standard Power Platform sign-in experience. Once signed in, the app accesses Dataverse as the authenticated user, so developers don’t need to build a separate login and token-handling process for the app.

4. How do you handle access-denied errors in Power Apps Code Apps?

You can handle access-denied errors by catching failed Dataverse requests and displaying user-friendly messages. For example, if a user tries to update or delete a Case without the required permissions, the app should handle the failure gracefully, show a clear message, and log technical details for troubleshooting.

5. Why is hiding buttons not enough to secure a Power Apps Code App?

Hiding buttons such as Edit or Delete only controls what users see in the interface. It does not prevent them from performing those operations. Dataverse enforces the actual security permissions based on the user’s security roles and access rights, even when an action is visible in the app.


											
Category: Technical

About Sam Kumar

Sam Kumar is the Vice President of Marketing at Inogic, a Microsoft Gold ISV Partner renowned for its innovative apps for Dynamics 365 CRM and Power Apps. With a rich history in Dynamics 365 and Power Platform development, Sam leads a team of certified CRM developers dedicated to pioneering cutting-edge technologies with Copilot and Azure AI the latest additions. Passionate about transforming the CRM industry, Sam’s insights and leadership drive Inogic’s mission to change the “Dynamics” of CRM.