Skip to content

Commit

Permalink
feat: goog authn backend session. (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
morganney authored Nov 30, 2023
1 parent 41bab2a commit 70e5c6a
Show file tree
Hide file tree
Showing 22 changed files with 425 additions and 53 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
BM_POSTGRES_PASSWORD=secret
BM_POSTGRES_USER=user
BM_POSTGRES_DB=db
BM_COOKIE_SECRET=ride_the_bus
BM_COOKIE_SECURE=false
BM_COOKIE_SAMESITE=lax
BM_SESSION_STORE=memory
BM_REDIS_HOST=redis://session
SSO_GOOG_CLIENT_ID=goog_sso_id
SSO_GOOG_CLIENT_SECRET=goog_sso_secret
DEBUG=
7 changes: 4 additions & 3 deletions initdb.d/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ CREATE TABLE IF NOT EXISTS "sso_provider" (
"client_secret" varchar(128) NOT NULL
) WITH (oids = false);

CREATE TABLE IF NOT EXISTS "user" (
CREATE TABLE IF NOT EXISTS "rider" (
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
"sub" varchar(128) UNIQUE NOT NULL,
"email" varchar(128) UNIQUE NOT NULL,
"sso_provider" integer NOT NULL,
"email" varchar(128) NOT NULL,
"given_name" varchar(32) NOT NULL,
"family_name" varchar(32),
"full_name" varchar(64) NOT NULL,
"last_login" timestamptz NOT NULL,
UNIQUE("sso_provider", "email"),
FOREIGN KEY (sso_provider) REFERENCES sso_provider(id) ON UPDATE CASCADE ON DELETE CASCADE
) WITH (oids = false);
153 changes: 146 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions packages/api/.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
POSTGRES_PASSWORD=${BM_POSTGRES_PASSWORD:?error}
POSTGRES_USER=${BM_POSTGRES_USER:?error}
POSTGRES_DB=${BM_POSTGRES_DB:?error}

BM_COOKIE_SECRET=${BM_COOKIE_SECRET:?error}
BM_COOKIE_SECURE=true
BM_COOKIE_SAMESITE=strict
BM_SESSION_STORE=redis
BM_COOKIE_SECURE=${BM_COOKIE_SECURE:-true}
BM_COOKIE_SAMESITE=${BM_COOKIE_SAMESITE:-strict}
BM_SESSION_STORE=${BM_SESSION_STORE:-redis}
BM_REDIS_HOST=${BM_REDIS_HOST}

SSO_GOOG_CLIENT_ID=${SSO_GOOG_CLIENT_ID}
DEBUG=${DEBUG}
2 changes: 2 additions & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
"debug": "^2.6.9",
"express": "^4.18.2",
"express-session": "^1.17.3",
"google-auth-library": "^9.2.0",
"helmet": "^7.1.0",
"http-errors": "^2.0.0",
"morgan": "^1.10.0",
"postgres": "^3.4.3",
"redis": "^4.6.10",
"restbus": "^2.2.0"
},
Expand Down
13 changes: 13 additions & 0 deletions packages/api/src/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { env } from 'node:process'

import postgres from 'postgres'

const sql = postgres({
host: 'db',
port: 5432,
database: env.POSTGRES_DB,
username: env.POSTGRES_USER,
password: env.POSTGRES_PASSWORD
})

export { sql }
Loading

0 comments on commit 70e5c6a

Please sign in to comment.