kiota-samples/sample-api/clients/typescript
dependabot[bot] c011c9d25c
build(deps-dev): bump eslint
Bumps the eslint group in /sample-api/clients/typescript with 1 update: [eslint](https://github.com/eslint/eslint).


Updates `eslint` from 9.9.1 to 9.10.0
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v9.9.1...v9.10.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: eslint
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-06 21:25:08 +00:00
..
.vscode
src
.eslintrc.json
.gitattributes
.gitignore
.prettierrc.yaml
README.md
RegisterApp.ps1
makesdk.bat
package-lock.json build(deps-dev): bump eslint 2024-09-06 21:25:08 +00:00
package.json build(deps-dev): bump eslint 2024-09-06 21:25:08 +00:00
tsconfig.json

README.md

ToDoItem Sample API TypeScript Kiota Client

This sample implements a client for the ToDoItem sample API. It includes an SDK generated by Kiota in the client folder.

The SDK was generated using the command in makesdk.bat. You can use the makesdk.bat file or the command to regenerate the SDK.

kiota generate -l typescript -c ToDoApiClient -d https://localhost:7206/openapi/openapi.yaml -o ./src/client

Prerequisites

  • Node.js version 18

  • An Azure account with an active subscription. Create an Azure account for free or join the Microsoft 365 Developer Program to get a free instant sandbox for testing.

  • The Azure account must have permission to manage applications in Azure Active Directory (Azure AD). Any of the following Azure AD roles include the required permissions:

    • Application administrator
    • Application developer
    • Cloud application administrator
    • Global administrator
  • The ToDoItem sample API running on your local machine.

Configure the sample

The sample API uses Azure AD to protect the Web API. In order to authenticate and get access tokens to access the API, you'll need to register an application in Azure AD for this sample client and add the app registration to the sample. You can install the Microsoft Graph PowerShell SDK and use the included PowerShell script to automate the process, or register the app manually.

Use PowerShell

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 manually.

Open PowerShell in the root of this project and run the following command.

.\RegisterApp.ps1

This will open a browser window to the Microsoft identity platform's sign-in page. Sign in with your Azure account, review the requested permissions, and consent to the application. This creates an app registration named Kiota ToDoItem Sample API TypeScript Client and save the needed configuration in ./src/settings.ts.

The script also accepts optional parameters to change how it behaves.

  • -AppName <string>: Set the name of the app registration
  • -TenantId <string>: Specify the tenant ID of the Azure subscription to create the app registration in.
  • -StayConnected: The script will leave the Microsoft Graph PowerShell SDK's session open rather than disconnect when it is finished.

Register manually

  1. Open a browser and navigate to the Azure Active Directory admin center. Login with your Azure account.

  2. Select Azure Active Directory in the left-hand navigation, then select App registrations under Manage.

  3. Select New registration. On the Register an application page, set the values as follows.

    • Set Name to Kiota ToDoItem Sample API TypeScript Client.
    • Set Supported account types to Accounts in this organizational directory only.
    • Leave Redirect URI blank.
  4. Select Register. On the Kiota ToDoItem Sample API TypeScript Client page, copy the values of the Application (client) ID and Directory (tenant) ID and save them, you will need to add them to the sample once you are done configuring the app registration.

  5. Select Authentication under Manage.

  6. Locate the Advanced settings section. Set the Allow public client flows toggle to Yes, then select Save.

  7. Create a new file in the ./src directory named settings.ts and add the following contents. Replace YOUR_CLIENT_ID with the client ID from your app registration, and replace YOUR_TENANT_ID with your tenant ID.

    export const CLIENT_ID = 'YOUR_CLIENT_ID';
    export const TENANT_ID = 'YOUR_TENANT_ID';
    export const API_SCOPE = 'api://YOUR_TODO_API_CLIENT_ID/ToDoItem.ReadWrite';
    

Run the sample

Before running the sample client, make sure that you have the sample API project running on your local machine.

Start the sample with the npm start command in the root directory. The application prompts for authenticate in a browser.

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code F8HNE7ABP to authenticate.