# Secure a Mobile API in Five Steps: The Order Is the Whole Point

> HTTPS, authentication, authorization, secrets, then monitoring — five layers for a mobile API on Azure, and why doing them out of order defeats the point.

- **Author:** Suthahar Jegatheesan (MSDEVBUILD)
- **Published:** 2026-10-20
- **Category:** Azure
- **Tags:** Azure, ASP.NET Core, API Security, Microsoft Entra ID, Azure Key Vault, Application Insights
- **Canonical URL:** https://blog.msdevbuild.com/blog/secure-mobile-api-five-steps/

---

**Highlight:** Secure a mobile API on Azure in this order: HTTPS only, authentication with Entra ID, authorization in your own code, secrets in Key Vault, then monitoring. You can add monitoring last. You cannot add HTTPS last — everything you build in the meantime travels in the clear.

import Callout from '../../../../components/mdx/Callout.astro';

Every list of "API security advice" has the same items on it. What almost none of them tell you is that the order matters as much as the items do.

Here are the five layers for a mobile API on Azure, in the order I'd add them to a brand-new ASP.NET Core API, and why.

<figure>

![Five steps with icons, in order. 1, a padlock: HTTPS only, so nothing travels in plain text. 2, a shield: authentication, Entra ID gives the user a signed pass and your API checks it. 3, a filter: authorization, Priya only gets Priya's orders, checked in your own code. A red dashed line after step 3 reads "1-3: the doors an attacker must pass". 4, Key Vault: secrets live in Key Vault, not your code. 5, Application Insights: monitoring alerts you when failed logins spike. A green box reads "Do them in this order. You can add monitoring last. You can't add HTTPS last."](./images/five-steps-beginner.png)

<figcaption>Figure 1 — the five layers, in the order to add them.</figcaption>

</figure>

## Step 1 — How do you enforce HTTPS on a mobile API?

Turn HTTP off, don't just redirect it. On App Service, set **HTTPS Only = On** and a minimum TLS version of 1.2, then add HSTS. A redirect still lets the first request go out in the clear. On a mobile app, that first request usually carries the token.

```csharp
app.UseHsts();
app.UseHttpsRedirection();
```

## Step 2 — Authentication: proving who is calling

Entra ID issues the token. Your API validates it. It's a local check against cached signing keys. Microseconds, not a round trip. Validate the audience too. A valid token for a different app is still a valid token. The whole sign-in journey is in [what actually happens when you tap Sign in](../secure-login-journey).

## Step 3 — Authorization: what the caller may do

A different question, and the one teams skip. Entra ID says she's Priya. Your API decides that Priya gets Priya's orders, and nobody else's.

```csharp
db.Orders.Where(o => o.UserId == me.GetObjectId())
```

Then make it fail closed, so an endpoint you forget about is protected by default:

```csharp
builder.Services.AddAuthorizationBuilder()
    .SetFallbackPolicy(new AuthorizationPolicyBuilder()
        .RequireAuthenticatedUser().Build());
```

## Step 4 — Secrets: nothing in config

Azure Key Vault holds them, a managed identity fetches them, and `appsettings.json` holds a vault URI at most. For Azure-to-Azure calls, skip keys entirely. SQL, Storage, Service Bus, Cosmos DB and Azure OpenAI all accept managed identity. The full case is in [Azure Key Vault, explained properly](../azure-key-vault-explained).

## Step 5 — Monitoring: you find out first

Application Insights for what your API sees, Microsoft Defender for Cloud for what Azure sees. Alert on the *rate* of 401s and 403s, not just on errors: a spike in 401s is somebody trying credentials, and it's the earliest warning you'll get.

## Why does the order matter?

<Callout type="tip">
  You can do step 5 last. You can't do step 1 last. Everything you added in the meantime travelled in the clear while you waited.
</Callout>

Steps 1 to 3 are the doors an attacker walks through, step 4 decides how bad the day is when something *else* goes wrong, and step 5 decides whether you find out in an hour or on the invoice.

## Where rate limiting fits

It's not one of the five. On its own it isn't a security boundary. But ASP.NET Core has it built in, and it turns a credential-stuffing bot from a real threat into a nuisance:

```csharp
builder.Services.AddRateLimiter(o =>
    o.AddFixedWindowLimiter("login", w => {
        w.PermitLimit = 10; w.Window = TimeSpan.FromMinutes(1);
    }));
```

Partition by user or IP, never globally, or one attacker rate-limits your real customers. The reasoning is in [the post on automated attackers](../ai-bot-attacks-mobile-app).

## Key takeaways

- Five layers, in order: HTTPS only, authentication, authorization, secrets, monitoring.
- HTTPS Only has to be a platform setting, not just an app redirect, or the first request still leaks.
- Authentication and authorization are separate steps — a valid token says nothing about which rows the caller may see.
- Secrets live in Key Vault, fetched by a managed identity, never in `appsettings.json`.
- Monitor the rate of 401/403s; it's the earliest sign of an attack in progress.

Official documentation: [Azure API Management key concepts](https://learn.microsoft.com/azure/api-management/api-management-key-concepts) and [access tokens in the Microsoft identity platform](https://learn.microsoft.com/entra/identity-platform/access-tokens).

---

## Frequently asked questions

### What are the steps to secure a mobile API on Azure?

Five, in order: enforce HTTPS only at the platform level, authenticate callers with Microsoft Entra ID tokens, authorize every request in your own code (for example, filtering to rows the caller owns), keep secrets in Azure Key Vault behind a managed identity, and monitor with Application Insights and Defender for Cloud.

### Is redirecting HTTP to HTTPS enough for a mobile API?

No. A redirect still lets the first request go out in the clear, and on a mobile app that first request often carries the token. Turn HTTPS Only on and set a minimum TLS version at the platform level, then add HSTS, rather than relying on an application redirect alone.

### What is the difference between authentication and authorization in an API?

Authentication answers "who are you" — Microsoft Entra ID issues a token and your API validates its signature, issuer and audience. Authorization answers "what may you do", and is enforced in your own code, typically by filtering a query to rows the caller owns.

### Why does secrets management come after authentication and authorization?

HTTPS, authentication and authorization are what an attacker has to get through to reach data at all, so they close off access first. Secrets management decides how much damage a separate failure causes, and monitoring decides how quickly you find out — both matter, but neither blocks an attacker on its own.
