Azure Active Directory code samples (V1 endpoint)


This article is part of the Azure Active Directory developer's guide.

You can use Microsoft Azure Active Directory (Azure AD) to add authentication and authorization to your web applications and web APIs.

This section provides links to samples you can use to learn more about the Azure AD V1 endpoint. These samples show you how it's done along with code snippets that you can use in your applications. On the code sample page, you'll find detailed read-me topics that help with requirements, installation, and set-up. And the code is commented to help you understand the critical sections.


If you are interested in Azure AD V2 code samples, see v2.0 code samples by scenario.

To understand the basic scenario for each sample type, see Authentication scenarios for Azure AD.

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

Desktop and mobile public client applications calling Microsoft Graph or a Web API

The following samples show public client applications (desktop/mobile applications) that access the Microsoft Graph or a Web API in the name of a user.

Client application Platform Flow/Grant Calls Microsoft Graph Calls an ASP.NET or ASP.NET Core 2.0 Web API
Desktop (WPF) .NET/C# Interactive dotnet-native-multitarget Dotnet-native-desktop


Mobile (UWP) .NET/C# Interactive dotnet-native-uwp-wam dotnet-windows-store (single tenant Web API)

dotnet-webapi-multitenant-windows-store (multi-tenant Web API)

Mobile (Android, iOS, UWP) .NET/C# (Xamarin) Interactive dotnet-native-multitarget
Mobile (Android) Android/Java Interactive android
Mobile (iOS) iOS/Objective C Interactive nativeClient-iOS
Desktop (Console) .NET/C# Username / Password

Windows Integrated Authentication

Desktop (Console) .NET Core/C# Device profile dotnet-deviceprofile

Web Applications

Web Applications signing in users, calling Microsoft Graph, or a Web API with the user's identity

Platform Only signs in users Calls Microsoft Graph or AAD Graph Calls another ASP.NET or ASP.NET Core 2.0 Web API
ASP.NET 4.5 webApp-openidconnect-dotnet


dotnet-webapp-multitenant-openidconnect (AAD Graph)
ASP.NET Core 2.0 dotnet-webapp-openidconnect-aspnetcore webapp-webapi-multitenant-openidconnect-aspnetcore (AAD Graph) dotnet-webapp-webapi-openidconnect-aspnetcore
ASP.NET 4.5 dotnet-webapp-webapi-oauth2-useridentity
Python python-webapp-graphapi
Java java-webapp-openidconnect
PHP php-graphapi-web

Web applications demonstrating role-based access control (authorization)

The following samples show how to implement role-based access control, which is used to restrict the permissions of certain features of a web application to certain users. The users are authorized depending on whether they belong to an Azure AD group or role.

Platform Sample Description
ASP.NET 4.5 dotnet-webapp-groupclaims A .NET 4.5 MVC web app that uses Azure AD groups for authorization
ASP.NET 4.5 dotnet-webapp-roleclaims A .NET 4.5 MVC web app that uses Azure AD roles for authorization

Daemon applications (accessing Web APIs with the application's identity)

The following samples show desktop or web applications that access the Microsoft Graph or a web API with no user (with the application identity).

Client application Platform Flow/Grant Calls Microsoft Graph Calls an ASP.NET or ASP.NET Core 2.0 Web API
Daemon app (Console) .NET/C# Client Credentials with app secret or certificate dotnet-daemon


Daemon app (Console) .NET Core/C# Client Credentials with certificate dotnetcore-daemon-certificate-credential
Desktop Java Client credentials java-native-headless
ASP.NET Web App .NET/C# Client credentials dotnet-webapp-webapi-oauth2-appidentity

Web APIs

Web API protected by Azure Active Directory

The following sample shows how to protect a node.js web API with Azure AD.

Platform Sample Description
Node.js node-webapi NodeJS web API that is secured using Azure AD and OAuth 2.0 access tokens.

Web API calling Microsoft Graph or another Web API

The following samples demonstrate a web API that calls another web API. The second sample shows how to handle conditional access.

Platform Calls Microsoft Graph Calls another ASP.NET or ASP.NET Core 2.0 Web API
ASP.NET 4.5 dotnet-webapi-onbehalfof dotnet-webapi-onbehalfof
ASP.NET 4.5 dotnet-webapi-onbehalfof-ca dotnet-webapi-onbehalfof-ca

Single page applications

This sample shows how to write a single page application secured with Azure AD.

Platform Calls Microsoft Graph Calls its own API Calls another Web API
JavaScript / ASP.NET 4.x javascript-singlepageapp
JavaScript (AngularJS) / ASP.NET 4.x angularjs-singlepageapp
JavaScript (AngularJS) / ASP.NET 4.x angularjs-singlepageapp-cors

Other Microsoft Graph samples

For 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

Azure Active Directory Developer's Guide

Azure AD Graph API Conceptual and Reference

Azure AD Graph API Helper Library