Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor OAuthDeviceCode to support non-Entra IdPs #1892

Merged
merged 16 commits into from
Sep 23, 2024

Conversation

gregertw
Copy link
Contributor

Description

  1. Added support for non-Microsoft Entra identity providers:
  • New oauth_discovery_url parameter for standard OAuth discovery URLs
  • Disabled instance discovery and authority validation for non-Entra authorities
  1. Enhanced token caching:
  • Added clear_cache option to clear existing token cache
  • Introduced mem_cache_only flag for in-memory-only token caching
  1. Improved token refresh logic:
  • Now checks for valid refresh tokens before initiating a new device code flow
  1. Added new convenience methods:
  • OAuthDeviceCode.default() for generic identity providers
  • OAuthDeviceCode.default_for_azure_ad() for Azure AD with pre-configured settings
  1. Updated error handling and user prompts for device code flow

Checklist:

  • Tests added/updated.
  • Documentation updated. Documentation is generated from docstrings - these must be updated according to your change.
    If a new method has been added it should be referenced in cognite.rst in order to generate docs based on its docstring.
  • Changelog updated in CHANGELOG.md.
  • Version bumped. If triggering a new release is desired, bump the version number in _version.py and pyproject.toml per semantic versioning.

@gregertw gregertw requested review from a team as code owners August 28, 2024 13:19
@gregertw gregertw requested review from amorken and removed request for a team and amorken August 28, 2024 13:19
Copy link

codecov bot commented Aug 28, 2024

Codecov Report

Attention: Patch coverage is 50.58824% with 42 lines in your changes missing coverage. Please review.

Project coverage is 90.18%. Comparing base (050f53a) to head (88fe60f).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
cognite/client/credentials.py 50.00% 42 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1892      +/-   ##
==========================================
- Coverage   90.32%   90.18%   -0.14%     
==========================================
  Files         133      133              
  Lines       21131    21200      +69     
==========================================
+ Hits        19086    19119      +33     
- Misses       2045     2081      +36     
Files with missing lines Coverage Δ
cognite/client/_version.py 100.00% <100.00%> (ø)
cognite/client/credentials.py 82.38% <50.00%> (-8.97%) ⬇️

@amorken amorken requested review from haakonvt and removed request for haakonvt August 28, 2024 19:19
@gregertw gregertw requested a review from doctrino August 30, 2024 13:34
Copy link
Contributor

@doctrino doctrino left a comment

Choose a reason for hiding this comment

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

Tried the flow and fails with the following error

cognite.client.exceptions.CogniteAuthError: Error generating access token! Error: invalid_client, error description: AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'. Trace ID: f0fb6991-ed32-4acd-953f-d8f5f333fe00 Correlation ID: 7d3ffed0-ee7d-4412-ba3a-b3a0915947ad Timestamp: 2024-09-02 14:32:11

In addition, some nitpick.

cognite/client/credentials.py Outdated Show resolved Hide resolved
cognite/client/credentials.py Outdated Show resolved Hide resolved
cognite/client/credentials.py Outdated Show resolved Hide resolved
@doctrino doctrino self-requested a review September 23, 2024 10:56
@doctrino doctrino merged commit d9631cb into master Sep 23, 2024
14 checks passed
@doctrino doctrino deleted the gtw/refactor_device_code_oauth2 branch September 23, 2024 11:11
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