{"id":15014007,"url":"https://github.com/alexatiks/keycloak-postman-pre-request","last_synced_at":"2025-04-09T19:23:09.914Z","repository":{"id":45707185,"uuid":"127435421","full_name":"alexatiks/keycloak-postman-pre-request","owner":"alexatiks","description":"Postman pre-request script to fetch a token from Keycloak and set it to a collection variable to use in request headers.","archived":false,"fork":false,"pushed_at":"2024-02-16T13:07:31.000Z","size":777,"stargazers_count":73,"open_issues_count":2,"forks_count":24,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-23T21:22:02.386Z","etag":null,"topics":["keycloak","postman","postman-collection","postman-pre-request-script"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexatiks.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":"2018-03-30T14:11:21.000Z","updated_at":"2025-02-18T01:51:21.000Z","dependencies_parsed_at":"2024-10-12T11:20:43.241Z","dependency_job_id":"fe3d6a29-f644-41a6-90df-dddcaf6ea7e3","html_url":"https://github.com/alexatiks/keycloak-postman-pre-request","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/alexatiks%2Fkeycloak-postman-pre-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexatiks%2Fkeycloak-postman-pre-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexatiks%2Fkeycloak-postman-pre-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexatiks%2Fkeycloak-postman-pre-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexatiks","download_url":"https://codeload.github.com/alexatiks/keycloak-postman-pre-request/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248095828,"owners_count":21046920,"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":["keycloak","postman","postman-collection","postman-pre-request-script"],"created_at":"2024-09-24T19:45:03.321Z","updated_at":"2025-04-09T19:23:09.894Z","avatar_url":"https://github.com/alexatiks.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Postman pre-request script for authentication with Keycloak\n\nThis is a javascript-Script for use with [Postman](https://www.getpostman.com/)'s pre-request script feature.\nIt makes POST request to [Keycloak Token Endpoint](https://www.keycloak.org/docs/latest/authorization_services/#_service_overview) to\nget a valid token and automatically set the token for all requests in Postman collection.\nThis will enable to make request as if a logged in user would make them to an API. \n\n## Usage\n\n1. Create a new client in Keycloak. This client is mostly default. Important are just these few:\n\n*  Client ID: _Choose a name_\n*  Client Protocol: openid-connect\n*  Access Type: confidential\n*  Valid Redirect URIs: http://localhost:8080/*\n\nThis client will only be used for Postman then. Btw. don´t forget to hit \"save\".\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/SirSundays/keycloak-postman-pre-request/blob/master/screenshots/keycloak_client_conf.png?raw=true\" style=\"width: 50%\" alt=\"Create new client\"/\u003e\n\u003c/p\u003e\n\n2. Go now into the second tab \"Credentials\" of your new created Client. Here you can find the Clientsecret in the field *Secret*. Copy that to you clipboard.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/SirSundays/keycloak-postman-pre-request/blob/master/screenshots/keycloak_client_credentials.png?raw=true\" style=\"width: 50%\" alt=\"Client credentials\"/\u003e\n\u003c/p\u003e\n\n3. Now head on to Postman. Create a new collection. Every query you want to make to the API which is protected by Keycloak, has to be in this collection then. On a already existing collection click edit (behind the 3 vertical dots). In the new appearing window choose a name and copy the content of [keycloak-fetch-token-postman-pre-request.js](keycloak-fetch-token-postman-pre-request.js) into the \"Pre-request Script\" tab in Postman. No fill in all the variables in the beginning of the script. Remember you already copied the Clientsecret. If you dont know a variable, some of them can be found in Keycloak under the previously created Client and then in the tab *Installation*. In the screenshot below you can see an example. These are my development values. *Never post production clientsecrets or something!* With username and password you can choose a user. This is good for testing roles. Leave the rest as is.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/SirSundays/keycloak-postman-pre-request/blob/master/screenshots/postman_collection_pre-request-script.png?raw=true\" style=\"width: 50%\" alt=\"Pre Request Script\"/\u003e\n\u003c/p\u003e\n\n4. In the Authorization tab set the Type to Bearer Token and Token to *{{token}}*. This is the token that get send back from Keycloak via the pre-request script.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/SirSundays/keycloak-postman-pre-request/blob/master/screenshots/postman_collection_auth.png?raw=true\" style=\"width: 50%\" alt=\"Collection Auth\"/\u003e\n\u003c/p\u003e\n \n5. For all API requests: In the Authorization tab select Type - Inherit auth from parent. You can see an example below. Keep in mind that the queries you want to execute has to be saved into the configured collection\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/SirSundays/keycloak-postman-pre-request/blob/master/screenshots/postman_query_auth.png?raw=true\" style=\"width: 50%\" alt=\"Postman Example Query\"/\u003e\n\u003c/p\u003e\n\n6. ENJOY\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexatiks%2Fkeycloak-postman-pre-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexatiks%2Fkeycloak-postman-pre-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexatiks%2Fkeycloak-postman-pre-request/lists"}