-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1033 from macolso/middleware-suh
Adding http-auth-middleware to SUH
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
title = "HTTP Auth Middleware" | ||
template = "render_hub_content_body" | ||
date = "2023-11-03T00:00:00Z" | ||
content-type = "text/html" | ||
tags = ["rust", "authentication", "http"] | ||
|
||
[extra] | ||
author = "fermyon" | ||
type = "hub_document" | ||
category = "Sample" | ||
language = “Rust" | ||
created_at = "2023-11-03T00:00:00Z" | ||
last_updated = "2023-11-07T00:00:00Z" | ||
spin_version = ">=v2.0" | ||
summary = "Example of how to compose a middleware component with a business logic component" | ||
url = "https://github.com/fermyon/http-auth-middleware" | ||
keywords = "rust, http, auth" | ||
|
||
--- | ||
|
||
This sample shows how to compose a middleware component with a business logic component using [Spin 2.0](https://www.fermyon.com/blog/introducing-spin-v2) and the Component Model. | ||
|
||
## Instructions | ||
|
||
### Install Prerequisites | ||
|
||
* Install [`cargo component`](https://github.com/bytecodealliance/cargo-component): | ||
|
||
```bash | ||
cargo install --git https://github.com/bytecodealliance/cargo-component cargo-component | ||
``` | ||
|
||
* Install a fork of [wasm-tools](https://github.com/dicej/wasm-tools/tree/wasm-compose-resource-imports): | ||
|
||
```bash | ||
cargo install --git https://github.com/dicej/wasm-tools --branch wasm-compose-resource-imports wasm-tools --locked | ||
``` | ||
|
||
* Install latest [Spin](https://developer.fermyon.com/spin/v2/install) | ||
* Create an OAuth App in your [GitHub Developer Settings](https://github.com/settings/developers). | ||
* Set the callback URL to `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 | ||
|
||
### Build And Run The Spin App | ||
|
||
```bash | ||
# Build the middleware | ||
cargo component build --manifest-path github-oauth/Cargo.toml --release | ||
|
||
# Build and run the example | ||
spin up --build -f example -e CLIENT_ID=<YOUR_GITHUB_APP_CLIENT_ID> -e CLIENT_SECRET=<YOUR_GITHUB_APP_CLIENT_SECRET> | ||
|
||
# Open http://127.0.0.1:3000/login in a browser | ||
|
||
# Deploy to Fermyon Cloud | ||
spin cloud deploy | ||
``` | ||
|
||
## Running with Wasmtime | ||
|
||
Please visit the [G]itHub repository](https://github.com/fermyon/http-auth-middleware#running-with-wasmtime) for detailed instructions on how to run with Wasmtime. |