Skip to content

Move Defender APIs to OAuth2, fix invalid scopes#856

Merged
ianhelle merged 13 commits intomainfrom
ianhelle/Defender-OAuthParamFix-2025-09-15
Sep 25, 2025
Merged

Move Defender APIs to OAuth2, fix invalid scopes#856
ianhelle merged 13 commits intomainfrom
ianhelle/Defender-OAuthParamFix-2025-09-15

Conversation

@ianhelle
Copy link
Contributor

@ianhelle ianhelle commented Sep 15, 2025

This pull request updates the Microsoft Defender and Microsoft 365 Defender data driver to use OAuth 2.0 (v2.0 endpoint and /.default scope) as the default authentication method for all Defender APIs. It also updates relevant documentation, error handling, and test cases to reflect these changes.

Authentication and API configuration updates:

  • Changed all Defender API authentication flows to use OAuth 2.0 (v2.0 endpoint) and the /.default scope by default, simplifying and standardizing token acquisition across environments. [1] [2]
  • Updated the construction of the resource and scope parameters to ensure correct formatting and error handling, raising a clear error if no scopes are provided for legacy OAuth 1.0 flows.
  • Revised the API selection logic and documentation to clarify that OAuth 2.0 is now the default and to document the current endpoints and scopes.

Testing and versioning:

  • Updated tests to expect the new OAuth 2.0 token endpoint URLs, ensuring test coverage matches the new authentication flow.
  • Bumped the package version to 2.17.0 to reflect these significant changes.

Fix old scopes that were causing authentication errors.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modernizes Microsoft Defender APIs authentication by migrating from OAuth 1.0 to OAuth 2.0 (v2.0 endpoints) and standardizes scope handling across all Defender services. The changes ensure consistent authentication patterns while maintaining backward compatibility for legacy configurations.

  • Migrates all Defender APIs (MDE, M365D, M365DGraph) to use OAuth 2.0 v2.0 token endpoints
  • Standardizes scope handling to use {resource}/.default pattern instead of specific permissions
  • Updates documentation to reflect the new OAuth 2.0 authentication flow

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/data/drivers/test_odata_drivers.py Updates test assertion to expect v2.0 token endpoint
msticpy/data/drivers/mdatp_driver.py Migrates API configurations to OAuth 2.0 endpoints and implements standardized scope handling
msticpy/_version.py Bumps version to 2.17.0

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

ianhelle and others added 2 commits September 15, 2025 10:25
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Using urljoin to join URL parts
@ianhelle ianhelle requested a review from Copilot September 15, 2025 19:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

ianhelle and others added 2 commits September 15, 2025 12:33
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ianhelle ianhelle requested a review from Copilot September 16, 2025 02:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

ianhelle and others added 3 commits September 15, 2025 19:38
…ng sanitization

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ng sanitization

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@ianhelle ianhelle requested a review from petebryan September 22, 2025 18:49
Copy link
Collaborator

@FlorianBracq FlorianBracq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I slightly changed the 'schema' test and applied some minor linting changes.
Also tested the code on my env, and all seems to be working well!

As a side note, some parameters from the init are not documented, I don't know if it's worth addressing in this PR?

@ianhelle
Copy link
Contributor Author

I slightly changed the 'schema' test and applied some minor linting changes. Also tested the code on my env, and all seems to be working well!

As a side note, some parameters from the init are not documented, I don't know if it's worth addressing in this PR?

Thanks so much for testing it and review.
I should fix the param docs but these classes are not really user-visible, they are all instantiated by the data provider layer. I will merge now and publish since we have an org blocked by this.

@ianhelle ianhelle merged commit f2fb544 into main Sep 25, 2025
11 checks passed
@ianhelle ianhelle deleted the ianhelle/Defender-OAuthParamFix-2025-09-15 branch September 25, 2025 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants