• Stars
    star
    129
  • Rank 279,262 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

How to manually process a JWT access token in a web API using the JSON Web Token Handler For the Microsoft .Net Framework 4.5.
page_type languages products name urlFragment services platforms author level client service endpoint
sample
csharp
aspnet-core
microsoft-identity-web
azure-active-directory
How to manually validate a JWT access token using the Microsoft identity platform
active-directory-dotnet-webapi-manual-jwt-validation
active-directory
dotnetcore
kalyankrishna1
300
.NET Desktop App (WPF)
ASP.NET Web API
AAD v2.0

How to manually validate a JWT access token using the Microsoft identity platform

Build badge

Overview

This sample demonstrates how to manually validate an access token issued to a web API protected by the Microsoft Identity Platform. Here a .NET Desktop App (WPF) calls a protected ASP.NET Web API that is secured using Azure AD.

About this sample

A Web API that accepts bearer token as a proof of authentication is secured by validating the token they receive from the callers. When a developer generates a skeleton Web API code using Visual Studio, token validation libraries and code to carry out basic token validation is automatically generated for the project. An example of the generated code using the asp.net security middleware and Microsoft Identity Model Extension for .NET to validate tokens is provided below.

public void ConfigureAuth(IAppBuilder app)
{
    app.UseWindowsAzureActiveDirectoryBearerAuthentication(
        new WindowsAzureActiveDirectoryBearerAuthenticationOptions
        {
            Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
            TokenValidationParameters = new TokenValidationParameters {
                    ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
            },
        });
}

The code above will validate the issuer, audience, and the signing tokens of the access token, which is usually sufficient for most scenarios. But often the developer's requirements are more than what these defaults provide. Examples of these requirements can be:

  • Restricting the Web API to one or more Apps (App IDs)
  • Restricting the Web API to just one or more tenants (Issuers)
  • Implement custom authorization.

Always verify that the access token presented to the Web Api has the expected scopes or roles

This sample demonstrates how to manually process a JWT access token in a web API using the JSON Web Token Handler For the Microsoft .Net Framework. This sample is equivalent to the NativeClient-DotNet sample, except that, in the TodoListService, instead of using OWIN middleware to process the token, the token is processed manually in application code. The client, which demonstrates how to acquire a token for this protected API, is unchanged from the NativeClient-DotNet sample.

Topology

Scenario: protecting a Web API - acquiring a token for the protected Web API

When you want to protect a Web API, you request your clients to get a Security token for your API, and you validate it. Usually, for ASP.NET applications this validation is delegated to the OWIN middleware, but you can also validate it yourself, leveraging the System.IdentityModel.Tokens.Jwt library.

Token Validation

A token represents the outcome of an authentication operation with some artifact that can be unambiguously tied to the Identity Provider that performed the authentication, without relying on any special network infrastructure.

With Azure Active Directory taking the full responsibility of verifying user's raw credentials, the token receiver's responsibility shifts from verifying raw credentials to verifying that their caller did indeed go through your identity provider of choice and successfully authenticated. The identity provider represents successful authentication operations by issuing a token, hence the job now becomes to validate that token.

What to validate?

While you should always validate tokens issued to the resources (audience) that you are developing, your application will also obtain access tokens for other resources from AAD. AAD will provide an access token in whatever token format that is appropriate to that resource. This access token itself should be treated like an opaque blob by your application, as your app isn’t the access token’s intended audience and thus your app should not bother itself with looking into the contents of this access token. Your app should just pass it in the call to the resource. It's the called resource's responsibility to validate this access token.

Validating the claims

When an application receives an access token upon user sign-in, it should also perform a few checks against the claims in the access token. These verifications include but are not limited to:

  • audience claim, to verify that the ID token was intended to be given to your application
  • not before and "expiration time" claims, to verify that the ID token has not expired
  • issuer claim, to verify that the token was issued to your app by the v2.0 endpoint
  • nonce, as a token replay attack mitigation

You are advised to use standard library methods like JwtSecurityTokenHandler.ValidateToken Method (JwtSecurityToken) to do most of the aforementioned heavy lifting. You can further extend the validation process by making decisions based on claims received in the token. For example, multi-tenant applications can extend the standard validation by inspecting the value of the tid claim (Tenant ID) against a set of pre-selected tenants to ensure they only honor tokens from tenants of their choice. Details on the claims provided in JWT tokens are listed in the Azure AD token reference. When you debug your application and want to understand the claims held by the token, you might find it useful to use the JWT token inspector tool.

Looking for previous versions of this code sample? Check out the tags on the releases GitHub page.

[!Note] If you want to run this sample on Azure Government, navigate to the "Azure Government Deviations" section at the bottom of this page.

