{"id":18970319,"url":"https://github.com/athiththan11/preserve-auth-header-handler","last_synced_at":"2025-10-15T15:25:59.950Z","repository":{"id":122657773,"uuid":"345195551","full_name":"athiththan11/Preserve-Auth-Header-Handler","owner":"athiththan11","description":"A Custom Handler to Preserve and Pass the Auth Header to BE in WSO2 APIM","archived":false,"fork":false,"pushed_at":"2021-03-06T21:28:50.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-01T07:27:09.598Z","etag":null,"topics":["authorization-header","custom-handler","handler","wso2","wso2-api-manager","wso2-apim","wso2-apimanager"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/athiththan11.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-06T21:07:25.000Z","updated_at":"2021-04-03T14:50:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"4a084690-c1d8-4fee-bcda-e0c5fd1a19be","html_url":"https://github.com/athiththan11/Preserve-Auth-Header-Handler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athiththan11%2FPreserve-Auth-Header-Handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athiththan11%2FPreserve-Auth-Header-Handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athiththan11%2FPreserve-Auth-Header-Handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athiththan11%2FPreserve-Auth-Header-Handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/athiththan11","download_url":"https://codeload.github.com/athiththan11/Preserve-Auth-Header-Handler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239970664,"owners_count":19727009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authorization-header","custom-handler","handler","wso2","wso2-api-manager","wso2-apim","wso2-apimanager"],"created_at":"2024-11-08T14:56:39.479Z","updated_at":"2025-10-15T15:25:54.905Z","avatar_url":"https://github.com/athiththan11.png","language":"Java","readme":"# Preserve-Auth-Header-Handler\n\nA custom handler implementation to preserve and pass the Authorization header to the backend server per API level in WSO2 APIM.\n\n\u003e The main branch contains the source code of the handler implemented for APIM v3.1.0. Please make a clone of this repo and update the dependencies and build the handler to support in other versions of the WSO2 API Manager.\n\n## Build\n\nExecute the following command from the root directory of the project to build\n\n```sh\nmvn clean package\n```\n\n## Usage\n\nCopy the built JAR artifact and place it inside the `\u003cgateway\u003e/repository/components/lib` directory and start the server to load the required classes.\n\n\u003e Please follow the [Configure Velocity Template](#configure-velocity-template) instructions to configure velocity template of the API Manager server to generate the API Synapse artifact with required handler definitions.\n\u003e\n\u003e Instructions given below (in this section) can be used to test the handler, becuase if the API is re-deployed or published from the Publisher portal, the made changes will be overriden.\n\nAfter a successful server start, navigate to the `\u003capim\u003e/repository/deployment/server/syanpse-configs/default/api` directory and open the respective API synapse artifact and add the `PreserveAuthHeaderHandler` definition after the `CORSRequestHandler` to extract the Authorization Header.\n\n```xml\n\u003chandler class=\"com.sample.handlers.PreserveAuthHeaderHandler\"\u003e\n    \u003cproperty name=\"AuthorizationHeader\" value=\"Authorization\"/\u003e\n\u003c/handler\u003e\n```\n\nFurthermore, add a global-in mediation sequence as provided in the [./examples/global--in.xml](./example/global--in.xml) directory to append the Authorization header again and to send it.\n\n### Configure Velocity Template\n\nWe will be introducing an API Property to preserve of Authorization header per API level. Please follow the given instructions to make the required changes in the API Manager server\n\n\u003e Please note that the built JAR artifact has to be placed inside the `\u003capim\u003e/repository/components/lib` directory prior to applying the following changes\n\u003e\n\u003e A complete `velocity_template.xml` can be found under [here](example/velocity_template.xml). Please comapre and merge the required changes to the `velocity_template.xml` in your environment.\n\n- Navigate and open the `\u003capim-publisher\u003e/repository/resources/api_templates/velocity_template.xml` and add the following changes\n  \n    ```xml\n    ...\n    \u003chandlers xmlns=\"http://ws.apache.org/ns/synapse\"\u003e\n    #foreach($handler in $handlers)\n\n        #if($handler.className == 'org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler')\n            #if($apiObj.additionalProperties.get('PreserveAuthHeader') == true)\n                \u003chandler class=\"com.sample.handlers.PreserveAuthHeaderHandler\"\u003e\n                #if($handler.hasProperties())\n                    #set ($tempMap = $handler.getProperties() )\n                    #foreach($property in $tempMap.entrySet())\n                    #if($property.key == 'AuthorizationHeader')\n                    \u003cproperty name=\"$!property.key\" value=\"$!property.value\" /\u003e\n                    #end\n                    #end\n                #end\n                \u003c/handler\u003e\n            #end\n        #end\n\n        \u003chandler xmlns=\"http://ws.apache.org/ns/synapse\" class=\"$handler.className\"\u003e\n    ...\n    ```\n\n- Save the `velocity_template.xml`\n- Once the configurations are merged and saved, log-in to the Publisher portal and open the specific API that requires to pass the Authorization header to the backend\n- Go to `Properties` section and add the following property\n  - Property Name: `PreserveAuthHeader`\n  - Property Value: `true`\n- Click on `Add` and then click on `Save` to publish the API with the changes. Above introduced property (`PreserveAuthHeader`) is used to specify whether the Authorization header of that particular API needs to be preserved and sent back to the Backend service or not.\n- Then, add a global-in mediation sequence as provided in the [./examples/global--in.xml](./example/global--in.xml) directory to append the Authorization header again and to send it\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathiththan11%2Fpreserve-auth-header-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fathiththan11%2Fpreserve-auth-header-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathiththan11%2Fpreserve-auth-header-handler/lists"}