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

Improve CamundaCloudTokenProvider to work with SM #625

Merged
merged 21 commits into from
Dec 15, 2023

Conversation

ChrisKujawa
Copy link
Collaborator

@ChrisKujawa ChrisKujawa commented Dec 15, 2023

Note

This PR is based on #607

Hey @LennartKleymann

first of all thank you very much for your time and the great contribution! 🙇🏼
I had a look at your PR, and since it is coming from our fork I was not able to modify it directly, so I created a new one based on yours.

Short description of what I did and why:

I had a look at your PR and felt that introducing the base class might not be optimal. It felt complex, and there were still some responsibilities lying in the sub-classes (like writing the caches, etc) and we had still some duplications between the classes.

In general, I favor composition over inheritance so I introduced a new interface and implementation for caching an AccessToken. The access token is persisted within the PersistedAccessTokenCache. The cache class has full responsibility, for caching and persisting.

It makes the unit tests, in this case much easier, and also the classes that use the cache.

Furthermore, I realized that our authentication API also supports form-url-encoding (I tried it manually), so I migrated from sending JSON content to form-url-x-encoding. This should help to support Keycloak as well. Since this was the only difference in these classes I removed the newer ones (I couldn't remove the old TokenProvider to not break earlier clients).

Thank you very much for providing the integration tests! 🎉 I adjusted them to use the CamundaCloudTokenProvider, and it worked without any issues. Furthermore, I tried again manually with the changes to run against SaaS, which worked as well.

// At begin...
2023-12-15 15:02:20.6464 | DEBUG | Zeebe.Client.Impl.Builder.CamundaCloudTokenProvider | Received access token for 3ae1aee9-1654-4801-b326-f930acb2322b.chaos-1.zeebe.ultrawombat.com 
// Later
2023-12-15 15:02:21.0047 | DEBUG | Grpc.Net.Client.Internal.GrpcCall | Starting gRPC call. Method type: 'Unary', URI: 'https://3ae1aee9-1654-4801-b326-f930acb2322b.chaos-1.zeebe.ultrawombat.com/gateway_protocol.Gateway/DeployResource'. 
2023-12-15 15:02:21.0052 | TRACE | Zeebe.Client.Impl.Misc.PersistedAccessTokenCache | Use in memory access token 
2023-12-15 15:02:21.0052 | TRACE | Grpc.Net.Client.Balancer.Internal.ConnectionManager | Pick started. 
2023-12-15 15:02:21.0063 | DEBUG | Grpc.Net.Client.Balancer.Internal.ConnectionManager | Successfully picked subchannel id '1-1' with address 3ae1aee9-1654-4801-b326-f930acb2322b.chaos-1.zeebe.ultrawombat.com:443. Transport status: ActiveStream 
2023-12-15 15:02:21.0063 | TRACE | Grpc.Net.Client.Balancer.Internal.BalancerHttpHandler | Sending request https://3ae1aee9-1654-4801-b326-f930acb2322b.chaos-1.zeebe.ultrawombat.com/gateway_protocol.Gateway/DeployResource. 
2023-12-15 15:02:21.0063 | DEBUG | Grpc.Net.Client.Internal.GrpcCall | Sending message. 

closes #503
closes #607

@ChrisKujawa ChrisKujawa force-pushed the jacob-elektronik-503-adding-oauth2-token-provider branch 2 times, most recently from 9a24d33 to 4a296ef Compare December 15, 2023 14:38
LennartKleymann and others added 20 commits December 15, 2023 15:44
AccessTokenCache takes care of caching an AccessToken, and as well of storing to and reading from disk.
Currently not able to compile, nor get dotnet 8.0 on fedora 37
Instead of using the base class, use the new PersistedAccessTokenCache which gives us all necessary
functionality and simplifies the TokenProvider a lot.

Additionally add a new method to set the path were the credentials are stored
Most of the logic is already tested in Cache tests
This should allow to use the CamundaCloudTokenProvider for SaaS but also with keycloak in SM
SaaS and SM can be handled with old CamundaCloudTokenProvider
Use CamundaCloudTokenProvider with OAuth SM test
Refactor a bit the ZeebeIntegrationTestHelper, remove booleans and make it more explicit
@ChrisKujawa ChrisKujawa force-pushed the jacob-elektronik-503-adding-oauth2-token-provider branch from 4a296ef to d44b524 Compare December 15, 2023 14:44
@ChrisKujawa ChrisKujawa merged commit dc3b0b2 into main Dec 15, 2023
5 checks passed
@ChrisKujawa ChrisKujawa deleted the jacob-elektronik-503-adding-oauth2-token-provider branch December 15, 2023 15:40
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.

I can use the client to perform authenticated requests
2 participants