> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leen.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Microsoft Defender for Cloud Instructions

> Instructions on how to onboard a Microsoft Defender for Cloud Integration

## Microsoft Defender for Cloud App

To integrate with Microsoft Defender for Cloud, users will have to authorize Leen's Microsoft Defender for Cloud app, which is an OAuth2 app.
This will allow Leen to access the appropriate Microsoft Defender resources in the organization's account.
Leen takes care of the OAuth2 code-flow and access token management, so you don't have to worry about it.

## Onboarding

Follow the steps below to onboard your environment to our Microsoft Defender for Cloud app.

<Steps>
  <Step title="Create Microsoft Defender for Cloud Connection">
    With your Leen API Key and your Customer's Org ID, make a API request to create a new Microsoft Defender for Connection.
    More information can be found on the [API Reference page.](/api-reference/provisioning/add-new-connection)

    <Accordion title="Example POST body and response">
      ```json theme={null}
          {
            "vendor": "MS_DEFENDER_CLOUD"
          }
      ```

      The response will look like this:

      ```json theme={null}
        {
            "id": "c54de187-df62-4e95-b10f-0ab53b095d9d",
            "vendor": "MS_DEFENDER_CLOUD",
            "is_active": false,
            "refresh_interval_secs": 14400,
            "timeout_secs": 1800,
            "organization_id": "fbd8b095-3c39-4137-9478-c32308444202",
            "oauth2_authorize_url": "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?.....",
            "identifier": null
        }
      ```
    </Accordion>
  </Step>

  <Step title="Granting permission to Leen app for Microsoft Defender for Cloud">
    Open the `oauth2_authorize_url` from the previous step in a new tab.
    This will prompt the admin user to authorize Leen's Microsoft Defender for Cloud app to access their Microsoft Defender resources.

    <img src="https://mintcdn.com/leen/vQ2Rhs44KY1LGMJC/images/ms_defender/cspm_permission_grant.png?fit=max&auto=format&n=vQ2Rhs44KY1LGMJC&q=85&s=5a76117b1f2c465cfbed6119eaed77de" alt="Microsoft Defender-auth" width="926" height="1258" data-path="images/ms_defender/cspm_permission_grant.png" />

    Once the user has authorized the app, they will be redirected to Leen on a successful authorization.

    <img src="https://mintcdn.com/leen/vQ2Rhs44KY1LGMJC/images/ms_defender/successful_connection.png?fit=max&auto=format&n=vQ2Rhs44KY1LGMJC&q=85&s=61fd0c0fa6dd3807fdd50d4dd4c2178e" alt="Microsoft Defender-auth-success" width="1072" height="1236" data-path="images/ms_defender/successful_connection.png" />
  </Step>

  <Step title="Pull Data">
    Now that the user has authorized the app, you can pull data from Microsoft Defender for Cloud using the `connection_id` from the first step.
    More information can be found on the [API Reference page.](/api-reference/appsec/get-issues)
  </Step>
</Steps>
