Skip to content

Commit ee5d4b1

Browse files
authored
Merge pull request #3 from sam-mfb/version-1.1
Version 1.1
2 parents cd74467 + 9e800ca commit ee5d4b1

File tree

10 files changed

+674
-266
lines changed

10 files changed

+674
-266
lines changed

.github/workflows/npm-publish.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Publish to NPM
2+
3+
on:
4+
release:
5+
types: [released]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: Setup Node.js
14+
uses: actions/setup-node@v3
15+
with:
16+
node-version: '18.x'
17+
registry-url: 'https://registry.npmjs.org'
18+
19+
- name: Setup pnpm
20+
uses: pnpm/action-setup@v2
21+
with:
22+
version: 8
23+
run_install: false
24+
25+
- name: Get pnpm store directory
26+
id: pnpm-cache
27+
shell: bash
28+
run: |
29+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
30+
31+
- name: Setup pnpm cache
32+
uses: actions/cache@v3
33+
with:
34+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
35+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
36+
restore-keys: |
37+
${{ runner.os }}-pnpm-store-
38+
39+
- name: Install dependencies
40+
run: pnpm install
41+
42+
- name: Build
43+
run: pnpm run build
44+
45+
- name: Run tests
46+
run: pnpm test -- --no-watch
47+
48+
publish-npm:
49+
needs: build
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v3
53+
54+
- name: Setup Node.js
55+
uses: actions/setup-node@v3
56+
with:
57+
node-version: '18.x'
58+
registry-url: 'https://registry.npmjs.org'
59+
60+
- name: Setup pnpm
61+
uses: pnpm/action-setup@v2
62+
with:
63+
version: 8
64+
run_install: false
65+
66+
- name: Install dependencies
67+
run: pnpm install
68+
69+
- name: Build
70+
run: pnpm run build
71+
72+
- name: Publish to NPM
73+
run: pnpm publish --no-git-checks
74+
env:
75+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

.github/workflows/unit-tests.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Unit Tests
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: '18.x'
19+
20+
- name: Setup pnpm
21+
uses: pnpm/action-setup@v2
22+
with:
23+
version: 8
24+
run_install: false
25+
26+
- name: Get pnpm store directory
27+
id: pnpm-cache
28+
shell: bash
29+
run: |
30+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
31+
32+
- name: Setup pnpm cache
33+
uses: actions/cache@v3
34+
with:
35+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
36+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
37+
restore-keys: |
38+
${{ runner.os }}-pnpm-store-
39+
40+
- name: Install dependencies
41+
run: pnpm install
42+
43+
- name: Run linting
44+
run: pnpm run lint
45+
46+
- name: Run unit tests
47+
run: pnpm test -- --no-watch
48+
49+
- name: Build
50+
run: pnpm run build

README.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,39 @@ This utility works by changing the flow above as follows using a client-server p
3232

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

35-
### Download
35+
### Option 1: Install via npm (Recommended)
3636

37-
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.
37+
You can install oauth2-forwarder globally via npm:
38+
39+
```bash
40+
npm install -g oauth2-forwarder
41+
```
42+
43+
After installation, you'll have the following commands available globally:
44+
- `o2f-server` - Run on the host machine
45+
- `o2f-client` - Run on the container
46+
- `o2f-browser` - Browser script for the container
47+
48+
#### On the host
49+
50+
Run `o2f-server` on the host machine. This will start the server and display the port it's listening on.
51+
52+
#### In the container
53+
54+
1. Set the server info environment variable based on the output from the host:
55+
```bash
56+
export OAUTH2_FORWARDER_SERVER="host.docker.internal:PORT"
57+
```
58+
where PORT is the port displayed when you ran `o2f-server`.
59+
60+
2. Set the BROWSER environment variable to use the browser script:
61+
```bash
62+
export BROWSER=o2f-browser
63+
```
64+
65+
### Option 2: Download Manually
66+
67+
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.
3868

3969
### On the host
4070

@@ -62,9 +92,25 @@ Notes:
6292

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

