{"id":21967164,"url":"https://github.com/rgglez/gofiber-roles-middleware","last_synced_at":"2025-03-22T22:13:13.751Z","repository":{"id":261571063,"uuid":"884069306","full_name":"rgglez/gofiber-roles-middleware","owner":"rgglez","description":"Middleware to validate if the user has certain roles in the claims","archived":false,"fork":false,"pushed_at":"2024-11-08T02:41:27.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-28T01:44:30.764Z","etag":null,"topics":["go","gofiber","jwt","middleware","roles","roles-permissions","zitadel"],"latest_commit_sha":null,"homepage":"","language":"Go","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/rgglez.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":"2024-11-06T04:42:09.000Z","updated_at":"2024-11-08T02:55:02.000Z","dependencies_parsed_at":"2024-11-07T09:35:26.999Z","dependency_job_id":"3f2b19dc-bab7-49a7-9c64-c55234ac42f9","html_url":"https://github.com/rgglez/gofiber-roles-middleware","commit_stats":null,"previous_names":["rgglez/gofiber-roles-middleware"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgglez%2Fgofiber-roles-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgglez%2Fgofiber-roles-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgglez%2Fgofiber-roles-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rgglez%2Fgofiber-roles-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rgglez","download_url":"https://codeload.github.com/rgglez/gofiber-roles-middleware/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245026006,"owners_count":20549071,"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":["go","gofiber","jwt","middleware","roles","roles-permissions","zitadel"],"created_at":"2024-11-29T13:22:14.251Z","updated_at":"2025-03-22T22:13:13.701Z","avatar_url":"https://github.com/rgglez.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n![GitHub all releases](https://img.shields.io/github/downloads/rgglez/gofiber-roles-middleware/total)\n![GitHub issues](https://img.shields.io/github/issues/rgglez/gofiber-roles-middleware)\n![GitHub commit activity](https://img.shields.io/github/commit-activity/y/rgglez/gofiber-roles-middleware)\n[![Go Report Card](https://goreportcard.com/badge/github.com/rgglez/gofiber-roles-middleware)](https://goreportcard.com/report/github.com/rgglez/gofiber-roles-middleware)\n[![GitHub release](https://img.shields.io/github/release/rgglez/gofiber-roles-middleware.svg)](https://github.com/rgglez/gofiber-roles-middleware/releases/)\n\n\n**gofiber-roles-middleware** is a [gofiber](https://gofiber.io/) [middleware](https://docs.gofiber.io/category/-middleware/) which verifies if the specified role(s) are present in a customizable key in the custom claims part of a given [JWT token](https://jwt.io/).\n\n## Installation\n\n```bash\ngo get github.com/rgglez/gofiber-roles-middleware\n```\n\n## Usage\n\n```go\nimport gofiberroles \"github.com/rgglez/gofiber-roles-middleware/gofiberroles\"\n\n// Initialize Fiber app and middleware\napp := fiber.New()\napp.Use(gofiberroles.New(gofiberroles.Config{RequiredRoles: []string{\"admin\", \"user\"}, RequireAll: true}))\n```\n\n## Configuration\n\nThere are some configuration options available in the ```Config``` struct:\n\n* **```Next```** defines a function to skip this middleware when returned true. Optional. Default: nil\n* **```RequiredRoles```** an array of strings which defines the required roles which the user must have (in the claims). Required.\n* **```RequireAll```** a boolean which defines if all the required roles must be present in the claims. Optional. Default: true.\n* **```ClaimsKey```** a string which will be used as the key to search for the roles in the claims. Optional. Default: \"urn:zitadel:iam:org:project:roles\". Notice that this is the default used by [Zitadel](https://zitadel.io).\n\n## Notes\n\n* This middleware **does not verify the signature of the token**. It assumes that your program does that verification with some other middleware.\n* The middleware was written with [Zitadel](https://zitadel.io) in mind. You might need to make some adjustments so it works with other claims structure. The token is assumed to be encoded with Base64 and just signed, not encrypted.\n\n## Example\n\nAn example is provided in the [example/](example/) directory.\n\n### Run it\n\n```bash\ncd example\ngo run main.go\n```\n\n### Try it\n\nThen, if it started correctly, assuming that you filled the enviroment variables in ```test_data.sh``` . Or, just set the same variables explained in the Testing section.\n\n```bash\n# first step is optional\nsource /path/to/test_data.sh\n```\n\nYou will need [pytest](https://en.wikipedia.org/wiki/Pytest) tu run the test:\n\n```bash\ncd tests\npytest\n```\n\n## Testing\n\nA test is included. To run the test you must:\n\n1. Get a valid JWT token, maybe from your Zitadel instance.\n1. Set the test data in the enviroment. An example bash script is provided in [```test_data.sh```](test_data.sh) as a guide. You must fill in the values with your own data accordingly:\n\n    ```bash\n    # A token got from a valid login \n    export ZITADEL_TOKEN=\n    # A string of comma-separated role names\n    export ZITADEL_ROLES=\n    ```\n    If you use this script, you should need to [source](https://www.geeksforgeeks.org/source-command-in-linux-with-examples/) it.\n\n1. Run\n    ```bash\n    go test\n    ```\n    inside the [```gofiberroles/```](gofiberroles/) directory.\n\n## Dependencies\n\n* [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber/v2)\n\n## License\n\nCopyright (c) 2024 Rodolfo González González\n\nLicensed under the [Apache 2.0](LICENSE) license. Read the [LICENSE](LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frgglez%2Fgofiber-roles-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frgglez%2Fgofiber-roles-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frgglez%2Fgofiber-roles-middleware/lists"}