Azure
The Moment Your Azure Static Web App Needs Microsoft Graph

The Moment Your Azure Static Web App Needs Microsoft Graph

It often starts with a page that is genuinely static.

There is some HTML, CSS and JavaScript, perhaps a React or Vue build, and no server-side runtime to manage. Put it in Azure Static Web Apps, connect a repository, add a custom domain and the application is online. Microsoft Entra ID authentication can sit in front of it, preview environments can be created from pull requests, and the operational footprint stays pleasantly small.

Then someone asks for one more feature.

Could the page show the signed-in user’s profile? Could it display group membership, upcoming meetings or a list of Teams? Could it send a message, process a shared mailbox or refresh information overnight? None of those requests sounds especially dramatic. Microsoft Graph exists to expose Microsoft 365 and Entra data through an API.

But this is the moment the architecture changes.

The important question is no longer simply, “Can this page call Microsoft Graph?” It is: whose identity is making the call, what can that identity access, where is its credential or token handled, and what continues to happen when no user is present?

Once those questions appear, the application may still have a static front end, but it is no longer only a static application.

Authentication at the front door is not the whole security model

One of the easiest mistakes is to treat sign-in as if it solves every identity problem in the application.

Azure Static Web Apps provides integrated authentication and authorization. Routes can require an authenticated user, and a custom Microsoft Entra provider can restrict sign-in to a particular tenant. That is useful and, for many internal applications, a very good front door.

It does not automatically answer how the application should call Microsoft Graph.

There are at least three different identities to think about:

  1. The user identity establishes who opened the application.
  2. The application identity defines what the software can do when it calls Microsoft Graph or another protected API.
  3. The Azure workload identity allows the hosted backend to reach Azure resources such as Key Vault, Storage or a database without storing another long-lived credential.

A fourth identity often appears in delivery: the GitHub Actions or Azure DevOps identity that is allowed to deploy the application. It should not be confused with any of the runtime identities.

These identities may all be represented in Microsoft Entra ID, but they have different purposes and should have different permissions. Combining them because it makes the first deployment easier usually creates a harder security and operations problem later.

Decide whether Graph should act as the user or as the application

Microsoft Graph supports two broad access models: delegated permissions and application permissions.

With delegated access, the application calls Graph on behalf of a signed-in user. The resulting access is bounded by both the delegated permission granted to the application and the authority of that user. If a user cannot open a particular file or mailbox, a delegated token does not normally make that restriction disappear.

This is often the right model for interactive features. A page showing “my profile”, “my calendar” or information the current user already has permission to see is naturally user-centred. Microsoft also recommends delegated permissions from a least-privilege perspective when they meet the requirement.

With application access, the software calls Graph as itself. There is no signed-in user in the authorization decision. This is appropriate for unattended jobs, shared services, scheduled processing and other cases where the work must continue independently of an interactive session.

It is also much easier to underestimate.

An application permission is not merely a more reliable delegated permission. It can grant a service access across an organization without a user being present. Permissions such as Mail.ReadWrite, Files.Read.All, Group.Read.All or Calendars.ReadWrite should be treated as significant production authority, not as convenient boxes to tick until the code works.

The requirement should therefore be written in operational terms before any permission is selected:

  • Does the operation happen only while a particular user is signed in?
  • Should the result be limited by that user’s existing access?
  • Must the work continue on a schedule or in response to an event?
  • Is the target one resource, a defined set of resources or the whole organization?
  • Is read access sufficient, or is write access genuinely required?

Those answers determine more than the Graph permission. They influence where the code belongs.

A browser is a public client

A static application’s code is delivered to the browser. That means the browser cannot be trusted with a client secret, certificate private key, storage key, database password or any other credential that depends on remaining confidential.

An environment variable injected into a front-end build is not protected simply because it came from an Azure application setting. If its value is compiled into JavaScript sent to the user, it is public. Renaming it, minifying the bundle or hiding it behind an attractive interface does not change that.

