-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Package Pizzly auth server to share with Nango (#288)
* Package auth server to share with Nango * Small fixes Co-authored-by: Bastien Beurier <[email protected]>
- Loading branch information
1 parent
f426b57
commit 990243a
Showing
40 changed files
with
276 additions
and
173 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 |
---|---|---|
@@ -1,32 +1,43 @@ | ||
############################################################################### | ||
# | ||
# Secure your instance | ||
# Configuration | ||
# | ||
# 1. Secure requests to the API by generating 2 API keys (e.g. using https://codepen.io/corenominal/pen/rxOmMJ) | ||
# The PIZZLY_SECRET_KEY should never be shared and authenticates endpoints related to provider configs and fetching credentials. | ||
# The PIZZLY_PUBLISHABLE_KEY is not secret, is visible in your frontend code, and authenticates endpoints related to the OAuth flow. | ||
# - Secure requests to the API by generating 2 API keys (e.g. using https://codepen.io/corenominal/pen/rxOmMJ) | ||
# The PIZZLY_SECRET_KEY should never be shared and authenticates endpoints related to provider configs and credentials. | ||
# The PIZZLY_PUBLISHABLE_KEY is not secret, is visible in your frontend code, and authenticates endpoints related to triggering the OAuth dance (less sensitive). | ||
# | ||
# PIZZLY_SECRET_KEY="" | ||
# PIZZLY_PUBLISHABLE_KEY="" | ||
# | ||
############################################################################### | ||
# | ||
# Database connection | ||
# - Customize the OAuth callback URL | ||
# | ||
# 1. Provide specific database attributes | ||
# (current values are defaults for running Pizzly locally with Docker) | ||
# AUTH_CALLBACK_URL="" | ||
# | ||
# PIZZLY_DB_USER="nango" | ||
# PIZZLY_DB_PASSWORD="nango" | ||
# PIZZLY_DB_HOST="nango-db" | ||
# PIZZLY_DB_PORT=5432 | ||
# PIZZLY_DB_NAME="nango" | ||
# PIZZLY_DB_SSL=FALSE | ||
# | ||
############################################################################### | ||
# - Customize database to store provider configurations and credentials. | ||
# (running 'docker compose up' creates a local Postgres database with the following credentials) | ||
# | ||
# - Set the log level (debug: most verbose, info: recommended for production, error: least verbose) | ||
NANGO_DB_USER=nango | ||
NANGO_DB_PASSWORD=nango | ||
NANGO_DB_HOST=nango-db | ||
NANGO_DB_PORT=5432 | ||
NANGO_DB_NAME=nango | ||
NANGO_DB_SSL=FALSE | ||
# | ||
# | ||
# - Configure server port (current value is the default for running Pizzly locally). | ||
# | ||
SERVER_PORT=3003 | ||
# | ||
# LOG_LEVEL=info | ||
# | ||
# - Configure server host (current value is the default for running Pizzly locally). | ||
# | ||
SERVER_HOST="http://localhost" | ||
# | ||
# | ||
# - Set the log level (debug: most verbose, info: recommended for production, error: least verbose) | ||
# | ||
LOG_LEVEL=info | ||
# | ||
############################################################################### |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,2 @@ | ||
tsconfig.tsbuildinfo | ||
dist/* |
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,36 @@ | ||
/* | ||
* Copyright (c) 2022 Nango, all rights reserved. | ||
*/ | ||
|
||
import type { Express } from 'express'; | ||
import db from './db/database.js'; | ||
import oauthController from './controllers/oauth.contoller.js'; | ||
import configController from './controllers/config.controller.js'; | ||
import connectionController from './controllers/connection.controller.js'; | ||
import accessMiddleware from './controllers/access.middleware.js'; | ||
import path from 'path'; | ||
import { dirname } from './utils/utils.js'; | ||
|
||
class AuthServer { | ||
async setup(app: Express) { | ||
await db.knex.raw(`CREATE SCHEMA IF NOT EXISTS ${db.schema()}`); | ||
await db.migrate(path.join(dirname(), '../../lib/db/migrations')); | ||
|
||
app.route('/oauth/connect/:providerConfigKey').get(accessMiddleware.checkPkey.bind(accessMiddleware), oauthController.oauthRequest.bind(oauthController)); | ||
app.route('/oauth/callback').get(oauthController.oauthCallback.bind(oauthController)); | ||
app.route('/config').get(accessMiddleware.checkSecret.bind(accessMiddleware), configController.listProviderConfigs.bind(configController)); | ||
app.route('/config/:providerConfigKey').get(accessMiddleware.checkSecret.bind(accessMiddleware), configController.getProviderConfig.bind(configController)); | ||
app.route('/config').post(accessMiddleware.checkSecret.bind(accessMiddleware), configController.createProviderConfig.bind(configController)); | ||
app.route('/config').put(accessMiddleware.checkSecret.bind(accessMiddleware), configController.editProviderConfig.bind(configController)); | ||
app.route('/config/:providerConfigKey').delete( | ||
accessMiddleware.checkSecret.bind(accessMiddleware), | ||
configController.deleteProviderConfig.bind(configController) | ||
); | ||
app.route('/connection/:connectionId').get( | ||
accessMiddleware.checkSecret.bind(accessMiddleware), | ||
connectionController.getConnectionCreds.bind(connectionController) | ||
); | ||
} | ||
} | ||
|
||
export default new AuthServer(); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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,23 @@ | ||
import type { Knex } from 'knex'; | ||
|
||
let config: { development: Knex.Config<any>; production: Knex.Config<any> } = { | ||
development: { | ||
client: 'pg', | ||
connection: { | ||
host: process.env['NANGO_DB_HOST'] || (process.env['SERVER_RUN_MODE'] === 'DOCKERIZED' ? 'nango-db' : 'localhost'), | ||
port: +(process.env['NANGO_DB_PORT'] || 5432), | ||
user: process.env['NANGO_DB_USER'] || 'nango', | ||
database: process.env['NANGO_DB_NAME'] || 'nango', | ||
password: process.env['NANGO_DB_PASSWORD'] || 'nango', | ||
ssl: process.env['NANGO_DB_SSL'] != null && process.env['NANGO_DB_SSL'].toLowerCase() === 'true' ? { rejectUnauthorized: false } : undefined | ||
}, | ||
migrations: { | ||
directory: './migrations', | ||
extension: 'ts' | ||
} | ||
}, | ||
|
||
production: {} | ||
}; | ||
|
||
export { config }; |
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
File renamed without changes.
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
Oops, something went wrong.