Prerequisites

  • Visual Studio
  • An Azure AD tenant. For more information, see: How to get an Azure AD tenant
  • A user account in your Azure AD tenant. This sample will not work with a personal Microsoft account. If you're signed in to the Azure portal with a personal Microsoft account and have not created a user account in your directory before, you will need to create one before proceeding.

Setup

Step 1: Clone or download this repository

From your shell or command line:

git clone https://github.com/Azure-Samples/active-directory-dotnet-webapi-manual-jwt-validation.git

or download and extract the repository .zip file.

⚠️ To avoid path length limitations on Windows, we recommend cloning into a directory near the root of your drive.

Register the sample application(s) with your Azure Active Directory tenant

There are two projects in this sample. Each needs to be separately registered in your Azure AD tenant. To register these projects, you can:

  • follow the steps below for manually register your apps
  • or use PowerShell scripts that:
    • automatically creates the Azure AD applications and related objects (passwords, permissions, dependencies) for you
    • modify the Visual Studio projects' configuration files.
Expand this section if you want to use this automation:

⚠️ If you have never used Azure AD Powershell before, we recommend you go through the App Creation Scripts once to ensure that your environment is prepared correctly for this step.

  1. On Windows, run PowerShell as Administrator and navigate to the root of the cloned directory

  2. If you have never used Azure AD Powershell before, we recommend you go through the App Creation Scripts once to ensure that your environment is prepared correctly for this step.

  3. In PowerShell run:

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process -Force
  4. Run the script to create your Azure AD application and configure the code of the sample application accordingly.

  5. In PowerShell run:

    cd .\AppCreationScripts\
    .\Configure.ps1

    Other ways of running the scripts are described in App Creation Scripts The scripts also provide a guide to automated application registration, configuration and removal which can help in your CI/CD scenarios.

  6. Open the Visual Studio solution and click start to run the code.

Choose the Azure AD tenant where you want to create your applications

As a first step you'll need to:

  1. Sign in to the Azure portal.
  2. If your account is present in more than one Azure AD tenant, select your profile at the top right corner in the menu on top of the page, and then switch directory to change your portal session to the desired Azure AD tenant.

