Microsoft identity platform app types and authentication flows
Article
The Microsoft identity platform supports authentication for different kinds of modern application architectures. All of the architectures are based on the industry-standard protocols OAuth 2.0 and OpenID Connect. By using the authentication libraries for the Microsoft identity platform, applications authenticate identities and acquire tokens to access protected APIs.
This article describes authentication flows and the application scenarios that they're used in.
Application categories
Security tokens can be acquired from several types of applications, including:
Web apps
Mobile apps
Desktop apps
Web APIs
Tokens can also be acquired by apps running on devices that don't have a browser or are running on the Internet of Things (IoT).
The following sections describe the categories of applications.
Protected resources vs. client applications
Authentication scenarios involve two activities:
Acquiring security tokens for a protected web API: We recommend that you use the Microsoft Authentication Library (MSAL), developed and supported by Microsoft.
Protecting a web API or a web app: One challenge of protecting these resources is validating the security token. On some platforms, Microsoft offers middleware libraries.
With users or without users
Most authentication scenarios acquire tokens on behalf of signed-in users.
However, there are also daemon apps. In these scenarios, applications acquire tokens on behalf of themselves with no user.
Single-page, public client, and confidential client applications
Security tokens can be acquired by multiple types of applications. These applications tend to be separated into the following three categories. Each is used with different libraries and objects.
Single-page applications: Also known as SPAs, these are web apps in which tokens are acquired by a JavaScript or TypeScript app running in the browser. Many modern apps have a single-page application at the front end that's primarily written in JavaScript. The application often uses a framework like Angular, React, or Vue. MSAL.js is the only Microsoft Authentication Library that supports single-page applications.
Public client applications: Apps in this category, like the following types, always sign in users:
Desktop apps that call web APIs on behalf of signed-in users
Mobile apps
Apps running on devices that don't have a browser, like those running on IoT
Confidential client applications: Apps in this category include:
Web apps that call a web API
Web APIs that call a web API
Daemon apps, even when implemented as a console service like a Linux daemon or a Windows service
Sign-in audience
The available authentication flows differ depending on the sign-in audience. Some flows are available only for work or school accounts. Others are available both for work or school accounts and for personal Microsoft accounts.
The Microsoft identity platform supports authentication for these app architectures:
Single-page apps
Web apps
Web APIs
Mobile apps
Native apps
Daemon apps
Server-side apps
Applications use the different authentication flows to sign in users and get tokens to call protected APIs.
Single-page application
Many modern web apps are built as client-side single-page applications. These applications use JavaScript or a framework like Angular, Vue, and React. These applications run in a web browser.
Single-page applications differ from traditional server-side web apps in terms of authentication characteristics. By using the Microsoft identity platform, single-page applications can sign in users and get tokens to access back-end services or web APIs. The Microsoft identity platform offers two grant types for JavaScript applications:
MSAL.js (2.x)
MSAL.js (1.x)
Web app that signs in a user
To help protect a web app that signs in a user:
If you develop in .NET, you use ASP.NET or ASP.NET Core with the ASP.NET OpenID Connect middleware. Protecting a resource involves validating the security token, which is done by the IdentityModel extensions for .NET and not MSAL libraries.
Web app that signs in a user and calls a web API on behalf of the user
To call a web API from a web app on behalf of a user, use the authorization code flow and store the acquired tokens in the token cache. When needed, MSAL refreshes tokens and the controller silently acquires tokens from the cache.
Desktop app that calls a web API on behalf of a signed-in user
For a desktop app to call a web API that signs in users, use the interactive token-acquisition methods of MSAL. With these interactive methods, you can control the sign-in UI experience. MSAL uses a web browser for this interaction.
There's another possibility for Windows-hosted applications on computers joined either to a Windows domain or by Microsoft Entra ID. These applications can silently acquire a token by using integrated Windows authentication.
Applications running on a device without a browser can still call an API on behalf of a user. To authenticate, the user must sign in on another device that has a web browser. This scenario requires that you use the device code flow.
Though we don't recommend that you use it, the username/password flow is available in public client applications. This flow is still needed in some scenarios like DevOps.
Using the username/password flow constrains your applications. For instance, applications can't sign in a user who needs to use multifactor authentication or the Conditional Access tool in Microsoft Entra ID. Your applications also don't benefit from single sign-on. Authentication with the username/password flow goes against the principles of modern authentication and is provided only for legacy reasons.
In desktop apps, if you want the token cache to persist, you can customize the token cache serialization. By implementing dual token cache serialization, you can use backward-compatible and forward-compatible token caches.
Mobile app that calls a web API on behalf of an interactive user
Similar to a desktop app, a mobile app calls the interactive token-acquisition methods of MSAL to acquire a token for calling a web API.
MSAL iOS and MSAL Android use the system web browser by default. However, you can direct them to use the embedded web view instead. There are specificities that depend on the mobile platform: Universal Windows Platform (UWP), iOS, or Android.
Some scenarios, like those that involve Conditional Access related to a device ID or a device enrollment, require a broker to be installed on the device. Examples of brokers are Microsoft Company Portal on Android and Microsoft Authenticator on Android and iOS.
A mobile app that uses MSAL iOS or MSAL Android can have app protection policies applied to it. For instance, the policies might prevent a user from copying protected text. The mobile app is managed by Intune and is recognized by Intune as a managed app. For more information, see Microsoft Intune App SDK overview.
The Intune App SDK is separate from MSAL libraries and interacts with Microsoft Entra ID on its own.
Protected web API
You can use the Microsoft identity platform endpoint to secure web services like your app's RESTful API. A protected web API is called through an access token. The token helps secure the API's data and authenticate incoming requests. The caller of a web API appends an access token in the authorization header of an HTTP request.
If you want to protect your ASP.NET or ASP.NET Core web API, validate the access token. For this validation, you use the ASP.NET JWT middleware. The validation is done by the IdentityModel extensions for .NET library and not by MSAL.NET.
Web API that calls another web API on behalf of a user
For your protected web API to call another web API on behalf of a user, your app needs to acquire a token for the downstream web API. Such calls are sometimes referred to as service-to-service calls. Web APIs that call other web APIs need to provide custom cache serialization.
Daemon app that calls a web API in the daemon's name
Apps that have long-running processes or that operate without user interaction also need a way to access secure web APIs. Such an app can authenticate and get tokens by using the app's identity. The app proves its identity by using a client secret or certificate.
You can write such daemon apps that acquire a token for the calling app by using the client credential acquisition methods in MSAL. These methods require a client secret that you add to the app registration in Microsoft Entra ID. The app then shares the secret with the called daemon. Examples of such secrets include application passwords, certificate assertion, and client assertion.
You use authentication flows to implement the application scenarios that are requesting tokens. There isn't a one-to-one mapping between application scenarios and authentication flows.
Microsoft Authentication Libraries support multiple platforms:
.NET
.NET Framework
Java
JavaScript
macOS
Native Android
Native iOS
Node.js
Python
Windows 10/UWP
You can also use various languages to build your applications.
In the Windows column of the following table, each time .NET is mentioned, .NET Framework is also possible. The latter is omitted to avoid cluttering the table.