Create a new file named Gemfile in the root directory of your project.
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.
Lastly, create a file called graph.rb in the client folder that was created by Kiota. Add the following code:
# frozen_string_literal: true
module Graph
end
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 get_user.rb and add the following code. Replace the client_id and client_secret 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.