Register the service app (TodoListService-ManualJwt)

  1. Navigate to the Azure portal and select the Azure AD service.
  2. Select the App Registrations blade on the left, then select New registration.
  3. In the Register an application page that appears, enter your application's registration information:
    • In the Name section, enter a meaningful application name that will be displayed to users of the app, for example TodoListService-ManualJwt.
    • Under Supported account types, select Accounts in this organizational directory only.
  4. Select Register to create the application.
  5. In the app's registration screen, find and note the Application (client) ID. You use this value in your app's configuration file(s) later in your code.
  6. Select Save to save your changes.
  7. In the app's registration screen, select the Expose an API blade to the left to open the page where you can declare the parameters to expose this app as an API for which client applications can obtain access tokens for. The first thing that we need to do is to declare the unique resource URI that the clients will be using to obtain access tokens for this API. To declare an resource URI, follow the following steps:
    • Select Set next to the Application ID URI to generate a URI that is unique for this app.
    • For this sample, accept the proposed Application ID URI (api://{clientId}) by selecting Save.
  8. All APIs have to publish a minimum of one scope for the client's to obtain an access token successfully. To publish a scope, follow these steps:
    • Select Add a scope button open the Add a scope screen and Enter the values as indicated below:
      • For Scope name, use access_as_user.
      • Select Admins and users options for Who can consent?.
      • For Admin consent display name type Access TodoListService-ManualJwt.
      • For Admin consent description type Allows the app to access TodoListService-ManualJwt as the signed-in user.
      • For User consent display name type Access TodoListService-ManualJwt.
      • For User consent description type Allow the application to access TodoListService-ManualJwt on your behalf.
      • Keep State as Enabled.
      • Select the Add scope button on the bottom to save this scope.
  9. Select the Manifest blade on the left.
    • Set accessTokenAcceptedVersion property to 2.
    • Click on Save.

Configure the service app (TodoListService-ManualJwt) to use your app registration

Open the project in your IDE (like Visual Studio or Visual Studio Code) to configure the code.

In the steps below, "ClientID" is the same as "Application ID" or "AppId".

  1. Open the TodoListService-ManualJwt\Web.Config file.
  2. Find the key ida:TenantId and replace the existing value with your Azure AD tenant ID.
  3. Find the key ida:Audience and replace the existing value with the App ID URI you registered earlier, when exposing an API. For instance use api://<application_id>.
  4. Find the key ida:ClientId and replace the existing value with the application ID (clientId) of TodoListService-ManualJwt app copied from the Azure portal.

Register the client app (TodoListClient-ManualJwt)

  1. Navigate to the Azure portal and select the Azure AD service.
  2. Select the App Registrations blade on the left, then select New registration.
  3. In the Register an application page that appears, enter your application's registration information:
    • In the Name section, enter a meaningful application name that will be displayed to users of the app, for example TodoListClient-ManualJwt.
    • Under Supported account types, select Accounts in this organizational directory only.
  4. Select Register to create the application.
  5. In the app's registration screen, find and note the Application (client) ID. You use this value in your app's configuration file(s) later in your code.
  6. In the app's registration screen, select Authentication in the menu.
  7. Select Save to save your changes.
  8. In the app's registration screen, select the API permissions blade in the left to open the page where we add access to the APIs that your application needs.
    • Select the Add a permission button and then,
    • Ensure that the My APIs tab is selected.
    • In the list of APIs, select the API TodoListService-ManualJwt.
    • In the Delegated permissions section, select the Access 'TodoListService-ManualJwt' in the list. Use the search box if necessary.
    • Select the Add permissions button at the bottom.

Configure the client app (TodoListClient-ManualJwt) to use your app registration

Open the project in your IDE (like Visual Studio or Visual Studio Code) to configure the code.

In the steps below, "ClientID" is the same as "Application ID" or "AppId".

  1. Open the TodoListClient\App.Config file.
  2. Find the key ida:Tenant and replace the existing value with your Azure AD tenant name.
  3. Find the key ida:ClientId and replace the existing value with the application ID (clientId) of TodoListClient-ManualJwt app copied from the Azure portal.
  4. Find the key todo:TodoListResourceId and replace the existing value with the App ID URI you registered earlier, when exposing an API. For instance use api://<application_id>.
  5. Find the key todo:TodoListBaseAddress and replace the existing value with the base address of TodoListService-ManualJwt (by default https://localhost:44324).

Running the sample

For Visual Studio Users

Clean the solution, rebuild the solution, and run it. You might want to go into the solution properties and set both projects as startup projects, with the service project starting first.

Explore the sample

Explore the sample by signing in, adding items to the To Do list, removing the user account, and starting again. Notice that if you stop the application without removing the user account, the next time you run the application you won't be prompted to sign in again - that is the sample implements a persistent cache for MSAL, and remembers the tokens from the previous run.

ℹ️ Did the sample not work for you as expected? Did you encounter issues trying this sample? Then please reach out to us using the GitHub Issues page.

Consider taking a moment to share your experience with us.

About The Code

The manual JWT validation occurs in the TokenValidationHandler implementation in the Global.aspx.cs file in the TodoListService-ManualJwt project. Each time a call is made to the web API, the TokenValidationHandler.SendAsync() handler is executed:

This method:

  1. Gets the token from the Authorization headers
  2. Gets the open ID configuration, including keys from the Azure AD discovery endpoint
  3. Sets the parameters to validate in GetTokenValidationParameters()
    • the audience - the application accepts both its App ID URI and its AppID/clientID
    • the valid issuers - the application accepts both Azure AD V1 and Azure AD V2
  4. Then the token is validated
  5. An asp.net claims principal is created after a successful validation
  6. ensures that the web API is consented to and provisioned in the Azure AD tenant from where the access token originated
  7. Finally, a check for scopes that the web API expects from the caller is carried out

The TokenValidationHandler class is registered with ASP.NET in the TodoListService-ManualJwt/Global.asx.cs file, in the Application_Start() method.

For more validation options, please refer to TokenValidationParameters.cs

Providing your own Custom token validation handler

If you do not wish to control the token validation from its very beginning to the end as laid out in the Global.asax.cs, but only limit yourself to validate business logic based on claims in the presented token, you can craft a Custom token handler as provided in the example below.
The provided example, validates to allow callers from a list of whitelisted tenants only.

  1. Create a custom handler implementation
public class CustomTokenHandler : JwtSecurityTokenHandler
{
   public override ClaimsPrincipal ValidateToken(
      string token, TokenValidationParameters validationParameters,
      out SecurityToken validatedToken)
   {
      try
      {
            var claimsPrincipal = base.ValidateToken(token, validationParameters, out validatedToken);

            string[] allowedTenants = { "14c2f153-90a7-4689-9db7-9543bf084dad", "af8cc1a0-d2aa-4ca7-b829-00d361edb652", "979f4440-75dc-4664-b2e1-2cafa0ac67d1" };
            string tenantId = claimsPrincipal.Claims.FirstOrDefault(x => x.Type == "tid" || x.Type == "http://schemas.microsoft.com/identity/claims/tenantid")?.Value;

            if (!allowedTenants.Contains(tenantId))
            {
               throw new Exception("This tenant is not authorized");
            }

            return claimsPrincipal;
      }
      catch (Exception e)
      {            
            throw;
      }
   }
}
  1. Assign the custom handler in Startup.Auth.cs
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
             new WindowsAzureActiveDirectoryBearerAuthenticationOptions
             {
                Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
                TokenValidationParameters = new TokenValidationParameters
                {
                   ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
                },
                TokenHandler = new CustomTokenHandler()
             });

How To Recreate This Sample

First, in Visual Studio 2017 create an empty solution to host the projects. Then, follow these steps to create each project.

Creating the TodoListService-ManualJwt Project

  1. In Visual Studio, create a new Visual C# ASP.NET Web Application (.NET Framework). Choose Web Api in the next screen. Leave the project's chosen authentication mode as the default, that is, No Authentication".

  2. Set SSL Enabled to be True. Note the SSL URL.

  3. In the project properties, Web properties, set the Project Url to be the SSL URL.

  4. Add the latest stable JSON Web Token Handler For the Microsoft .Net Framework NuGet, System.IdentityModel.Tokens.Jwt, to the project.

  5. Add an assembly reference to System.IdentityModel.

  6. In the Models folder, add a new class named TodoItem.cs. Copy the implementation of TodoItem from this sample into the class.

  7. Create a folder named Utils , add a new class named ClaimConstants.cs. Copy the implementation of ClaimConstants.cs from this sample into the class.

  8. Add a new, empty, Web API 2 controller named TodoListController.

  9. Copy the implementation of the TodoListController from this sample into the controller.

  10. Open Global.asax, and copy the implementation from this sample into the controller. Note that a single line is added at the end of Application_Start(),

    GlobalConfiguration.Configuration.MessageHandlers.Add(new TokenValidationHandler());
  11. In web.config create keys for ida:AADInstance, ida:Tenant, and ida:Audience and set them accordingly. For the global Azure cloud, the value of ida:AADInstance is https://login.microsoftonline.com/{0}.

Creating the TodoListClient Project

  1. In the solution, create a new Windows --> Windows Classic Desktop -> WPF App(.NET Framework) called TodoListClient.
  2. Add the Microsoft Authentication Library (MSAL) NuGet, Microsoft.Identity.Client to the project.
  3. Add assembly references to System.Net.Http, System.Web.Extensions, and System.Configuration.
  4. Add a new class to the project named TodoItem.cs. Copy the code from the sample project file of the same name into this class, completely replacing the code in the file in the new project.
  5. Add a new class to the project named FileCache.cs. Copy the code from the sample project file of the same name into this class, completely replacing the code in the file in the new project.
  6. Copy the markup from MainWindow.xaml in the sample project into the file of the same name in the new project, completely replacing the markup in the file in the new project.
  7. Copy the code from MainWindow.xaml.cs in the sample project into the file of the same name in the new project, completely replacing the code in the file in the new project.
  8. In app.config create keys for ida:AADInstance, ida:Tenant, ida:ClientId, todo:TodoListResourceId, and todo:TodoListBaseAddress and set them accordingly. For the global Azure cloud, the value of ida:AADInstance is https://login.microsoftonline.com/{0}.

Finally, in the properties of the solution itself, set both projects as startup projects.

How to deploy this sample to Azure

This project has one WebApp / Web API projects. To deploy them to Azure Web Sites, you'll need, for each one, to:

  • create an Azure Web Site
  • publish the Web App / Web APIs to the web site, and
  • update its client(s) to call the web site instead of IIS Express.

Create and publish the TodoListService-ManualJwt to an Azure Web Site

  1. Sign in to the Azure portal.

  2. Click Create a resource in the top left-hand corner, select Web --> Web App, and give your web site a name, for example, TodoListService-ManualJwt-contoso.azurewebsites.net.

  3. Thereafter select the Subscription, Resource Group, App service plan and Location. OS will be Windows and Publish will be Code.

  4. Click Create and wait for the App Service to be created.

  5. Once you get the Deployment succeeded notification, then click on Go to resource to navigate to the newly created App service.

  6. From the Overview tab of the App Service, download the publish profile by clicking the Get publish profile link and save it. Other deployment mechanisms, such as from source control, can also be used.

  7. Switch to Visual Studio and go to the TodoListService-ManualJwt project. Right click on the project in the Solution Explorer and select Publish. Click Import Profile on the bottom bar, and import the publish profile that you downloaded earlier.

  8. Click on Configure and in the Connection tab, update the Destination URL so that it is a https in the home page url, for example https://TodoListService-ManualJwt-contoso.azurewebsites.net. Click Next.

  9. On the Settings tab, make sure Enable Organizational Authentication is NOT selected. Click Save. Click on Publish on the main screen.

  10. Visual Studio will publish the project and automatically open a browser to the URL of the project. If you see the default web page of the project, the publication was successful.

Update the Active Directory tenant application registration for TodoListService-ManualJwt

  1. Navigate back to to the Azure portal. In the left-hand navigation pane, select the Azure Active Directory service, and then select App registrations (Preview).
  2. In the resultant screen, select the TodoListService-ManualJwt application.
  3. From the Branding menu, update the Home page URL, to the address of your service, for example https://TodoListService-ManualJwt-contoso.azurewebsites.net. Save the configuration.
  4. Add the same URL in the list of values of the Authentication -> Redirect URIs menu. If you have multiple redirect urls, make sure that there a new entry using the App service's Uri for each redirect url.

Update the TodoListClient-ManualJwt to call the TodoListService-ManualJwt Running in Azure Web Sites

  1. In Visual Studio, go to the TodoListClient-ManualJwt project.
  2. Open TodoListClient\App.Config. Only one change is needed - update the todo:TodoListBaseAddress key value to be the address of the website you published, for example, https://TodoListService-ManualJwt-contoso.azurewebsites.net.
  3. Run the client! If you are trying multiple different client types (for example, .Net, Windows Store, Android, iOS) you can have them all call this one published web API.

NOTE: Remember, the To Do list is stored in memory in this TodoListService sample. Azure Web Sites will spin down your web site if it is inactive, and your To Do list will get emptied. Also, if you increase the instance count of the web site, requests will be distributed among the instances. To Do will, therefore, not be the same on each instance.

Azure Government Deviations

In order to run this sample on Azure Government, you can follow through the steps above with a few variations:

  • Step 2:

    • You must register this sample for your AAD Tenant in Azure Government by following Step 2 above in the Azure Government portal.
  • Step 3:

    • Before configuring the sample, you must make sure your Visual Studio is connected to Azure Government.
    • Navigate to the Web.config file. Replace the ida:AADInstance property in the Azure AD section with https://login.microsoftonline.us/.

Once those changes have been accounted for, you should be able to run this sample on Azure Government.

Troubleshooting

If you are using this sample with an Azure AD B2C custom policy, you might want to read #22, and change step 3. in the About The Code paragraph.

Community Help and Support

Use Stack Overflow to get support from the community. Ask your questions on Stack Overflow first and browse existing issues to see if someone has asked your question before. Make sure that your questions or comments are tagged with [msal dotnet azure-active-directory].

If you find a bug in the sample, please raise the issue on GitHub Issues.

To provide a recommendation, visit the following User Voice page.

Contributing

If you'd like to contribute to this sample, see CONTRIBUTING.MD.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

More information

For more information about token validation, see:

For more information about how the protocols work in this scenario and other scenarios, see Authentication Scenarios for Azure AD.

More Repositories

1

azure-search-openai-demo

A sample app for the Retrieval-Augmented Generation pattern running in Azure, using Azure AI Search for retrieval and Azure OpenAI large language models to power ChatGPT-style and Q&A experiences.
Python
5,707
star
2

cognitive-services-speech-sdk

Sample code for the Microsoft Cognitive Services Speech SDK
C#
1,955
star
3

graphrag-accelerator

One-click deploy of a Knowledge Graph powered RAG (GraphRAG) in Azure
Python
1,730
star
4

active-directory-aspnetcore-webapp-openidconnect-v2

An ASP.NET Core Web App which lets sign-in users (including in your org, many orgs, orgs + personal accounts, sovereign clouds) and call Web APIs (including Microsoft Graph)
PowerShell
1,366
star
5

openai

The repository for all Azure OpenAI Samples complementing the OpenAI cookbook.
Jupyter Notebook
1,090
star
6

contoso-real-estate

Intelligent enterprise-grade reference architecture for JavaScript, featuring OpenAI integration, Azure Developer CLI template and Playwright tests.
JavaScript
881
star
7

Cognitive-Speech-TTS

Microsoft Text-to-Speech API sample code in several languages, part of Cognitive Services.
C#
870
star
8

chat-with-your-data-solution-accelerator

A Solution Accelerator for the RAG pattern running in Azure, using Azure AI Search for retrieval and Azure OpenAI large language models to power ChatGPT-style and Q&A experiences. This includes most common requirements and best practices.
Python
816
star
9

blockchain

Azure Blockchain Content and Samples
HTML
786
star
10

serverless-chat-langchainjs

Build your own serverless AI Chat with Retrieval-Augmented-Generation using LangChain.js, TypeScript and Azure
Bicep
694
star
11

azure-search-openai-demo-csharp

A sample app for the Retrieval-Augmented Generation pattern running in Azure, using Azure Cognitive Search for retrieval and Azure OpenAI large language models to power ChatGPT-style and Q&A experiences.
C#
638
star
12

Serverless-microservices-reference-architecture

This reference architecture walks you through the decision-making process involved in designing, developing, and delivering a serverless application using a microservices architecture through hands-on instructions for configuring and deploying all of the architecture's components along the way. The goal is to provide practical hands-on experience in working with several Azure services and the technologies that effectively use them in a cohesive and unified way to build a serverless-based microservices architecture.
C#
493
star
13

modern-data-warehouse-dataops

DataOps for the Modern Data Warehouse on Microsoft Azure. https://aka.ms/mdw-dataops.
Shell
486
star
14

openai-plugin-fastapi

A simple ChatGPT Plugin running in Codespaces for dev and Azure for production.
Bicep
432
star
15

Azure-MachineLearning-DataScience

HTML
407
star
16

raspberry-pi-web-simulator

Raspberry Pi web simulator. Demo address:
JavaScript
406
star
17

contoso-chat

This sample has the full End2End process of creating RAG application with Prompt Flow and AI Studio. It includes GPT 3.5 Turbo LLM application code, evaluations, deployment automation with AZD CLI, GitHub actions for evaluation and deployment and intent mapping for multiple LLM task mapping.
Jupyter Notebook
400
star
18

MyDriving

Building IoT or Mobile solutions are fun and exciting. This year for Build, we wanted to show the amazing scenarios that can come together when these two are combined. So, we went and developed a sample application. MyDriving uses a wide range of Azure services to process and analyze car telemetry data for both real-time insights and long-term patterns and trends. The following features are supported in the current version of the mobile app.
C#
387
star
19

azure-voting-app-redis

Azure voting app used in docs.
Shell
370
star
20

azure-search-knowledge-mining

Azure Search Knowledge Mining Accelerator
CSS
370
star
21

azure-cli-samples

Contains Azure CLI scripts samples used for documentation at https://docs.microsoft.com
Shell
353
star
22

Synapse

Samples for Azure Synapse Analytics
Jupyter Notebook
348
star
23

nodejs-docs-hello-world

A simple nodejs application for docs
JavaScript
347
star
24

cognitive-services-quickstart-code

Code Examples used by the Quickstarts in the Cognitive Services Documentation
Jupyter Notebook
346
star
25

saga-orchestration-serverless

An orchestration-based saga implementation reference in a serverless architecture
C#
340
star
26

container-apps-store-api-microservice

Sample microservices solution using Azure Container Apps, Dapr, Cosmos DB, and Azure API Management
Shell
323
star
27

azure-sdk-for-go-samples

Examples of how to utilize Azure services from Go.
Go
296
star
28

AzureMapsCodeSamples

A set of code samples for the Azure Maps web control.
JavaScript
293
star
29

active-directory-dotnet-native-aspnetcore-v2

Calling a ASP.NET Core Web API from a WPF application using Azure AD v2.0
C#
280
star
30

jp-azureopenai-samples

Python
270
star
31

active-directory-b2c-custom-policy-starterpack

Azure AD B2C now allows uploading of a Custom Policy which allows full control and customization of the Identity Experience Framework
268
star
32

azureai-samples

Official community-driven Azure AI Examples
Jupyter Notebook
260
star
33

azure-batch-samples

Azure Batch and HPC Code Samples
C#
256
star
34

active-directory-b2c-dotnet-webapp-and-webapi

A combined sample for a .NET web application that calls a .NET web API, both secured using Azure AD B2C
JavaScript
244
star
35

openai-dotnet-samples

Azure OpenAI .NET Samples
Jupyter Notebook
236
star
36

streaming-at-scale

How to implement a streaming at scale solution in Azure
C#
234
star
37

azure-files-samples

This repository contains supporting code (PowerShell modules/scripts, ARM templates, etc.) for deploying, configuring, and using Azure Files.
PowerShell
231
star
38

azure-search-openai-javascript

A TypeScript sample app for the Retrieval Augmented Generation pattern running on Azure, using Azure AI Search for retrieval and Azure OpenAI and LangChain large language models (LLMs) to power ChatGPT-style and Q&A experiences.
TypeScript
231
star
39

service-fabric-dotnet-getting-started

Get started with Service Fabric with these simple introductory sample projects.
CSS
230
star
40

ansible-playbooks

Ansible Playbook Samples for Azure
226
star
41

iot-edge-opc-plc

Sample OPC UA server with nodes that generate random and increasing data, anomalies and much more ...
C#
222
star
42

cognitive-services-REST-api-samples

This is a repo for cognitive services REST API samples in 4 languages: C#, Java, Node.js, and Python.
HTML
217
star
43

active-directory-dotnetcore-daemon-v2

A .NET Core daemon console application calling Microsoft Graph or your own WebAPI with its own identity
PowerShell
215
star
44

active-directory-b2c-advanced-policies

Sample for use with Azure AD B2C with Custom Policies.
C#
215
star
45

powerbi-powershell

Samples for calling the Power BI REST API via PowerShell
PowerShell
207
star
46

ms-identity-python-webapp

A Python web application calling Microsoft graph that is secured using the Microsoft identity platform
PowerShell
207
star
47

ms-identity-javascript-react-tutorial

A chapterwise tutorial that will take you through the fundamentals of modern authentication with Microsoft identity platform in React using MSAL React
JavaScript
204
star
48

SpeechToText-WebSockets-Javascript

SDK & Sample to do speech recognition using websockets in Javascript
TypeScript
200
star
49

azure-iot-samples-csharp

Provides a set of easy-to-understand samples for using Azure IoT Hub and Azure IoT Hub Device Provisioning Service and Azure IoT Plug and Play using C# SDK.
C#
196
star
50

digital-twins-explorer

A code sample for visualizing Azure Digital Twins graphs as a web application to create, edit, view, and diagnose digital twins, models, and relationships.
JavaScript
184
star
51

AI-Gateway

APIM ❤️ OpenAI - this repo contains a set of experiments on using GenAI capabilities of Azure API Management with Azure OpenAI and other services
Jupyter Notebook
182
star
52

Serverless-Eventing-Platform-for-Microservices

This solution is a personal knowledge management system and it allows users to upload text, images, and audio into categories. Each of these types of data is managed by a dedicated microservice built on Azure serverless technologies including Azure Functions and Cognitive Services. The web front-end communicates with the microservices through a SignalR-to-Event Grid bridge, allowing for real-time reactive UI updates based on the microservice updates. Each microservice is built and deployed independently using VSTS’s build and release management system, and use a variety of Azure-native data storage technologies.
C#
176
star
53

Custom-vision-service-iot-edge-raspberry-pi

Sample showing how to deploy a AI model from the Custom Vision service to a Raspberry Pi 3 device using Azure IoT Edge
Python
176
star
54

active-directory-angularjs-singlepageapp

An AngularJS based single page app, implemented with an ASP.NET Web API backend, that signs in users and calls web APIs using Azure AD
JavaScript
171
star
55

IoTDemos

Demos created by the IoT Engineering team that showcase IoT services in an end-to-end solution
CSS
171
star
56

ms-identity-aspnet-webapp-openidconnect

A sample showcasing how to develop a web application that handles sign on via the unified Azure AD and MSA endpoint, so that users can sign in using both their work/school account or Microsoft account. The sample also shows how to use MSAL to obtain a token for invoking the Microsoft Graph, as well as incrementental consent.
170
star
57

cosmos-db-design-patterns

A collection of design pattern samples for building applications and services with Azure Cosmos DB for NoSQL.
C#
167
star
58

ms-identity-javascript-angular-tutorial

A chapterwise tutorial that will take you through the fundamentals of modern authentication with Microsoft identity platform in Angular using MSAL Angular v2
TypeScript
165
star
59

azure-python-labs

Labs demonstrating how to use Python with Azure, Visual Studio Code, GitHub, Windows Subsystem for Linux, and more!
Python
164
star
60

active-directory-b2c-javascript-msal-singlepageapp

A single page application (SPA) calling a Web API. Authentication is done with Azure AD B2C by leveraging MSAL.js
JavaScript
164
star
61

cosmosdb-chatgpt

Sample application that combines Azure Cosmos DB with Azure OpenAI ChatGPT service
HTML
163
star
62

active-directory-b2c-dotnetcore-webapp

An ASP.NET Core web application that can sign in a user using Azure AD B2C, get an access token using MSAL.NET and call an API.
C#
160
star
63

active-directory-xamarin-native-v2

This is a simple Xamarin Forms app showcasing how to use MSAL.NET to authenticate work or school and Microsoft personal accounts with the Microsoft identity platform, and access the Microsoft Graph with the resulting token.
C#
160
star
64

cognitive-services-python-sdk-samples

Learn how to use the Cognitive Services Python SDK with these samples
Python
159
star
65

active-directory-dotnet-webapp-openidconnect

A .NET MVC web application that uses OpenID Connect to sign-in users from a single Azure Active Directory tenant.
JavaScript
159
star
66

NVIDIA-Deepstream-Azure-IoT-Edge-on-a-NVIDIA-Jetson-Nano

This is a sample showing how to do real-time video analytics with NVIDIA DeepStream connected to Azure via Azure IoT Edge. It uses a NVIDIA Jetson Nano device that can process up to 8 real-time video streams concurrently.
C++
158
star
67

openhack-devops-team

DevOps OpenHack Team environment APIs
C#
153
star
68

semantic-kernel-rag-chat

Tutorial for ChatGPT + Enterprise Data with Semantic Kernel, OpenAI, and Azure Cognitive Search
C#
147
star
69

azure-search-power-skills

A collection of useful functions to be deployed as custom skills for Azure Cognitive Search
C#
146
star
70

azure-spring-boot-samples

Spring Cloud Azure Samples
JavaScript
146
star
71

service-fabric-dotnet-web-reference-app

An end-to-end Service Fabric application that demonstrates patterns and features in a web application scenario.
C#
144
star
72

aks-store-demo

Sample microservices app for AKS demos, tutorials, and experiments
Bicep
142
star
73

active-directory-b2c-javascript-nodejs-webapi

A small Node.js Web API for Azure AD B2C that shows how to protect your web api and accept B2C access tokens using Passport.js.
JavaScript
141
star
74

Serverless-APIs

Guidance for building serverless APIs with Azure Functions and API Management.
C#
139
star
75

blockchain-devkit

Samples of how to integrate, connect and use devops to interact with Azure blockchain
Kotlin
138
star
76

storage-blob-dotnet-getting-started

The getting started sample demonstrates how to perform common tasks using the Azure Blob Service in .NET including uploading a blob, CRUD operations, listing, as well as blob snapshot creation.
C#
135
star
77

active-directory-dotnet-webapp-openidconnect-aspnetcore

An ASP.NET Core web application that signs-in Azure AD users from a single Azure AD tenant.
HTML
132
star
78

power-bi-embedded-integrate-report-into-web-app

A Power BI Embedded sample that shows you how to integrate a Power BI report into your own web app
JavaScript
131
star
79

azure-event-grid-viewer

Live view of events from Azure Event Grid with ASP.NET Core and SignalR
HTML
130
star
80

azure-opensource-labs

Azure Open Source Labs (https://aka.ms/oss-labs)
Bicep
128
star
81

azure-video-indexer-samples

Contains the Azure Media Services Video Indexer samples
Python
128
star
82

active-directory-lab-hybrid-adfs

Create a full AD/CA/ADFS/WAP lab environment with Azure AD Connect installed
PowerShell
125
star
83

service-fabric-dotnet-quickstart

Service Fabric quickstart .net application sample
C#
125
star
84

jmeter-aci-terraform

Scalable cloud load/stress testing pipeline solution with Apache JMeter and Terraform to dynamically provision and destroy the required infrastructure on Azure.
HCL
120
star
85

active-directory-dotnet-desktop-msgraph-v2

Sample showing how a Windows desktop .NET (WPF) application can get an access token using MSAL.NET and call the Microsoft Graph API or other APIs protected by the Microsoft identity platform (Azure Active Directory v2)
C#
120
star
86

active-directory-dotnet-webapp-webapi-openidconnect-aspnetcore

An ASP.NET Core web application that authenticates Azure AD users and calls a web API using OAuth 2.0 access tokens.
C#
119
star
87

ms-identity-aspnet-daemon-webapp

A web application that sync's data from the Microsoft Graph using the identity of the application, instead of on behalf of a user.
C#
117
star
88

active-directory-dotnet-webapp-multitenant-openidconnect

A sample .NET 4.5 MVC web app that signs-up and signs-in users from any Azure AD tenant using OpenID Connect.
JavaScript
116
star
89

azure-intelligent-edge-patterns

Samples for Intelligent Edge Patterns
JavaScript
114
star
90

cognitive-services-sample-data-files

Cognitive Services sample data files
113
star
91

python-docs-hello-world

A simple python application for docs
Python
113
star
92

azure-ai

A hub with a curated awesome list of all Azure AI samples
112
star
93

Cognitive-Speech-STT-Windows

Windows SDK for the Microsoft Speech-to-Text API, part of Cognitive Services
111
star
94

durablefunctions-apiscraping-dotnet

Build an Azure Durable Functions that will scrape GitHub for opened issues and store them on Azure Storage.
C#
111
star
95

active-directory-b2c-xamarin-native

This is a simple Xamarin Forms app showcasing how to use MSAL to authenticate users via Azure Active Directory B2C, and access a Web API with the resulting tokens.
C#
110
star
96

cognitive-services-dotnet-sdk-samples

Learn how to use the Cognitive Services SDKs with these samples
C#
108
star
97

active-directory-dotnet-daemon

A Windows console application that calls a web API using its app identity (instead of a user's identity) to get access tokens in an unattended job or process.
C#
107
star
98

azure-samples-python-management

This repo contains sample code for management libraries of Azure SDK for Python
Python
105
star
99

private-aks-cluster-terraform-devops

This sample shows how to create a private AKS cluster using Terraform and Azure DevOps.
HCL
105
star
100

ms-identity-java-webapp

A Java web application calling Microsoft graph that is secured using the Microsoft identity platform
Java
105
star