Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish to NPM

on:
release:
types: [released]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Run tests
run: npm test -- --no-watch

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
31 changes: 31 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Unit Tests

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run linting
run: npm run lint

- name: Run unit tests
run: npm test -- --no-watch

- name: Build
run: npm run build
52 changes: 49 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,39 @@ This utility works by changing the flow above as follows using a client-server p

This helper is written in Typescript and compiles down to two Javascript scripts, one for the server and one for the client.

### Download
### Option 1: Install via npm (Recommended)

Download the latest release from this repo. The release consists of a filed named `oauth2-forwarder.zip` which contains two Javascript scripts: `o2f-server.js` and `o2f-client.js` plus a helper `browser.sh` script, all in a directory called `o2f`. These can be placed wherever you want, but these instructions assume they are placed in the home directories of the host and container.
You can install oauth2-forwarder globally via npm:

```bash
npm install -g oauth2-forwarder
```

After installation, you'll have the following commands available globally:
- `o2f-server` - Run on the host machine
- `o2f-client` - Run on the container
- `o2f-browser` - Browser script for the container

#### On the host

Run `o2f-server` on the host machine. This will start the server and display the port it's listening on.

#### In the container

1. Set the server info environment variable based on the output from the host:
```bash
export OAUTH2_FORWARDER_SERVER="host.docker.internal:PORT"
```
where PORT is the port displayed when you ran `o2f-server`.

2. Set the BROWSER environment variable to use the browser script:
```bash
export BROWSER=o2f-browser
```

### Option 2: Download Manually

Download the latest release from this repo. The release consists of a file named `oauth2-forwarder.zip` which contains two Javascript scripts: `o2f-server.js` and `o2f-client.js` plus a helper `browser.sh` script, all in a directory called `o2f`. These can be placed wherever you want, but these instructions assume they are placed in the home directories of the host and container.

### On the host

Expand Down Expand Up @@ -62,9 +92,25 @@ Notes:

Here's a strategy to make this fairly easy to use with a Docker container built with a Dockerfile.

#### Option 1: Using npm (Recommended)

On the host, set a specific port that you will listen on by configuring the env variable `OAUTH2_FORWARDER_PORT`.

Add these lines in the Dockerfile:

```
RUN npm install -g oauth2-forwarder
ENV OAUTH2_FORWARDER_SERVER host.docker.internal:[PORT]
ENV BROWSER o2f-browser
```

Replace `[PORT]` with the actual port number (or use Docker's `ARG` command).

#### Option 2: Using the zip release

On the host, set a specific port that you will listen on by configuring the env variable `OAUTH2_FORWARDER_PORT`.

Add these lines in the Dockerfile
Add these lines in the Dockerfile:

```
RUN curl -LO https://github.com/sam-mfb/oauth2-forwarder/releases/download/v[VERSION]/oauth2-forwarder.zip
Expand Down
15 changes: 15 additions & 0 deletions browser-global.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
#
# Assing this script to the BROWSER env variable via:
# export BROWSER=o2f-browser
#
# This will ensure requests to open a browser get forwarded
# through to the proxy
#
LOG_FILE="/tmp/oauth2-forwarder.log"

# fork and return 0 as some apps (e.g., az cli) expect a zero return
# before they will launch their redirect listener
o2f-client "$@" >> "$LOG_FILE" 2>&1 &

exit 0
46 changes: 35 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
"version": "1.0.0",
"description": "utilities for forwarding oauth2 interactive flow (e.g. container to host)",
"main": "dist/index.js",
"bin": {
"o2f-server": "./dist/o2f-server.js",
"o2f-client": "./dist/o2f-client.js",
"o2f-browser": "./browser-global.sh"
},
"scripts": {
"build": "rimraf ./dist && webpack",
"build": "rimraf ./dist && webpack && node prepend-shebang.js",
"zip-release": "./release.sh",
"test": "jest --watch",
"e2e-test": "jest -c ./jest.e2e.config.js",
Expand All @@ -14,23 +19,42 @@
},
"author": "Sam Davidoff",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/sam-mfb/oauth2-forwarder.git"
},
"files": [
"dist",
"browser.sh",
"browser-global.sh"
],
"keywords": [
"oauth2",
"docker",
"container",
"authentication",
"browser"
],
"engines": {
"node": ">=18.0.0"
},
"devDependencies": {
"@eslint/js": "^9.15.0",
"@eslint/js": "^9.25.1",
"@types/eslint__js": "^8.42.3",
"@types/jest": "^29.5.14",
"@types/node": "^20.17.8",
"eslint": "^9.15.0",
"@types/node": "^22.15.3",
"eslint": "^9.25.1",
"jest": "^29.7.0",
"prettier": "^3.4.1",
"prettier": "^3.5.3",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.1",
"typescript": "^5.7.2",
"typescript-eslint": "^8.16.0",
"webpack": "^5.96.1",
"ts-jest": "^29.3.2",
"ts-loader": "^9.5.2",
"typescript": "^5.8.3",
"typescript-eslint": "^8.31.1",
"webpack": "^5.99.7",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"open": "^10.1.0"
"open": "^10.1.2"
}
}
Loading
Loading