Code Monkey home page Code Monkey logo

http-auth-middleware's Introduction

http-auth-middleware

This repo is an example of how to compose a middleware component with a business logic component.

Repo structure

The github-oauth/ directory contains an API for using GitHub oauth in an application. It consists of

  1. The authorize handler which kicks off the github oauth flow allowing a user to give permissions to a GitHub app
  2. The callback handler which GitHub uses as the redirect url in the oauth flow. The callback handler is responsible for taking a code from the URL param and exchanging it for authentication token from GitHub for the user.
  3. The authenticate handler which validates a given access token in an incoming request with the GitHub user API.
  4. The login handler which returns a login button.

The example/ directory contains a Spin application which consists of one http handler which returns an HTTP response contains Hello, Fermyon! in the body. In the spin.toml file, the component build instructions point to a build.sh script which builds the example component and composes it with the github-oauth component.

Demo instructions

Pre-requisites

cargo install --git https://github.com/bytecodealliance/cargo-component cargo-component
cargo install --git https://github.com/dicej/wasm-tools --branch wasm-compose-resource-imports wasm-tools --locked
  • Install latest Spin

  • Create a GitHub App. The callback URL should be http://127.0.0.1:3000/login/callback. Accept defaults and input dummy values for the rest of the fields.

    • Save the Client ID
    • Generate a new Client Secret and save that as well
  • In example/spin.toml: replace <YOUR GITHUB CLIENT ID> with the Client ID from your GitHub APP and <YOUR GITHUB CLIENT SECRET> with the Client Secret from your GitHub App

Build the components and run the demo


# Build the middleware
cargo component build --manifest-path github-oauth/Cargo.toml --release

# Build and run the example
spin up --build -f example

# Open http://127.0.0.1:3000/login in a browser

http-auth-middleware's People

Contributors

fibonacci1729 avatar kate-goldenring avatar michellen 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.