Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TT-13391] Move upstream OAuth to EE (#6684)
### **User description** <details open> <summary><a href="https://tyktech.atlassian.net/browse/TT-13359" title="TT-13359" target="_blank">TT-13359</a></summary> <br /> <table> <tr> <th>Summary</th> <td>[Upstream Auth] Move upstream auth features to ee folder</td> </tr> <tr> <th>Type</th> <td> <img alt="Story" src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10315?size=medium" /> Story </td> </tr> <tr> <th>Status</th> <td>In Code Review</td> </tr> <tr> <th>Points</th> <td>N/A</td> </tr> <tr> <th>Labels</th> <td>-</td> </tr> </table> </details> <!-- do not remove this marker as it will break jira-lint's functionality. added_by_jira_lint --> --- <!-- Provide a general summary of your changes in the Title above --> ## Description TASK: https://tyktech.atlassian.net/browse/TT-13359 <!-- Describe your changes in detail --> ## Related Issue <!-- This project only accepts pull requests related to open issues. --> <!-- If suggesting a new feature or change, please discuss it in an issue first. --> <!-- If fixing a bug, there should be an issue describing it with steps to reproduce. --> <!-- OSS: Please link to the issue here. Tyk: please create/link the JIRA ticket. --> ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why ___ ### **PR Type** enhancement, other ___ ### **Description** - Refactored context handling across multiple files to use `httputil` instead of `ctx`. - Implemented upstream OAuth provider and middleware for handling OAuth tokens in the `ee` package. - Moved encryption and decryption logic to the `crypto` package. - Added initialization and caching logic for upstream OAuth in the server. - Updated event firing to use `model.EventMetaDefault` for consistency. - Added utilities for context data handling and request encoding to events. ___ PRDescriptionHeader.CHANGES_WALKTHROUGH <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><details><summary>14 files</summary><table> <tr> <td> <details> <summary><strong>api.go</strong><dd><code>Refactor context handling and event firing in API gateway</code></dd></summary> <hr> gateway/api.go <li>Removed in-place modification of <code>http.Request</code> context.<br> <li> Replaced <code>ctx</code> package usage with <code>httputil</code>.<br> <li> Updated event firing to use <code>model.EventMetaDefault</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-644cda3aeb4ac7f325359e85fcddb810f100dd5e6fa480b0d9f9363a743c4e05">+51/-77</a> </td> </tr> <tr> <td> <details> <summary><strong>mw_oauth2_auth.go</strong><dd><code>Replace upstream OAuth with no-op middleware</code> </dd></summary> <hr> gateway/mw_oauth2_auth.go <li>Removed upstream OAuth implementation.<br> <li> Added a no-op upstream OAuth middleware.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-a90347c3ad28f06a7bd1c5554ce63448774cb486cf4e9961af2323423ce8209d">+15/-378</a></td> </tr> <tr> <td> <details> <summary><strong>provider.go</strong><dd><code>Implement upstream OAuth provider with token caching</code> </dd></summary> <hr> ee/middleware/upstreamoauth/provider.go <li>Implemented upstream OAuth provider for client credentials and <br>password grants.<br> <li> Added token caching and retrieval logic.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-81f303e143b11cb1ecd6390a8e7a585f077da9f88e578c0ffed921af30081a8a">+317/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>mw_url_rewrite.go</strong><dd><code>Refactor URL rewrite middleware to use httputil</code> </dd></summary> <hr> gateway/mw_url_rewrite.go <li>Replaced <code>ctx</code> package usage with <code>httputil</code> for context data handling.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-84a6a5c810334aaa8702669f2aebf0284f116d83e8a55ec9d1d5b8bae87f1be6">+21/-20</a> </td> </tr> <tr> <td> <details> <summary><strong>rpc_backup_handlers.go</strong><dd><code>Use crypto package for encryption in RPC backup handlers</code> </dd></summary> <hr> gateway/rpc_backup_handlers.go - Moved encryption and decryption logic to `crypto` package. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-69d9cb8df2bd4296a8e5e5d769009a09bd61ca65b7dbcbf29751af92698bd9ce">+9/-75</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Refactor middleware context handling and event firing</code> </dd></summary> <hr> gateway/middleware.go <li>Replaced <code>ctx</code> package usage with <code>httputil</code> for context handling.<br> <li> Updated event firing to use <code>model.EventMetaDefault</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-703054910891a4db633eca0f42ed779d6b4fa75cd9b3aa4c503e681364201c1b">+10/-22</a> </td> </tr> <tr> <td> <details> <summary><strong>event_system.go</strong><dd><code>Refactor event system to use model package</code> </dd></summary> <hr> gateway/event_system.go <li>Moved <code>EventMetaDefault</code> to <code>model</code> package.<br> <li> Updated event firing to use <code>model.EventMetaDefault</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-d56e22d4f1b8d2e91bb643d30e678a3819691a18bfae8506b10e0af8dc279a0e">+11/-34</a> </td> </tr> <tr> <td> <details> <summary><strong>mw_organisation_activity.go</strong><dd><code>Refactor organisation activity middleware for context and events</code></dd></summary> <hr> gateway/mw_organisation_activity.go <li>Replaced <code>ctx</code> package usage with <code>httputil</code> for context data handling.<br> <li> Updated event firing to use <code>model.EventMetaDefault</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-26dd955903317b085be06642ae3e76fe41c8c53844d8758a1a1c8bd05b0110a2">+12/-9</a> </td> </tr> <tr> <td> <details> <summary><strong>middleware.go</strong><dd><code>Implement upstream OAuth middleware for token handling</code> </dd></summary> <hr> ee/middleware/upstreamoauth/middleware.go - Implemented upstream OAuth middleware for handling OAuth tokens. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-1347b256f3728407a2697f1e824391eaa329162e644741d8321f25c7a0630363">+101/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>server.go</strong><dd><code>Initialize upstream OAuth caches in server</code> </dd></summary> <hr> gateway/server.go <li>Added initialization for upstream OAuth caches.<br> <li> Defined functions for creating OAuth caches.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-4652d1bf175a0be8f5e61ef7177c9666f23e077d8626b73ac9d13358fa8b525b">+29/-2</a> </td> </tr> <tr> <td> <details> <summary><strong>helpers.go</strong><dd><code>Add AES encryption and decryption helpers</code> </dd></summary> <hr> internal/crypto/helpers.go - Added functions for encryption and decryption using AES. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-3d1fc755c46eaa99e9f1edf358b9e00842342ae6333902959d7a68b46d156829">+69/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>context.go</strong><dd><code>Add context data handling utilities</code> </dd></summary> <hr> internal/httputil/context.go <li>Added context data handling functions.<br> <li> Defined context keys for request handling.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-aa35e72b1da34689ec8451189adab625374ed898ead1c72f6953c9e946470ffd">+56/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>event.go</strong><dd><code>Add request encoding to event utility</code> </dd></summary> <hr> internal/event/event.go - Added function to encode HTTP requests to events. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-3d64b81c3937b899f363a9ce6bd4dbca0325ce8c20a67b8fb763d0c798cef93e">+11/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>events.go</strong><dd><code>Add EventMetaDefault struct for event metadata</code> </dd></summary> <hr> internal/model/events.go - Added `EventMetaDefault` struct for event metadata. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-3e14096ae0e251fe2fabcf8dfb7e7fa8ed8258ef2a5017a1a5051f95f4dafdc0">+8/-0</a> </td> </tr> </table></details></td></tr><tr><td><strong>Other</strong></td><td><details><summary>1 files</summary><table> <tr> <td> <details> <summary><strong>ctx.go</strong><dd><code>Remove context key definitions from ctx package</code> </dd></summary> <hr> ctx/ctx.go - Removed context key definitions and related functions. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6684/files#diff-600f5f552779994b15324fda108549eec7e7be30b1d8a1a16ee8344243e0cbc7">+7/-45</a> </td> </tr> </table></details></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull request to receive relevant information --------- Co-authored-by: Tit Petric <[email protected]> Co-authored-by: Tit Petric <[email protected]> Co-authored-by: Jeffy Mathew <[email protected]>
- Loading branch information