Check if username exist in Microsoft Azure Active Directory

10,833

You can use the Graph API and query for the user you want. For information about Graph API read: http://msdn.microsoft.com/en-us/library/azure/hh974476.aspx
The common queries page (http://msdn.microsoft.com/en-us/library/azure/jj126255.aspx) has a query for a user given the userPrincipalName. You should use this query and check if it returns a 404 (not found).

Basically the query you are looking for is: "https://graph.windows.net/contoso.com/users/[email protected]?api-version=2013-04-05" where you need to replace contoso.com with your domain and [email protected] with the upn you want to search for.

You should also look at the Azure AD samples on GitHub. In this case, you're probably interested in how to use the Graph API: https://github.com/AzureADSamples/WebApp-GraphAPI-DotNet

This sample MVC web application demonstrates how to query Azure Active Directory using the Graph API. To facilitate application development, it includes showing how to use included Graph Library, and uses OpenID Connect to authorize users to conenct to their directory data.

Share:
10,833
kat1330
Author by

kat1330

Passionate software engineer with +7 years of experience who enjoys working with team and follows best practices. Currently is assistant to software engineering director and lead engineer for front-end financial application. I like NodeJS, .NET, Angular, ReactJS, AWS, Docker, Kubernetes...

Updated on June 04, 2022

Comments

  • kat1330
    kat1330 over 1 year

    I am using Microsoft Azure Active Directory login for my MVC 5 application. Can somebody give me an idea how I can check if a username already exists in Microsoft Azure Active Directory?

    What is the general approach to do this?