# Authorization code

## Introduction

This walkthrough details the process of registering a Microsoft Entra ID application, granting it high-level API permissions, and securely connecting it to the Mindflow platform based on the provided documentation.

## Registering the Application in Azure

1. To establish an identity for the integration, you must first register the application within your Microsoft Entra tenant.
2. **Navigate to App Registrations**: In the Microsoft Azure portal, go to Microsoft Entra ID directory and select **App registrations** from the sidebar.
3. **Create New Registration**: Click on **+ New registration.**

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0001.jpg)

   </div>

4. **Configure Application Settings**:
   1. **Name**: Enter a display name, such as "**TEST**".
   2. **Supported Account Types**: Select **Accounts in this organizational directory only (Single tenant)**.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0002.jpg)

   </div>

5. **Complete Registration**: Click **Register**. Once created, note the **Application (client) ID** and **Directory (tenant) ID** from the **Essentials** section for later use.

## Configuring API Permissions

1. Explicitly grant permissions to allow the app to interact with Microsoft Graph data.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0003.jpg)

   </div>

2. **Access Permissions Menu**: From the application sidebar, select **API permissions**.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0004.jpg)

   </div>

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0005.jpg)

   </div>

3. **Choose Permission Type**: Select Delegated permissions. This is used for services requiring the sign in of a user.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0006.jpg)

   </div>

4. **Select Specific Scopes**:
   1. Search for and select required permissions such as **Files.Read.All**, **Files.ReadWrite**, and **Files.ReadWrite.All**.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0007.jpg)

   </div>

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0008.jpg)

   </div>

   1. Add **offline_access** to maintain access to data.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0010.jpg)

   </div>

5. **Grant Admin Consent**: Initially, the status will show as not granted.
6. Click **Grant admin consent** and confirm to authorize these permissions for the entire tenant. A success message will appear once completed.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0011.jpg)

   </div>

## Generating Authentication Credentials

1. Generate a client secret to allow Mindflow to authenticate as this application.
2. **Create Secret**: Navigate to **Certificates & secrets** and click **+ New client secret**.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0012.jpg)

   </div>

3. **Set Expiration**: Provide a description (e.g., "**TEST**") and choose an expiration period, such as the recommended **180 days**.
4. **Secure the Value**: Immediately copy the **Secret Value**.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0013.jpg)

   </div>

:::note
Note: This value is hidden after you leave the page. Store it safely as it is required for the credential configuration on Mindflow.
:::

## Configuring redirect URL

1. To allow the app to properly redirect to Mindflow to allows users to approve the delegation of permissions to the App navigate to Overview then click `Redirect URLs`

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0016.jpg)

   </div>

2. Click Add, select Web as platform and within the placeholder, write down `https://credentials-{your-mindflow-env}.mindflow.io/oauth2/callback`

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0017.jpg)

   </div>

3. Click configure

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0018.jpg)

   </div>

## Integrating with Mindflow

1. Use the gathered Azure details to create a functional credential within Mindflow.
2. **Start Credential Creation**: In Mindflow, select the appropriate service, such as **Microsoft Graph - Files**.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0019.jpg)

   </div>

3. **Configure Connection**: Fill in the following details in Mindflow:
   1. **Credential Name**: e.g., "Microsoft Graph - Files credential".
   2. **Credential Type**: Select **OAuth 2.0 Authorization Code**.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0020.jpg)

   </div>

   1. **Client ID**: Paste the **Application (client) ID** from Phase 1.
   2. **Client Secret**: Paste the **Secret Value** generated in Phase 3.
   3. **Callback URL**: Ensure this matches the **Redirect URI** configured in Azure (e.g., `https://credentials-{tenant}.mindflow.io/oauth2/callback`).
   4. **Endpoints**: Use the provided OAuth 2.0 authorization and token endpoints, replacing `{tenant-id}` with your actual Directory ID.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0021.jpg)

   </div>

   1. **Set Scopes**: Under **Advanced settings**, enter the required scopes, such as `offline_access https://graph.microsoft.com/.default`.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0022.jpg)

   </div>

4. **Authorize**: Click **Authorize and create**. You will be prompted to sign in and accept the requested permissions for your organization.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0023.jpg)

   </div>

5. A successful integration will result in an "**Authorization Successful!**" message.

   <div class="docs-screenshot-compact">

   ![Auth pages jpg](./assets/auth-pages-jpg-0024.jpg)

   </div>
