Skip to content

Commit 5c26002

Browse files
committed
Initial commit
0 parents  commit 5c26002

26 files changed

+3882
-0
lines changed

Diff for: .gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# Compiled binary addons (http://nodejs.org/api/addons.html)
20+
build/Release
21+
22+
# Dependency directory
23+
# Commenting this out is preferred by some people, see
24+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
25+
node_modules
26+
27+
# Users Environment Variables
28+
.lock-wscript
29+
30+
#Nothing in dist
31+
dist/*

Diff for: .npmignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
src/*
2+
dist/test/*
3+
build.sh
4+
.jshintrc
5+
.gitignore
6+
static/bundle.js
7+
static/bundle.js.map

Diff for: .vscode/settings.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editor.tabSize": 2,
3+
"editor.wordWrap": "wordWrapColumn",
4+
"editor.wordWrapColumn": 80
5+
}

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Jeswin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# border-patrol
2+
3+
A service which does oauth authentication and issues a JWT token.
4+
5+
## Installation
6+
7+
1. Install via npm.
8+
9+
```sh
10+
npm i -g border-patrol
11+
```
12+
13+
2. Create a postgres database and create the tables with scripts found under the 'db' directory.
14+
15+
## Running
16+
17+
You'd use something like this.
18+
19+
```sh
20+
(export PORT=5999 CONFIG_DIR=/some/path/to/config; border-patrol)
21+
```
22+
23+
Where:
24+
25+
- PORT is the port on which the service will run.
26+
- CONFIG_DIR is the directory in which config files are placed.
27+
28+
An example directory containing config files (which are JS files) can be found under the 'example-config' directory.
29+
This is where you specify database connection strings, jwt signing keys etc.
30+
31+
## Authenticating
32+
33+
Send the browser to {YOUR_DOMAIN}/authenticate/{OAUTH_SERVICE}?success=SOME_URL&newuser=OTHER_URL. For example: www.example.com/authenticate/github?success=example.com/success&newuser=example.com/newuser.
34+
The page will redirect to example.com/success if the authenticated user is found in the database, and to example.com/newuser if the authenticated user is not found in the database.

Diff for: build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rm -rf dist
2+
tsc
3+
cp src/test/sample-data.sql dist/test/sample-data.sql

Diff for: db/create-tables.sql

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
3+
CREATE TABLE "user" (
4+
"id" character varying (64) NOT NULL,
5+
"first_name" character varying (64) NOT NULL,
6+
"last_name" character varying (64) NOT NULL,
7+
"created_at" bigint NOT NULL,
8+
"updated_at" bigint NOT NULL,
9+
CONSTRAINT "user_pkey"
10+
PRIMARY KEY ("id"));
11+
12+
CREATE TABLE "provider_user" (
13+
"user_id" character varying (64) NOT NULL,
14+
"provider_user_id" character varying (128) NOT NULL,
15+
"provider" character varying (64) NOT NULL,
16+
"created_at" bigint NOT NULL,
17+
"updated_at" bigint NOT NULL,
18+
CONSTRAINT "provider_user_pkey"
19+
PRIMARY KEY ("provider_user_id", "provider"),
20+
CONSTRAINT "provider_user_user_fkey"
21+
FOREIGN KEY ("user_id")
22+
REFERENCES "user" ("id"));
23+
24+
CREATE TABLE "user_token" (
25+
"name" character varying (128) NOT NULL,
26+
"user_id" character varying (64) NOT NULL,
27+
"value" character varying (128) NOT NULL,
28+
"created_at" bigint NOT NULL,
29+
"updated_at" bigint NOT NULL,
30+
CONSTRAINT "user_token_pkey"
31+
PRIMARY KEY ("name", "user_id"),
32+
CONSTRAINT "user_token_user_fkey"
33+
FOREIGN KEY ("user_id")
34+
REFERENCES "user" ("id"));
35+
36+
CREATE TABLE "role" (
37+
"name" character varying (64) NOT NULL,
38+
"description" character varying (512),
39+
"created_at" bigint NOT NULL,
40+
"updated_at" bigint NOT NULL,
41+
CONSTRAINT "role_pkey"
42+
PRIMARY KEY ("name"));
43+
44+
CREATE TABLE "role_token" (
45+
"name" character varying (256) NOT NULL,
46+
"role_name" character varying (64) NOT NULL,
47+
"value" character varying (64) NOT NULL,
48+
"created_at" bigint NOT NULL,
49+
"updated_at" bigint NOT NULL,
50+
CONSTRAINT "role_token_pkey"
51+
PRIMARY KEY ("name", "role_name"),
52+
CONSTRAINT "role_token_role_fkey"
53+
FOREIGN KEY ("role_name")
54+
REFERENCES "role" ("name"));
55+
56+
CREATE TABLE "user_role" (
57+
"user_id" character varying (64) NOT NULL,
58+
"role_name" character varying (64) NOT NULL,
59+
"created_at" bigint NOT NULL,
60+
"updated_at" bigint NOT NULL,
61+
CONSTRAINT "user_role_pkey"
62+
PRIMARY KEY ("role_name", "user_id"),
63+
CONSTRAINT "user_role_role_fkey"
64+
FOREIGN KEY ("role_name")
65+
REFERENCES "role" ("name"),
66+
CONSTRAINT "user_role_user_fkey"
67+
FOREIGN KEY ("user_id")
68+
REFERENCES "user" ("id"));
69+
70+
*/

Diff for: db/drop-tables.sql

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
3+
DROP TABLE IF EXISTS "provider_user";
4+
5+
DROP TABLE IF EXISTS "user_token";
6+
7+
DROP TABLE IF EXISTS "role_token";
8+
9+
DROP TABLE IF EXISTS "user_role";
10+
11+
DROP TABLE IF EXISTS "user";
12+
13+
DROP TABLE IF EXISTS "role";
14+
15+
*/

Diff for: example-config/app.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
path: "/some/path"
3+
};

Diff for: example-config/db.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
database: "someapdb",
3+
host: "test.example.com",
4+
password: "secret",
5+
port: 5432,
6+
user: "someappdbuser"
7+
};

0 commit comments

Comments
 (0)