Run the following commands in the directory where you want to create a new project.
Bash
composer init
Add dependencies
Before you can compile and run the generated API client, you need to make sure the generated source files are part of a project with the required dependencies. Your project must have a reference to the abstraction package. Additionally, you must either use the Kiota default implementations or provide your own custom implementations of the following packages.
To ensure the newly generated classes can be imported, update the autoload paths using:
Bash
composer dumpautoload
Register an application
To be able to authenticate with the Microsoft Entra identity platform and get an access token for Microsoft Graph, you need to create an application registration. You can install the Microsoft Graph PowerShell SDK and use it to create the app registration, or register the app manually in the Microsoft Entra admin center.
The following instructions register an app and enable authorization code flow for authentication.
Select Azure Active Directory in the left-hand navigation, then select App registrations under Manage.
Select New registration. On the Register an application page, set the values as follows.
Set Name to Kiota Test Client.
Set Supported account types to Accounts in any organizational directory and personal Microsoft accounts.
Set Redirect URI platform to Web, and set the value to http://localhost.
Select Register. On the Overview page, copy the value of the Application (client) ID and save it.
Select Certificates & secrets under Manage. Select the New client secret button. Enter a value in Description and select one of the options for Expires and select Add.
Copy the Value of the new secret before you leave this page. It is never displayed again. Save the value for later.
Note
The PowerShell script requires an account with the Application administrator, Cloud application administrator, or Global administrator role. If your account has the Application developer role, you can register an app in the Azure Active Directory admin center.
Create a file in the root of the project named GetUser.php and add the following code. Replace the $clientId and $clientSecret with your credentials from the previous step.
Use the following steps to get an authorization code.
Important
Authorization codes are short-lived, typically expiring after 10 minutes. You should get a new authorization code just before running the example.
Open your browser and paste in the following URL, replacing YOUR_CLIENT_ID with the client ID of your app registration.
Learn how to authenticate users with Microsoft identity platform, configure permissions, and retrieve user data for your Microsoft Teams app using the Microsoft Graph API.
In this quickstart, you learn how a Java app can get an access token and call an API protected by Microsoft identity platform endpoint, using the app's own identity
List of client libraries and middleware compatible with the Microsoft identity platform. Use these libraries to add support for user sign-in (authentication) and protected web API access (authorization) to your applications.
An index of identity platform code samples, grouped by app types, languages, and frameworks, shows how these libraries enable app authentication and authorization.