GithubHelp home page GithubHelp logo

mikaelvesavuori / oso-serverless-authorizer Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 10 KB

This repository demonstrates a working implementation of Oso in an AWS Lambda context using TypeScript, and being deployed with Serverless Framework.

TypeScript 100.00%
authorizer aws demo oso serverless authorizer-serverless

oso-serverless-authorizer's Introduction

Oso serverless authorizer

This repository demonstrates a working implementation of Oso in an AWS Lambda context using TypeScript, and being deployed with Serverless Framework. When deployed, it will first pass the request through an Oso-powered Lambda authorizer on AWS API Gateway, and successful calls will be fed into a very basic function responding with OK.

Note: Uses and adapts the same quickstart example as Oso provides.

Technical notes

Oso uses proprietary files in the .polar format to store the policies it will use.

Assets and files like that tend to cause problems with bundlers, like Webpack, which are incredibly common (and useful) when building web applications.

Despite trying several solutions for a few hours I was unable to get everything working the way you might expect with Webpack, Serverless Framework, and serverless-offline.

While other, older Oso examples work just fine, they are unfortunately written in "old-style" Node and are in plain JS rather than TypeScript.

I had to strike a compromise where this solution is able to use TypeScript and Serverless Framework, but in which we will trade away some of the packaging automation. The way this is achieved is by doing the packaging step manually, so that we can be very precise with how we pull in the right materials. Therefore, it does not use the built in packaging from Serverless Framework.

In closing: The particular type of solution provided here would therefore work best in a situation where you can deploy the authorizer (in which we use Oso here) separately from any other application stacks. Else you will have to do some hooking and wiring to not break the regular bundling that you will expect for the other microservices.

Deploy

First you will have to build the application with npm run package.

Deploy the stack with npm run deploy.

Copy the URL and use it as below.

Usage

Call the deployed endpoint and set an Authorization header. To define your identity and the "requested" use, we will be using that Authorization header.

  • A combination such as Authorization: graham#oso will work.
  • However, Authorization: graham#gmail will not work.

To better understand the specifics of the permissions model, see repositoriesDb and usersDb in index.ts, as well as how they relate to the policy defined in policy.polar.

Remove

Run npm run teardown.

References

oso-serverless-authorizer's People

Contributors

mikaelvesavuori avatar

Stargazers

 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.