95+
#### Option 1: Using npm (Recommended)
96+
97+
On the host, set a specific port that you will listen on by configuring the env variable `OAUTH2_FORWARDER_PORT`.
98+
99+
Add these lines in the Dockerfile:
100+
101+
```
102+
RUN npm install -g oauth2-forwarder
103+
ENV OAUTH2_FORWARDER_SERVER host.docker.internal:[PORT]
104+
ENV BROWSER o2f-browser
105+
```
106+
107+
Replace `[PORT]` with the actual port number (or use Docker's `ARG` command).
108+
109+
#### Option 2: Using the zip release
110+
65111
On the host, set a specific port that you will listen on by configuring the env variable `OAUTH2_FORWARDER_PORT`.
66112

67-
Add these lines in the Dockerfile
113+
Add these lines in the Dockerfile:
68114

69115
```
70116
RUN curl -LO https://github.com/sam-mfb/oauth2-forwarder/releases/download/v[VERSION]/oauth2-forwarder.zip

browser-global.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env sh
2+
#
3+
# Assing this script to the BROWSER env variable via:
4+
# export BROWSER=o2f-browser
5+
#
6+
# This will ensure requests to open a browser get forwarded
7+
# through to the proxy
8+
#
9+
LOG_FILE="/tmp/oauth2-forwarder.log"
10+
11+
# fork and return 0 as some apps (e.g., az cli) expect a zero return
12+
# before they will launch their redirect listener
13+
o2f-client "$@" >> "$LOG_FILE" 2>&1 &
14+
15+
exit 0

package.json

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
{
22
"name": "oauth2-forwarder",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "utilities for forwarding oauth2 interactive flow (e.g. container to host)",
55
"main": "dist/index.js",
6+
"bin": {
7+
"o2f-server": "./dist/o2f-server.js",
8+
"o2f-client": "./dist/o2f-client.js",
9+
"o2f-browser": "./browser-global.sh"
10+
},
611
"scripts": {
7-
"build": "rimraf ./dist && webpack",
12+
"build": "rimraf ./dist && webpack && node prepend-shebang.js",
813
"zip-release": "./release.sh",
914
"test": "jest --watch",
1015
"e2e-test": "jest -c ./jest.e2e.config.js",
@@ -14,23 +19,42 @@
1419
},
1520
"author": "Sam Davidoff",
1621
"license": "MIT",
22+
"repository": {
23+
"type": "git",
24+
"url": "https://github.com/sam-mfb/oauth2-forwarder.git"
25+
},
26+
"files": [
27+
"dist",
28+
"browser.sh",
29+
"browser-global.sh"
30+
],
31+
"keywords": [
32+
"oauth2",
33+
"docker",
34+
"container",
35+
"authentication",
36+
"browser"
37+
],
38+
"engines": {
39+
"node": ">=18.0.0"
40+
},
1741
"devDependencies": {
18-
"@eslint/js": "^9.15.0",
42+
"@eslint/js": "^9.25.1",
1943
"@types/eslint__js": "^8.42.3",
2044
"@types/jest": "^29.5.14",
21-
"@types/node": "^20.17.8",
22-
"eslint": "^9.15.0",
45+
"@types/node": "^22.15.3",
46+
"eslint": "^9.25.1",
2347
"jest": "^29.7.0",
24-
"prettier": "^3.4.1",
48+
"prettier": "^3.5.3",
2549
"rimraf": "^6.0.1",
26-
"ts-jest": "^29.2.5",
27-
"ts-loader": "^9.5.1",
28-
"typescript": "^5.7.2",
29-
"typescript-eslint": "^8.16.0",
30-
"webpack": "^5.96.1",
50+
"ts-jest": "^29.3.2",
51+
"ts-loader": "^9.5.2",
52+
"typescript": "^5.8.3",
53+
"typescript-eslint": "^8.31.1",
54+
"webpack": "^5.99.7",
3155
"webpack-cli": "^5.1.4"
3256
},
3357
"dependencies": {
34-
"open": "^10.1.0"
58+
"open": "^10.1.2"
3559
}
3660
}

0 commit comments

Comments
 (0)