Microsoft identity platform code samples (v2.0 endpoint)

You can use Microsoft identity platform to:

  • Add authentication and authorization to your web applications and web APIs.
  • Require an access token to access a protected web API.

This article briefly describes and provides you with links to samples for the Microsoft identity platform endpoint. These samples show you how it's done, and also provide code snippets that you can use in your applications. On the code sample page, you'll find detailed readme topics that help with requirements, installation, and setup. Comments within the code help you understand the critical sections.

Note

If you're interested in v1.0 samples, see Azure AD code samples (v1.0 endpoint).

To understand the basic scenario for each sample type, see App types for the Microsoft identity platform endpoint.

You can also contribute to the samples on GitHub. To learn how, see Microsoft Azure Active Directory samples and documentation.

Single-page applications

These samples show how to write a single-page application secured with Microsoft identity platform. These samples use one of the flavors of MSAL.js.

Platform Description Link
This image shows the JavaScript logo JavaScript (msal.js) Calls Microsoft Graph javascript-graphapi-web-v2
This image shows the JavaScript logo JavaScript (msal.js) Calls B2C b2c-javascript-msal-singlepageapp
This image shows the JavaScript logo JavaScript (msal.js) Calls own web API javascript-singlepageapp-dotnet-webapi-v2
This image shows the Angular JS logo JavaScript (MSAL AngularJS) Calls Microsoft Graph MsalAngularjsDemoApp
This image shows the Angular logo JavaScript (MSAL Angular) Calls Microsoft Graph MSALAngularDemoApp

Web applications

The following samples illustrate web applications that sign in users. Some samples also demonstrate the application calling Microsoft Graph, or your own web API with the user's identity.

Platform Only signs in users Signs in users and calls Microsoft Graph
This image shows the ASP.NET Core logo

ASP.NET Core 2.2

ASP.NET Core WebApp signs-in users tutorial Same sample in the ASP.NET Core Web App calls Microsoft Graph phase
This image shows the ASP.NET logo

ASP.NET

ASP.NET Quickstart

dotnet-webapp-openidconnect-v2

dotnet-admin-restricted-scopes-v2

msgraph-training-aspnetmvcapp
This image shows the Java logo ms-identity-java-webapp: an MSAL4J web app calling Microsoft graph
This image shows the Node.js logo Node.js Quickstart
This image shows the Ruby logo msgraph-training-rubyrailsapp

Desktop and mobile public client apps

The following samples show public client applications (desktop or mobile applications) that access the Microsoft Graph API, or your own web API in the name of a user. All these client applications use Microsoft Authentication Library (MSAL).

Client application Platform Flow/Grant Calls Microsoft Graph Calls an ASP.NET Core 2.0 web API
Desktop (WPF) This image shows the .NET/C# logo interactive dotnet-desktop-msgraph-v2 dotnet-native-aspnetcore-v2
Desktop (Console) This image shows the .NET/C# (Desktop) logo Integrated Windows Authentication dotnet-iwa-v2
Desktop (Console) This image shows the .NET/C# (Desktop) logo Username/Password dotnetcore-up-v2
Mobile (Android, iOS, UWP) This image shows the .NET/C# (Xamarin) logo interactive xamarin-native-v2
Mobile (iOS) This image shows iOS/Objective-C or Swift interactive ios-swift-objc-native-v2

ios-native-nxoauth2-v2

Desktop (macOS) macOS interactive macOS-swift-objc-native-v2
Mobile (Android-Java) This image shows the Android logo interactive android-Java
Mobile (Android-Kotlin) This image shows the Android logo interactive android-Kotlin

Daemon applications

The following samples show an application that accesses the Microsoft Graph API with its own identity (with no user).

Client application Platform Flow/Grant Calls Microsoft Graph
Console This image shows the .NET Core logo

ASP.NET

Client Credentials dotnetcore-daemon-v2
Web app This image shows the ASP.NET logo

ASP.NET

Client Credentials dotnet-daemon-v2

Headless applications

The following sample shows a public client application running on a device without a web browser. The app can be a command-line tool, an app running on Linux or Mac, or an IoT application. The sample features an app accessing the Microsoft Graph API, in the name of a user who signs-in interactively on another device (such as a mobile phone). This client application uses Microsoft Authentication Library (MSAL).

Client application Platform Flow/Grant Calls Microsoft Graph
Desktop (Console) This image shows the .NET/C# (Desktop) logo Device code flow dotnetcore-devicecodeflow-v2

Web APIs

The following samples show how to protect a web API with the Microsoft identity platform endpoint, and how to call a downstream API from the web API.

Platform Sample
This image shows the ASP.NET Core logo

ASP.NET Core 2.2

ASP.NET Core web API (service) of dotnet-native-aspnetcore-v2
This image shows the ASP.NET logo

ASP.NET MVC

Web API (service) of ms-identity-aspnet-webapi-onbehalfof

Azure Functions as web APIs

The following samples show how to protect an Azure Function using HttpTrigger and exposing a web API with the Microsoft identity platform endpoint, and how to call a downstream API from the web API.

Platform Sample
This image shows the ASP.NET Core logo

ASP.NET Core 2.2

ASP.NET Core web API (service) Azure Function of dotnet-native-aspnetcore-v2
This image shows the Node.js logo

NodeJS

Web API (service) of NodeJS and passport-azure-ad
This image shows the Python logo

Python

Web API (service) of Python
This image shows the Node.js logo

NodeJS

Web API (service) of NodeJS and passport-azure-ad using on behalf of

Other Microsoft Graph samples

To learn about samples and tutorials that demonstrate different usage patterns for the Microsoft Graph API, including authentication with Azure AD, see Microsoft Graph Community samples & tutorials.

See also