GitXplorerGitXplorer
s

opa-php-examples

public
4 stars
2 forks
3 issues

Commits

List of commits on branch master.
Unverified
5aa842d44586b188f1e8cf8c04cc5257af8b310b

Update dependencies

ssegrax committed 3 years ago
Unverified
ea2a264b74d317d8fe13363c8b76b8c6b8f7ee87

Add link to walkthrough of examples

ssegrax committed 5 years ago
Unverified
300e42205242a738b12159bdebdb9b600a35b381

Add comments to routes

ssegrax committed 5 years ago
Unverified
6c6081953d4297ac34f46eeeadaf2c35d8b8f51d

Add link to segrax/openpolicyagent

ssegrax committed 5 years ago
Unverified
2b8eb6e0e332087402782f5f0fe8ede89f7669e8

Improve wording again

ssegrax committed 5 years ago
Unverified
6bdf734bba448fabf23ee13f1ef2ee8f6059804d

Fix spelling

ssegrax committed 5 years ago

README

The README file for this repository.

segrax/opa-php-examples

Software License Build Status

Examples of using Open Policy Agent (OPA) with the segrax/open-policy-agent library on PHP 7.3.

These examples are pre-configured to work out of the box and contain insecure JWTs / secret-key and must never be reused for any purpose.

The API is setup for xdebug including working @code configuration.

All Examples make use of docker-compose, and executing the steps below will launch multiple contains.

For a walkthrough using these examples please see this tutorial

Includes

  • Plain PHP usage of client
  • Slim 4 Skeleton API with policy authorization

Usage

Plain PHP

This example can be used for making queries to an instance of OPA.

    cd plain
    make composer-install
    make test

Slim 4 API Authorization

This example demonstrates how to invoke a policy for making a decision on access to a route.

    cd slim4-api
    make start

The containers will now build and be started, by default the API will be listening on port 80. This 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.

A Postman collection is included inside slim4-api, import it and test both endpoints.

This is the policy for the included example endpoint.

package slim.api

default allow = false

# OPA Bundle
allow {
    input.path = ["opa", "bundles", "{name}"]
    input.token.sub == "opa"
}

# Allow a user to access their own private end point
allow {
    input.method == "GET"
    input.path = ["welcome", userid ]
    userid == input.token.sub
}

# Allow anyone (including unauthed) access to the public endpoint
allow {
    input.path = ["public"]
    input.method == "GET"
}