feat(http): add oauth2 client_credentials support#813
feat(http): add oauth2 client_credentials support#813jak78dkt merged 13 commits intoDecathlon:mainfrom
Conversation
tzatziki-http/src/main/java/com/decathlon/tzatziki/utils/OAuth2TokenFetcher.java
Outdated
Show resolved
Hide resolved
tzatziki-http/src/main/java/com/decathlon/tzatziki/steps/HttpSteps.java
Outdated
Show resolved
Hide resolved
|
First, thanks for this nice contribution 😄 In your step if you call addHeader for "logged_user" with access token directly then you can directly call with authenticated user using existing http calls steps: So finally, only one step to implement that call OAuth2ClientCredentialsStore to either register client and get access token or only get access token if client is already registered by another scenario. And then add the token as header for the user. Last thought, maybe we should handle the refresh of the access token in case persisted between test and it expired during test campaign |
|
Maybe we can also add a test in case auth server failed to respond. |
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| - | - | Base64 Basic Authentication | c3f956b | tzatziki-http/src/test/resources/com/decathlon/tzatziki/steps/http.feature | View secret |
| - | - | Base64 Basic Authentication | c3f956b | tzatziki-http/src/test/resources/com/decathlon/tzatziki/steps/http.feature | View secret |
| - | - | Base64 Basic Authentication | c3f956b | tzatziki-http/src/test/resources/com/decathlon/tzatziki/steps/http.feature | View secret |
| - | - | Base64 Basic Authentication | c3f956b | tzatziki-http/src/test/resources/com/decathlon/tzatziki/steps/http.feature | View secret |
| - | - | Base64 Basic Authentication | 53f7677 | tzatziki-http/src/test/resources/com/decathlon/tzatziki/steps/http.feature | View secret |
| - | - | Base64 Basic Authentication | bb186ca | tzatziki-http/src/test/resources/com/decathlon/tzatziki/steps/http.feature | View secret |
| - | - | Base64 Basic Authentication | c3f956b | tzatziki-http/src/test/resources/com/decathlon/tzatziki/steps/http.feature | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Thanks for the suggestion, indeed I did not see that was already possible. I have done the changes and removed the unnecessary new step definitions. |
|
Thanks for the contribution! That's awesome! Given that the user "user" is authenticated with clientId "my-service", clientSecret "secret123" and token url "http://auth-server/oauth/token"Or, alternatively (for a shorter, maybe more readable step): Given that the user "user" is authenticated with:
client_id: my-service
client_secret: secret123
token_url: "http://auth-server/oauth/token"This consistency is essential for me. Once this is updated, I'll be happy to approve! |
tzatziki-http/src/main/java/com/decathlon/tzatziki/steps/HttpSteps.java
Outdated
Show resolved
Hide resolved
* add oauth2 client_credentials support * use BASIC_AUTH for getting bearer token from oauth2 server * update authenticated steps gherkin phrases * fix tests * add tests for erroneous cases * refactor tests, update doc * prevent unnecessary call to oauth2 server if client already registered * refactor authentication step's gherkin statement * refactor authentication step's gherkin statement * try git guardian config file * try git guardian config file * remove gitguardian config file * fix authentication step base method
This PR provides built-in support for OAuth2 client credentials flow authentication. This allows you to set up authenticated API calls in your tests.
Setting up OAuth2 Authentication
Use the
Setup authenticationstep to configure OAuth2 client credentials. This will automatically fetch the access token from the specified token URL:This step will:
grant_type=client_credentialsaccess_tokenfrom the JSON responseMaking Authenticated HTTP Calls
Once authentication is set up, you can make authenticated HTTP calls using the
as authenticated usersyntax:The authenticated calls will automatically include the
Authorization: Bearer <token>header.