-
Notifications
You must be signed in to change notification settings - Fork 105
Fix #1127 - Use CredentialProvider in OAuth2 provider #1126
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
base: main
Are you sure you want to change the base?
Fix #1127 - Use CredentialProvider in OAuth2 provider #1126
Conversation
9cb6610
to
565cdd6
Compare
@ricardozanini PTAL |
...time/src/main/java/io/quarkiverse/openapi/generator/providers/ConfigCredentialsProvider.java
Outdated
Show resolved
Hide resolved
...time/src/main/java/io/quarkiverse/openapi/generator/providers/ConfigCredentialsProvider.java
Outdated
Show resolved
Hide resolved
d0c6537
to
aad13a7
Compare
9c48cc2
to
a276dfa
Compare
...nt/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/CredentialsProvider.java
Fixed
Show fixed
Hide fixed
...nt/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/CredentialsProvider.java
Fixed
Show fixed
Hide fixed
...nt/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/CredentialsProvider.java
Fixed
Show fixed
Hide fixed
...nt/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/CredentialsProvider.java
Fixed
Show fixed
Hide fixed
...t/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/AbstractAuthProvider.java
Show resolved
Hide resolved
...t/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/AbstractAuthProvider.java
Show resolved
Hide resolved
...time/src/main/java/io/quarkiverse/openapi/generator/providers/ConfigCredentialsProvider.java
Outdated
Show resolved
Hide resolved
30d851b
to
8483233
Compare
...nt/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/CredentialsProvider.java
Fixed
Show fixed
Hide fixed
...nt/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/CredentialsProvider.java
Fixed
Show fixed
Hide fixed
.../main/java/io/quarkiverse/openapi/generator/oidc/providers/OAuth2AuthenticationProvider.java
Show resolved
Hide resolved
...time/src/main/java/io/quarkiverse/openapi/generator/providers/ConfigCredentialsProvider.java
Outdated
Show resolved
Hide resolved
0f1e570
to
6df6a23
Compare
a225e19
to
23a4790
Compare
@ricardozanini I had to use Quarkus test profile to load the custom credentials provider for the IT, now it works, PTAL again :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take another look later.
client/integration-tests/auth-provider/src/main/resources/application.properties
Outdated
Show resolved
Hide resolved
23a4790
to
04c31a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@ricardozanini I added a data structure which embed all parameters that must be made available to the methods of the CredentialProvider. I added lombok dependency to have the getter and builder generated, if that pose a problem, I will remove, let me know |
Signed-off-by: gabriel-farache <[email protected]>
Signed-off-by: gabriel-farache <[email protected]>
Signed-off-by: gabriel-farache <[email protected]>
898fb3b
to
6f7ddc0
Compare
Hey @gabriel-farache many thanks! Yes, please remove lombok. |
Signed-off-by: gabriel-farache <[email protected]>
6f7ddc0
to
d52de6a
Compare
@ricardozanini done |
...nt/runtime/src/main/java/io/quarkiverse/openapi/generator/providers/CredentialsProvider.java
Outdated
Show resolved
Hide resolved
Signed-off-by: gabriel-farache <[email protected]>
I'll ask for more eyes. |
...uth-provider/src/test/java/io/quarkiverse/openapi/generator/it/auth/KeycloakServiceMock.java
Outdated
Show resolved
Hide resolved
...ovider/src/test/java/io/quarkiverse/openapi/generator/it/auth/TokenExternalServicesMock.java
Outdated
Show resolved
Hide resolved
...dc/src/test/java/io/quarkiverse/openapi/generator/oidc/OAuth2AuthenticationProviderTest.java
Outdated
Show resolved
Hide resolved
...dc/src/test/java/io/quarkiverse/openapi/generator/oidc/OAuth2AuthenticationProviderTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: gabriel-farache <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @gabriel-farache.
...uth-provider/src/test/java/io/quarkiverse/openapi/generator/it/auth/KeycloakServiceMock.java
Outdated
Show resolved
Hide resolved
...uth-provider/src/test/java/io/quarkiverse/openapi/generator/it/auth/KeycloakServiceMock.java
Outdated
Show resolved
Hide resolved
...ovider/src/test/java/io/quarkiverse/openapi/generator/it/auth/TokenExternalServicesMock.java
Show resolved
Hide resolved
...ovider/src/test/java/io/quarkiverse/openapi/generator/it/auth/TokenExternalServicesMock.java
Show resolved
Hide resolved
...est/java/io/quarkiverse/openapi/generator/it/auth/TokenWithCustomCredentialProviderTest.java
Outdated
Show resolved
Hide resolved
provider.filter(reactiveRequestContext); | ||
assertHeader(headers, HttpHeaders.AUTHORIZATION, expectedAuthorizationHeader); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter
is a non-blocking method and then, immediately, you are checking the headers in the assertHeader
.
Potentially header couldn't be there yet, making the test to be flaky.
Perhaps you can use CountDownLatch or other mechanism to wait until the filter logic finishes, and then assert the headers. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how I could use a CountDownLatch
as I do not want to add code just for testing purposes in the filter
part handling the response
Plus, the getTokens
method is mocked and should return instantly.
But I do agree, in rare case, there may be sync issue and the test may fail; to avoid that, I mocked the RestClientRequestContext
that executes the suspend
and resume
methods which are used in the filter
. THen I added a simple while-sleep
loop to wait until the request is resumed. The loop may not be the most efficient solution, but for this case I believe it's enough as the impact will be very low, WDYT?
Signed-off-by: gabriel-farache <[email protected]>
Signed-off-by: gabriel-farache <[email protected]>
11c0b03
to
fcbdbf0
Compare
@gmunozfe mind taking a look? |
Many thanks for submitting your Pull Request ❤️!
Please make sure that your PR meets the following requirements:
[0.9.x] Subject
This PR solves #1127
CredentialProvider
interface instance when setting the token in the headerget
as for the other providers but aset
as the access token is first generated by the delegate and then set in the header. The reactive delegate and its Mutiny (async) usage force us to have all in one (getting the token and setting the header) to avoid losing the benefit of releasing the thread while waiting for the token. If we are fine with losing it, agetToken
method can instead be defined in theOidcClientRequestFilterDelegate
interface and then use it in aCredentialProvider
get
method for oauth2 instead of calling thefilter
from the delegate