Single-page applications can securely use authorization code flow with PKCE for supported delegated scenarios. The browser can obtain a user token without pretending that it can keep a client secret. But that does not make the browser a suitable home for app-only Graph credentials, privileged business logic or unrestricted access to supporting data stores.

If the feature needs any of those things, introduce a server-side boundary.

The front end calls an API that you control. That API validates the caller, performs the permitted operation and returns only the data the user actually needs. For delegated Graph access through a middle tier, the OAuth on-behalf-of flow can preserve the user’s identity while the backend obtains a token for the downstream API. For unattended work, the backend uses an application identity under a separately reviewed app-only permission model.

This also creates a useful enforcement point. The browser might request “show my upcoming meetings”; it should not receive a general-purpose Graph token or an endpoint capable of querying arbitrary users merely because the underlying application technically can.

The backend can be small without being an afterthought

Adding a backend does not mean every application needs a large platform.

For a modest application, an Azure Function can be enough. Static Web Apps can integrate with managed Functions or link an existing API hosted in Functions, App Service, Container Apps or API Management. A narrowly defined Function can validate a request, call Graph and return a constrained response without turning the project into a traditional monolith.

Functions are a natural fit when the work is short-lived and event-oriented: respond to an HTTP request, process a queue item, react to a storage event or run on a timer. They also bring triggers and bindings that would otherwise have to be built into the application.

However, “serverless” should not be used as a substitute for understanding the runtime. Cold starts, execution limits, dependency packaging, connection behaviour and the hosting plan still matter. A web application forced through a Functions compatibility layer can become awkward if it wants a continuously available server process, complex middleware, long-lived connections or a conventional full-stack deployment model.

That is where Azure App Service can be the simpler option.

App Service is a good home for an ordinary web application or API that expects a persistent HTTP runtime. It supports established application stacks, deployment slots, managed identity, networking and conventional health checks. If the application already has a server, session handling, a database integration and several related routes, fitting it into App Service may involve fewer surprises than breaking it into numerous functions merely to use a serverless label.

Azure Container Apps becomes attractive when the unit of deployment is already a container, when an API and worker need to share a release, or when background processing has requirements that do not fit comfortably into a Function. Container Apps can run continuously available services as well as jobs that start, complete and stop. Jobs can be manual, scheduled or event-driven, making them useful for discrete Graph synchronization and reporting tasks.

The choice is not about which service is newest. It is about choosing the smallest hosting model that fits the application’s execution pattern and that the team can operate well.

A practical hosting decision

The following is a useful starting point rather than a universal rule:

Requirement Likely starting point
Static content with tenant-restricted sign-in Azure Static Web Apps
Small protected API using delegated Graph access Static Web Apps with Azure Functions
Full-stack application with sessions, several APIs or a relational database Azure App Service
Scheduled or event-driven Graph processing Azure Functions or Container Apps Jobs
Containerized API plus a continuously running worker Azure Container Apps
Complex API estate requiring centralized policy, throttling and lifecycle management API Management in front of the selected backend

This table deliberately begins with the workload rather than the preferred Azure product. A static front end does not have to be abandoned when the application grows. It can remain an effective presentation tier while the sensitive responsibilities move behind an API.

Managed identity helps, but it does not remove the need for authorization design

Managed identity is one of the most useful controls available to an Azure-hosted backend. It allows App Service, Functions and other Azure services to obtain tokens for supported resources without storing a reusable credential in application configuration.

That is valuable for reaching Key Vault, Storage, databases and other Entra-protected Azure services. It removes a class of secret-rotation and accidental-disclosure problems.

It does not mean the identity should receive broad permissions.

A managed identity is still a security principal. It needs a defined owner, a documented purpose and the smallest role assignments that meet that purpose. If it is granted access to Microsoft Graph, that permission deserves the same review as an app registration using a certificate or secret. Secretless authentication reduces credential risk; it does not reduce the consequence of an over-privileged identity.

The same distinction applies to Key Vault. Moving a client secret into Key Vault is better than placing it directly in source code, but it does not turn an unnecessary secret into good architecture. If the platform supports a federated or managed-identity approach, prefer that where practical. If a credential remains necessary, document its owner, expiry, rotation process and the applications that depend on it.

