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

feat: oauth2 client credentials #468

Conversation

felicijus
Copy link
Contributor

@felicijus felicijus commented Aug 14, 2024

Provides a way to Authenticate with Oauth2Session for 0Auth2 Client Credentials (and possibility to adopt other Flows) via AuthMetadataPlugin (OAuth2MetadataPlugin) tailored to oauthlib and requests_oauthlib.

Provides posibility to adapt to non RFC 6749 compliant Authentification Server.

Changes

  • OAuth2MetadataPlugin (Class to be able Authenticate with any Authorization flow provided by oauthlib package
  • OAuth2 Client Credentials (specific Implementation with oauthlib package for Client Credential Flow)
  • New create channel functions for create_camunda_cloud_channel and
    create_oauth2_client_credentials_channel
  • Use given expires_in attribute in Token to reauthenticate after expiration (overridable, configurable if not given)

API Updates

New Features (required)

private APIs

  1. OAuth2MetadataPlugin
  2. Oauth2ClientCredentialsMetadataPlugin (Specializationof OAuth2MetadataPlugin)

public APIs

  1. create_camunda_cloud_channel
  2. create_oauth2_client_credentials_channel

Deprecations (required)

The other way to create_camunda_cloud_channel (channel/camunda_cloud_channel.py) could be deleted.

Enhancements (optional)

More configurable way to handle Authentification for pyzeebe grpc channel.

Checklist

  • Unit tests
  • Documentation

References

https://datatracker.ietf.org/doc/html/rfc6749
https://oauthlib.readthedocs.io/en/latest/oauth2/clients/client.html
https://requests-oauthlib.readthedocs.io/en/latest/oauth2_workflow.html

@CLAassistant
Copy link

CLAassistant commented Aug 14, 2024

CLA assistant check
All committers have signed the CLA.

@felicijus felicijus changed the title Feature/oauth client credentials feat: oauth client credentials Aug 14, 2024
@felicijus felicijus marked this pull request as draft August 14, 2024 16:22
@dimastbk
Copy link
Collaborator

Hi. Do you want to replace #412?

pyzeebe/credentials/oauth.py Outdated Show resolved Hide resolved
pyzeebe/channel/oauth_channel.py Show resolved Hide resolved
@felicijus felicijus force-pushed the feature/oauth-client-credentials branch from 91f9b26 to cf55cff Compare August 21, 2024 07:24
felicijus and others added 4 commits August 21, 2024 09:34
This commit adds a new function `create_oauth2_client_credentials_channel` to the `pyzeebe.channel` module. This function allows the creation of a channel connected to a Camunda Cloud cluster using OAuth2 client credentials for authentication. The function takes various parameters such as the target address, client ID, client secret, authorization server, scope, audience, and expiration time. It returns a GRPC channel connected to the Zeebe Gateway.

The new function is added in the `pyzeebe.channel.oauth_channel` module, which is imported in the `pyzeebe.channel.__init__` module.

This change is necessary to provide support for authenticating with Camunda Cloud using OAuth2 client credentials.

Co-authored-by: dependabot[bot] <[email protected]>
This commit adds a new function `create_oauth2_client_credentials_channel` to the `pyzeebe.channel.oauth_channel` module. The function allows the creation of a channel connected to a Camunda Cloud cluster using OAuth2 client credentials for authentication. It takes various parameters such as the target address, client ID, client secret, authorization server, scope, audience, and expiration time. The function returns a GRPC channel connected to the Zeebe Gateway. This change is necessary to provide support for authenticating with Camunda Cloud using OAuth2 client credentials.
…d Channel

Based on Oauth2ClientCredentialsMetadataPlugin and a general OAuth2MetadataPlugin to support Oauth2Sessions
This commit refactors the `create_oauth2_client_credentials_channel` function in the `pyzeebe.channel.oauth_channel` module. The function is responsible for creating a channel connected to a Camunda Cloud cluster using OAuth2 client credentials for authentication. It takes various parameters such as the target address, client ID, client secret, authorization server, scope, audience, and expiration time. The function returns a GRPC channel connected to the Zeebe Gateway.

The refactoring improves the code structure and readability of the function, making it easier to maintain and understand. This change is necessary to provide support for authenticating with Camunda Cloud using OAuth2 client credentials.

Co-authored-by: dependabot[bot] <[email protected]>
@felicijus felicijus force-pushed the feature/oauth-client-credentials branch from cf55cff to 07140cf Compare August 21, 2024 07:34
@felicijus
Copy link
Contributor Author

felicijus commented Aug 21, 2024

I think the changes are now all implemented as you wished @dimastbk.
I needed to change the commit author therefore the force pushes.

@felicijus
Copy link
Contributor Author

How should we handle the mypy errors @dimastbk ?

I would suggest doing it with inline ignore statement # type: ignore.

pyzeebe/credentials/oauth.py:10: error: Skipping analyzing "grpc._auth": module is installed, but missing library stubs or py.typed marker  [import-untyped]
pyzeebe/credentials/oauth.py:17: error: Class cannot subclass "AuthMetadataPlugin" (has type "Any")  [misc]
pyzeebe/channel/oauth_channel.py:[5](https://github.com/camunda-community-hub/pyzeebe/actions/runs/10503175124/job/29127825861?pr=468#step:6:6): error: Skipping analyzing "grpc.aio._typing": module is installed, but missing library stubs or py.typed marker  [import-untyped]
pyzeebe/channel/oauth_channel.py:5: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 3 errors in 2 files (checked 52 source files)
Error: Process completed with exit code 1.

This commit fixes the type hint import error by ignoring the untyped import. This change is necessary to ensure the code passes linting without any errors.

Co-authored-by: dependabot[bot] <[email protected]>
@felicijus felicijus marked this pull request as ready for review August 24, 2024 05:08
pyzeebe/channel/oauth_channel.py Outdated Show resolved Hide resolved
pyzeebe/channel/oauth_channel.py Show resolved Hide resolved
pyzeebe/credentials/oauth.py Outdated Show resolved Hide resolved
pyzeebe/channel/oauth_channel.py Outdated Show resolved Hide resolved
pyzeebe/channel/__init__.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@dimastbk dimastbk left a comment

Choose a reason for hiding this comment

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

Sorry, I've been on vacation for the last two weeks.

pyzeebe/channel/camunda_cloud_channel.py Outdated Show resolved Hide resolved
pyzeebe/channel/channel_options.py Outdated Show resolved Hide resolved
pyzeebe/channel/oauth_channel.py Outdated Show resolved Hide resolved
docs/credentials.rst Show resolved Hide resolved
pyzeebe/credentials/oauth.py Outdated Show resolved Hide resolved
@felicijus felicijus changed the title feat: oauth client credentials feat: oauth2 client credentials Sep 18, 2024
@coveralls
Copy link

coveralls commented Sep 30, 2024

Pull Request Test Coverage Report for Build 11191422489

Details

  • 90 of 90 (100.0%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.3%) to 96.883%

Totals Coverage Status
Change from base Build 11130949290: 0.3%
Covered Lines: 1088
Relevant Lines: 1123

💛 - Coveralls

@felicijus
Copy link
Contributor Author

Got some time now.
I will create a pull request regarding the grpcAddress (java zeebe) or target.
So naming could be:

  1. grpc_address (favourite)
  2. target

And then finish up this pull request.

Coverage should be fine, i think ✅

pyzeebe/credentials/oauth.py Outdated Show resolved Hide resolved
docs/channels.rst Outdated Show resolved Hide resolved
pyzeebe/channel/oauth_channel.py Outdated Show resolved Hide resolved
@dimastbk dimastbk merged commit cfff667 into camunda-community-hub:master Oct 5, 2024
17 checks passed
@dimastbk
Copy link
Collaborator

dimastbk commented Oct 5, 2024

Thanks

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.

4 participants