> ## 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 EDR Instructions

> Instructions on how to onboard a Microsoft Defender Integration

## Microsoft Defender App

To integrate with Microsoft Defender, users will have to authorize Leen's Microsoft Defender 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 app.

<Steps>
  <Step title="Create Microsoft Defender Connection">
    With your Leen API Key and your Customer's Org ID, make a API request to create a new Microsoft Defender 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_ENDPOINT"
          }
      ```

      The response will look like this:

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

  <Step title="Granting permission to Leen app for Microsoft Defender">
    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 app to access their Microsoft Defender resources.

    <img src="https://mintcdn.com/leen/vQ2Rhs44KY1LGMJC/images/ms_defender/permission_grant_page.png?fit=max&auto=format&n=vQ2Rhs44KY1LGMJC&q=85&s=26545908d2194c5b618462375276e4fe" alt="Microsoft Defender-auth" width="521" height="720" data-path="images/ms_defender/permission_grant_page.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 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>
