Code Monkey home page Code Monkey logo

opa-php-examples's Introduction

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"
}

opa-php-examples's People

Contributors

segrax avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.