Securing APIs as a SaaS vendor at scale with Entra ID: A case study of Fortytwo Identity Universe – part 1

Most guidance around securing APIs with Entra ID focuses on a single tenant, a single application, a single API, or a simple client-server architecture. In my experience, reality is often much messier.

As organizations modernize their platforms, they quickly move from managing one API to managing many APIs across many different teams, with different coding practices, languages and platforms. Creative souls like myself create new services that customers will interact with, and the number of app registrations and standalone services grow quickly..

At Fortytwo, we’ve been living this reality while building Fortytwo Identity Universe, our Identity and Access Management platform. Along the way, which is a road we are still walking, we’ve designed and operated a growing ecosystem of APIs secured with Microsoft Entra ID, supporting both human and machine identities across multiple services.

In this blog series, I’ll use Fortytwo Identity Universe as a real-world case study to explore how, as a SaaS provider, you can secure your APIs with Entra ID and have customers consume them in an as low friction way as possible.

This won’t be a product walkthrough. Instead, I’ll use our architecture, decisions, successes, and mistakes as practical examples to answer questions such as:

  • How should you structure API registrations in Entra ID?
  • When should you use scopes versus app roles?
  • How do you handle service-to-service communication, especially between your own SaaS services?
  • How do you manage consent across many APIs?
  • What governance practices become important as the number of APIs grows?

The goal is to bridge the gap between Microsoft’s documentation and the realities of running a platform with many interconnected services. Whether you’re building your first API or designing an enterprise-scale API ecosystem, the patterns discussed in this series should help you avoid common pitfalls and establish a foundation that can grow with your organization.

We’ll start with the architecture of Fortytwo Identity Universe itself and then progressively dive deeper into authentication, authorization, application registration strategy, governance, automation, and different lessons learned.

Let’s begin with the challenge every growing platform based on Entra ID eventually faces: turning a collection of APIs into a manageable set of app registrations, roles and consents.

At Fortytwo, we have several services that are essentially standalone products, and other services where the services themselves are both standalone and working with other Fortytwo services. We follow our own interpretations of domain driven design, but have a quite large overlap of team members and owners across our services.

In order to simplify consuming our APIs as much as possible, we have all public APIs published at a single place – api.fortytwo.io:

Let’s talk about how that affects our app registration strategy in Entra ID. When you create an app registration and go to Expose an API, Entra ID allows you to choose an Application ID URI. By default, this is on the format api://<appid>, which looks like this:

Now, in order to request an access token for this application, we will need to ask for the scope api://811a824e-a443-4e16-a221-4b1c092244c0/.default, which to me is not really sexy. However, you can also choose an Application ID URI which is the https protocol scheme and a domain name:

This makes much more sense. That means that when we have all of our APIs made available at api.fortytwo.io, we have chosen https://api.fortytwo.io as the Application ID URI for our API surface. This means that providing scope=https://api.fortytwo.io/.default when requesting a token is enough to get a token back.

There is one big bonus and caveat at the same time, which is that all our services published under api.fortytwo.io all must accept tokens for the same app. Luckily, an API can easily accept access tokens without the need of any client credentials for the app registration itself, which means that on our Fortytwo Universe app, there are 0 credentials (I’ll talk about how we do service access into customer tenants later). The app only asks for consent for user.read, which is the bare minimum required for signing in:

After this consent, the customer can use all of our APIs, both as users and service principals.

Either by assigning user roles (which we will cover later):

Or by using application roles (which we will also cover later):

In both circumstances, the access token will contain roles, such as for this user token example:

