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

Support OAuth2 authentication #1346

Merged
merged 1 commit into from
Sep 6, 2023
Merged

Conversation

MarcialRosales
Copy link
Contributor

@MarcialRosales MarcialRosales commented May 11, 2023

Fixes #956

Proposed Changes

Enable the following mechanisms via two attributes added to the ConnectionFactory:

  • Obtain Basic Credentials (this means username+password or Oauth2 tokens) via the interface ICredentialsProvider
  • In case of OAuth2 credentials, which they have a validity period, refresh the tokens before they expire.

This PR is accompanied by another PR on the rabbitmq-website to update the .Net Client guide.

Acceptance Tests

Via TestApplications/OAuth2, it is possible to test end-to-end the following flows:

  • Initial token request and connection establishment with the token (using standard connection)
  • refresh the token via the token request. This is tested with keycloak
  • refresh the token by requesting a new one. This is tested with uaa
  • Specify extra parameters to be included when requesting a token such as scope.

To do:

  • Test using TLS with the authorization server

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

  • Bug fix (non-breaking change which fixes issue #NNNN)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause an observable behavior change in existing systems)
  • Documentation improvements (corrections, new content, etc)
  • Cosmetic change (whitespace, formatting, etc)

This PR is accompanied by another docs' PR

@MarcialRosales MarcialRosales force-pushed the support-credential-refresh branch 4 times, most recently from 0059af6 to ece4e10 Compare May 12, 2023 14:03
@MarcialRosales MarcialRosales requested a review from lukebakken May 16, 2023 09:30
@lukebakken lukebakken self-assigned this Jun 15, 2023
@jonproch117
Copy link

Is this feature still planned to be released? The associated changes to the website here from this PR were published, which threw me off since the referenced classes/properties don't yet exist in the library.

Thanks!

@MarcialRosales MarcialRosales marked this pull request as ready for review August 8, 2023 09:25
@MarcialRosales MarcialRosales force-pushed the support-credential-refresh branch from 30afc8f to 9baf8fc Compare August 8, 2023 09:26
@lukebakken
Copy link
Contributor

@jonproch117 - I'm working on reviewing this PR now. I should be able to get it released by the end of August. Sorry about the confusion!

@lukebakken lukebakken added this to the 6.6.0 milestone Aug 8, 2023
Copy link
Contributor

@lukebakken lukebakken left a comment

Choose a reason for hiding this comment

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

Thanks for all of your excellent work, @MarcialRosales

I am going to move IOAuth2Client and related classes to their own project (and thus dll that is published to NuGet). The reason being that only a fraction of the users of the .NET client will need the OAuth2 code, and most will not want to have the extra dependencies on System.Net.Http.Json and System.Text.Json.

I'll start work on that tomorrow!

@lukebakken lukebakken marked this pull request as draft August 9, 2023 01:39
@MarcialRosales
Copy link
Contributor Author

Excellent @lukebakken ! Good call on splitting that dependency. We just need to make it clear in the documentation to include this extra DLL when using OAuth2 authentication/authorization. Shall I create that doc's PR or will you do it?

@lukebakken
Copy link
Contributor

We just need to make it clear in the documentation to include this extra DLL when using OAuth2 authentication/authorization. Shall I create that doc's PR or will you do it?

Go right ahead. I think it should be pretty clear to end-users but best to make it as obvious as possible.

@lukebakken lukebakken force-pushed the support-credential-refresh branch 8 times, most recently from 3cb1f0a to 2df1e82 Compare September 5, 2023 15:51
Change test assertion

Restore original test

The new test did work in Unix but
failed on Windows

Fix whitespace, remove use of #nullable, do not remove UserName / Password from connection factory

Do not make unnecessary API changes

Add tls-gen as a submodule, start getting bash scripts to pass shellcheck

Bash script refactoring

Use full docker options
Clean up OAuth2 test Program
Remove unused code in start-rabbitmq.sh

Start to move OAuth2 code to its own project

Finish moving OAuth2 code to its own project

Remove OAuth2 from APIApproval

Add OAuth2 API approval test and move verified output into each directory

Version the RabbitMQ.Client.OAuth2 project independently of the RabbitMQ.Client project

Fix lack of whitespaces, use TimeSpan to represent a duration rather than a long.

Fix APIApproval

Fix project refs, use forward slashes
@lukebakken lukebakken force-pushed the support-credential-refresh branch from 2df1e82 to 5914434 Compare September 5, 2023 16:46
Copy link
Contributor

@lukebakken lukebakken left a comment

Choose a reason for hiding this comment

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

@MarcialRosales before merging, would you please review my changes? If you would run through your test scenarios in your env one more time I would appreciate it as well. Thanks!

@lukebakken lukebakken marked this pull request as ready for review September 6, 2023 13:32
@lukebakken lukebakken merged commit 6668107 into main Sep 6, 2023
@lukebakken lukebakken deleted the support-credential-refresh branch September 6, 2023 13:39
lukebakken added a commit that referenced this pull request Sep 11, 2023
lukebakken added a commit that referenced this pull request Sep 21, 2023
@lukebakken
Copy link
Contributor

@jonproch117 - if you'd like to test this out, please see the following beta releases:

I'm working on documentation at this time. You can see an example of how to use the new library via our test code here:

https://github.com/rabbitmq/rabbitmq-dotnet-client/tree/6.x/projects/TestApplications/OAuth2

@jonproch117
Copy link

@lukebakken This is working for me. Thanks!

lukebakken added a commit that referenced this pull request Oct 3, 2023
lukebakken added a commit that referenced this pull request Oct 4, 2023
Follow-up to:
* #956
* #1346

UAA service, RabbitMQ mounts for UAA

Source code checkout happens _after_ service containers are started

Use conventional-actions/docker-run@v1
lukebakken added a commit that referenced this pull request Oct 5, 2023
Follow-up to:
* #956
* #1346

UAA service, RabbitMQ mounts for UAA

Source code checkout happens _after_ service containers are started

Use conventional-actions/docker-run@v1

Start adding test project for OAuth2

Converting OAuth2 test program to Xunit

Run OAuth2 tests using `dotnet test`

Refactor test to use async/await when available

Remove TestApplications/OAuth2

Simplify APIApproval a bit
lukebakken added a commit that referenced this pull request Oct 5, 2023
Follow-up to:
* #956
* #1346

UAA service, RabbitMQ mounts for UAA

Source code checkout happens _after_ service containers are started

Use conventional-actions/docker-run@v1

Start adding test project for OAuth2

Converting OAuth2 test program to Xunit

Run OAuth2 tests using `dotnet test`

Refactor test to use async/await when available

Remove TestApplications/OAuth2

Simplify APIApproval a bit
lukebakken added a commit that referenced this pull request Oct 5, 2023
Follow-up to:
* #956
* #1346

UAA service, RabbitMQ mounts for UAA

Source code checkout happens _after_ service containers are started

Use conventional-actions/docker-run@v1

Start adding test project for OAuth2

Converting OAuth2 test program to Xunit

Run OAuth2 tests using `dotnet test`

Refactor test to use async/await when available

Remove TestApplications/OAuth2

Simplify APIApproval a bit

Ensure main workflow does NOT run OAuth2 tests
lukebakken added a commit that referenced this pull request Oct 6, 2023
Follow-up to:
* #956
* #1346

UAA service, RabbitMQ mounts for UAA

Source code checkout happens _after_ service containers are started

Use conventional-actions/docker-run@v1

Start adding test project for OAuth2

Converting OAuth2 test program to Xunit

Run OAuth2 tests using `dotnet test`

Refactor test to use async/await when available

Remove TestApplications/OAuth2

Simplify APIApproval a bit
lukebakken added a commit that referenced this pull request Oct 6, 2023
Follow-up to:
* #956
* #1346

UAA service, RabbitMQ mounts for UAA

Source code checkout happens _after_ service containers are started

Use conventional-actions/docker-run@v1

Start adding test project for OAuth2

Converting OAuth2 test program to Xunit

Run OAuth2 tests using `dotnet test`

Refactor test to use async/await when available

Remove TestApplications/OAuth2

Simplify APIApproval a bit
@lukebakken
Copy link
Contributor

@jonproch117 thank you! I will release version 6.6.0 today.

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.

Support credential refresh for OAuth 2/JWT authentication scenarios
3 participants