Scope Graph access as closely as the service allows

Selecting the least-privileged Graph permission is essential, but it may not be the end of the authorization design.

Some Graph-connected workloads can be restricted to a particular resource or installation context. Exchange Online, for example, supports RBAC for Applications so that supported app-only mail and calendar permissions can be associated with a mailbox resource scope instead of being left organization-wide. Microsoft Teams also provides resource-specific consent for supported scenarios.

These controls are service-specific, so they must be evaluated against the actual endpoint and access model. The general principle is still useful: ask not only what the application can do, but where it can do it.

Be especially careful when different authorization systems overlap. A narrowly scoped assignment in one system does not necessarily cancel a broader permission granted elsewhere. Effective access may be additive. Verification should test an allowed resource and a resource that must remain denied; confirming only the happy path proves functionality, not containment.

Do not let background work hide inside the web process

The first scheduled task is another architectural turning point.

It is tempting to add a timer inside the same process serving the web application. That can work on a developer’s laptop and still behave badly in Azure. The platform may restart or scale the application. Multiple instances may run the same task. A deployment can interrupt work midway through. A sleeping process is not a durable scheduler.

If a Graph operation needs to run every hour, respond to a queue or resume reliably after failure, give it an execution model designed for that responsibility. A timer-triggered Function, a queue-triggered Function or a Container Apps Job is easier to reason about than an invisible loop inside a web server.

Also decide what happens when Graph throttles the request, a token cannot be obtained, consent changes or an item is only partly processed. Retry behaviour needs limits and backoff. Operations should be idempotent where possible. Failed work should be visible somewhere other than a transient console stream.

These concerns are not excessive engineering. They are what separates a feature that worked during a demonstration from a service that can be supported.

Deployment identity should be separate from runtime identity

The pipeline that publishes the application has another distinct job. It may need permission to update one Static Web App, deploy to one App Service or publish a container image. It does not need the application’s Microsoft Graph permissions.

Federated identity through OpenID Connect allows GitHub Actions to obtain short-lived Azure credentials without storing a long-lived client secret in the repository. Scope the Azure role to the deployment target where possible, protect the production environment and ensure the workflow receives only the permissions it needs.

Then add deployment safeguards appropriate to the application: tests, a health check, concurrency control, a known-good rollback and a way to prevent code from being deployed ahead of a required database migration.

The deployment completed successfully is not the same as the application being healthy. Verify the route users depend on, the backend’s ability to obtain its required tokens and at least one bounded Graph operation. If the application has a denied-path security test, run that too.

Design the operational model while the application is still small

The best time to establish these boundaries is before the application becomes important.

Record the identities it uses, the permissions assigned to each one and who owns their review. Document the redirect URIs, allowed audiences and sign-in restrictions. Decide where logs live and ensure they do not contain access tokens, secrets or unnecessary personal data. Create a health endpoint that tests useful dependencies without disclosing internal detail. Set an alert for credential expiry if any credentials remain.

Most importantly, test recovery. Know how to roll back a deployment without restoring an old database over newer data. Know how to remove a bad permission without locking out every administrator. Know which background operations can safely run again and which need reconciliation.

These details rarely appear in the first screenshot of a prototype, but they determine whether the finished application is trustworthy.

The boundary is the useful part

Azure Static Web Apps is not the wrong choice when an application eventually needs Microsoft Graph. In many cases it remains exactly the right place for the front end.

The mistake is assuming the original hosting decision has already answered every future question.

When Graph, secrets, persistence or unattended work enter the design, pause and redraw the application. Separate the browser from privileged operations. Decide whether Graph acts for a user or for the service. Give background work an appropriate runtime. Keep deployment authority separate from production authority. Use managed identity where it removes a real secret, and scope every identity as narrowly as the platform permits.

The application may still look like the same page to its users. Architecturally, it has crossed a boundaryโ€”and recognizing that boundary early is what keeps a simple idea from becoming a difficult service to secure and operate.

References

Leave a Reply

Your email address will not be published. Required fields are marked *