{
  "aud": "2808f963-7bba-4e66-9eee-82d0b178f408",
  "iss": "https://login.microsoftonline.com/237098ae-0798-4cf9-a3a5-208374d2dcfd/v2.0",
  "iat": 1796028302,
  "nbf": 1796028302,
  "exp": 1796032751,
  "aio": "AdQAK/8eAAAA....EDcQ==",
  "azp": "68bf2f1d-b9e1-4477-8b90-81314861f05f",
  "azpacr": "0",
  "name": "Marius Solbakken Mellum",
  "oid": "61858a99-231e-4b5d-9960-79d10c15d76f",
  "preferred_username": "cloudadmin.marius@goodworkarounddev.onmicrosoft.com",
  "rh": "1.AUsArphwI5gH-UyjpSCDdNLc_WP5CCi6e2ZOnu6C0LF49AgAAABLAA.",
  "roles": [
    "iam-core-administrator",
    "collection_criteria_definition-administrator"
  ],
  "scp": "user_impersonation",
  "sid": "0032628a-b7b2-8ace-fa77-60ab71fa79b4",
  "sub": "-bMwB_D-TIK9iRkYAznq506fJKb6yS5U4YF5_psQEfo",
  "tid": "237098ae-0798-4cf9-a3a5-208374d2dcfd",
  "upn": "cloudadmin.marius@goodworkarounddev.onmicrosoft.com",
  "uti": "vwAO7SQkUkyeiE_VtrJIAA",
  "ver": "2.0",
  "xms_ftd": "1IYT8OyzZyjD28elCFHikilRVthwf0KBv89vzncbsxcBc3dlZGVuYy1kc21z"
}

And this application token example:

{
  "aud": "2808f963-7bba-4e66-9eee-82d0b178f408",
  "iss": "https://login.microsoftonline.com/237098ae-0798-4cf9-a3a5-208374d2dcfd/v2.0",
  "iat": 1796032075,
  "nbf": 1796032075,
  "exp": 1796035975,
  "aio": "ATQAy/8eAAAATkFEZDwqMYZEuUzqjXBPCghKrMq1eJfBgBUB/7v7QuwqEzC/u5gGLe0X3LD8J6O9",
  "azp": "c4a1705d-9278-4417-8d78-92014798407e",
  "azpacr": "2",
  "idtyp": "app",
  "oid": "37dc977f-d3d5-4bcc-9c4d-16575ad2a4f6",
  "rh": "1.AUsArphwI5gH-UyjpSCDdNLc_WP5CCi6e2ZOnu6C0LF49AgAAABLAA.",
  "roles": [
    "iam-core.identity.read.all",
    "iam-core.orgunit.read.all"
  ],
  "sub": "37dc977f-d3d5-4bcc-9c4d-16575ad2a4f6",
  "tid": "237098ae-0798-4cf9-a3a5-208374d2dcfd",
  "uti": "Ok2iNAnoBkGKVz7m1xtKAA",
  "ver": "2.0",
  "xms_ftd": "YtyHQRcWwR0zm_IuCeNN2WTNNVAyxWMHNOrh5xWcSKwBc3dlZGVuYy1kc21z"
}

These values will then be used for authorization in all of our APIs. This also means that our services will see the roles assigned for all other services, but we see that as a strength.

Now, for the observant reader, you might have noticed the scp of the user claim having the value of user_impersonation. In order to do a delegated sign-in, meaning a sign-in with a user, we need to define at least one scope in our API that the frontend can request.

As an example, if my API is exposed like this in Entra ID:

You will not be able to use your app with delegated permissions:

If we look to how Microsoft does Microsoft Graph, there are a gazilion delegated scopes available. We have scopes like Calendars.Read, which allows an application to read all the signed in user’s calendar. Of course, you would not like all the different apps that use Microsoft Graph to have the same permissions – allowing any registered app in your tenant to read your users calendars should now be fun. This is what the scope does; it limits how an access token can be used.

For us in Fortytwo, however, we have opted to only use a single scope. Either you’re allowed as a frontend, or you’re not. The jury is still out on whether this is the right approach. Should we have all the application scopes available as delegated scopes too? This would increase the complexity of obtaining an access token, and our authorization code, which we initially were not too keen to handle. That is we why chose to create a single scope “user_impersonation”, which any frontend will use – meaning that all frontends can do any action that the user can do. If our customers chooses to build a frontend themselves for a single of our features, right now, the access token that they will get can be used for other services too.

Of course, there are authorization controls in place – we use user roles. As an example, in order to read identities, you need the “IAM Core – Administrator” or “IAM Core – Reader” role, otherwise you are denied access.

In the next part, we will look more into details on token acquisition and how we provide Portal and PowerShell access to our customers.

Leave a Reply