To run the completed project in this folder, you need the following:
- Node.js installed on your development machine. (Note: This tutorial was written with Node.js version 16.14.2. The steps in this guide may work with other versions, but that has not been tested.)
- A Microsoft work or school account with the Global administrator role.
If you don't have a Microsoft account, you can sign up for the Microsoft 365 Developer Program to get a free Microsoft 365 subscription.
You can register an application using the Azure Active Directory admin center, or by using the Microsoft Graph PowerShell SDK.
-
Open a browser and navigate to the Azure Active Directory admin center and login using a Global administrator account.
-
Select Azure Active Directory in the left-hand navigation, then select App registrations under Manage.
-
Select New registration. Enter a name for your application, for example,
JavaScript App-Only Graph Tutorial
. -
Set Supported account types to Accounts in this organizational directory only.
-
Leave Redirect URI empty.
-
Select Register. On the application's Overview page, copy the value of the Application (client) ID and Directory (tenant) ID and save them, you will need these values in the next step.
-
Select API permissions under Manage.
-
Remove the default User.Read permission under Configured permissions by selecting the ellipses (...) in its row and selecting Remove permission.
-
Select Add a permission, then Microsoft Graph.
-
Select Application permissions.
-
Select User.Read.All, then select Add permissions.
-
Select Grant admin consent for..., then select Yes to provide admin consent for the selected permission.
-
Select Certificates and secrets under Manage, then select New client secret.
-
Enter a description, choose a duration, and select Add.
-
Copy the secret from the Value column, you will need it in the next steps.
To use PowerShell, you'll need the Microsoft Graph PowerShell SDK. If you do not have it, see Install the Microsoft Graph PowerShell SDK for installation instructions.
-
Open PowerShell and run the RegisterAppForAppOnlyAuth.ps1 file with the following command.
.\RegisterAppForAppOnlyAuth.ps1 -AppName "JavaScript App-Only Graph Tutorial" -GraphScopes "User.Read.All"
-
Copy the Client ID, Tenant ID, and Client secret values from the script output. You will need these values in the next step.
SUCCESS Client ID: ae2386e6-799e-4f75-b191-855d7e691c75 Tenant ID: 5927c10a-91bd-4408-9c70-c50bce922b71 Client secret: ... Secret expires: 10/28/2024 5:01:45 PM
-
Rename appSettings.example.js to
appSettings.js
and update the values according to the following table.Setting Value clientId
The client ID of your app registration clientSecret
The client secret tenantId
The tenant ID of your organization
In your command-line interface (CLI), navigate to the project directory and run the following command.
npm install
node index.js