{"id":23472906,"url":"https://github.com/segrax/opa-php-examples","last_synced_at":"2025-10-07T16:55:17.447Z","repository":{"id":37586560,"uuid":"226433959","full_name":"segrax/opa-php-examples","owner":"segrax","description":"Example usage of OPA in PHP","archived":false,"fork":false,"pushed_at":"2023-04-19T21:17:03.000Z","size":97,"stargazers_count":4,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T18:52:19.820Z","etag":null,"topics":["authorization","authorization-middleware","middlewares","opa","openpolicyagent","psr-15","psr-7","slimphp"],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/segrax.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null}},"created_at":"2019-12-07T00:38:46.000Z","updated_at":"2022-09-21T09:06:52.000Z","dependencies_parsed_at":"2025-04-14T18:44:18.797Z","dependency_job_id":"21f3c58f-45b7-48d6-b946-e1e31e0eacc7","html_url":"https://github.com/segrax/opa-php-examples","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/segrax/opa-php-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segrax%2Fopa-php-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segrax%2Fopa-php-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segrax%2Fopa-php-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segrax%2Fopa-php-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/segrax","download_url":"https://codeload.github.com/segrax/opa-php-examples/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/segrax%2Fopa-php-examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278811846,"owners_count":26050181,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","authorization-middleware","middlewares","opa","openpolicyagent","psr-15","psr-7","slimphp"],"created_at":"2024-12-24T17:14:26.335Z","updated_at":"2025-10-07T16:55:17.412Z","avatar_url":"https://github.com/segrax.png","language":"PHP","readme":"# segrax/opa-php-examples\n\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md)\n[![Build Status](https://api.travis-ci.com/segrax/opa-php-examples.svg)](https://travis-ci.com/segrax/openpolicyagent)\n\nExamples of using Open Policy Agent (OPA) with the [segrax/open-policy-agent](https://github.com/segrax/openpolicyagent) library on PHP 7.3.\n\nThese examples are pre-configured to work out of the box and contain insecure JWTs / secret-key and must never be reused for any purpose.\n\nThe API is setup for xdebug including working [@code](https://code.visualstudio.com/) configuration.\n\nAll Examples make use of docker-compose, and executing the steps below will launch multiple contains.\n\nFor a walkthrough using these examples please see this [tutorial](https://coil.com/p/segra/OPA-for-API-Authorization-with-Slim-PHP/H-7YsQL2m)\n\n## Includes\n* Plain PHP usage of client\n* Slim 4 Skeleton API with policy authorization\n\n\n## Usage\n\n### Plain PHP\nThis example can be used for making queries to an instance of OPA.\n```bash\n    cd plain\n    make composer-install\n    make test\n```\n\n### Slim 4 API Authorization\nThis example demonstrates how to invoke a policy for making a decision on access to a route.\n```bash\n    cd slim4-api\n    make start\n```\nThe containers will now build and be started, by default the API will be listening on port 80.\nThis example serves up policies in a bundle to the running OPA using the Distributor PSR-15 middleware that is included in segrax/open-policy-agent.\n\nA [Postman](https://www.getpostman.com/) collection is included inside slim4-api, import it and test both endpoints.\n\nThis is the policy for the included example endpoint.\n```\npackage slim.api\n\ndefault allow = false\n\n# OPA Bundle\nallow {\n    input.path = [\"opa\", \"bundles\", \"{name}\"]\n    input.token.sub == \"opa\"\n}\n\n# Allow a user to access their own private end point\nallow {\n    input.method == \"GET\"\n    input.path = [\"welcome\", userid ]\n    userid == input.token.sub\n}\n\n# Allow anyone (including unauthed) access to the public endpoint\nallow {\n    input.path = [\"public\"]\n    input.method == \"GET\"\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsegrax%2Fopa-php-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsegrax%2Fopa-php-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsegrax%2Fopa-php-examples/lists"}