To run the completed project in this folder, you need the following:
- Java SE Development Kit (JDK) and Gradle installed on your development machine. (Note: This tutorial was written with OpenJDK version 17.0.2 and Gradle 7.4.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,
Java 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 "Java 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 oAuth.properties.example to
oauth.Properties
and update the values according to the following table.Setting Value app.clientId
The client ID of your app registration app.clientSecret
The client secret app.tenantId
The tenant ID of your organization
In your command-line interface (CLI), navigate to the project directory and run the following command.
./gradlew --console plain run