From 41aac655fe8461b0631b7000c2f17b278092cf68 Mon Sep 17 00:00:00 2001 From: Lauren Liberda Date: Mon, 13 Dec 2021 00:29:26 +0100 Subject: [PATCH] more universal oauth key storage --- ...1-mastodon-oauth.sql => 041-external-oauth.sql} | 5 +++-- server/routes/grantOverrides.js | 14 +++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) rename migrations/{041-mastodon-oauth.sql => 041-external-oauth.sql} (61%) diff --git a/migrations/041-mastodon-oauth.sql b/migrations/041-external-oauth.sql similarity index 61% rename from migrations/041-mastodon-oauth.sql rename to migrations/041-external-oauth.sql index 91588917..61449795 100644 --- a/migrations/041-mastodon-oauth.sql +++ b/migrations/041-external-oauth.sql @@ -1,11 +1,12 @@ -- Up -CREATE TABLE mastodon_oauth ( +CREATE TABLE oauth_keys ( instance TEXT NOT NULL PRIMARY KEY, + provider TEXT NOT NULL, client_id TEXT NOT NULL, client_secret TEXT NOT NULL ); -- Down -DROP TABLE mastodon_oauth; +DROP TABLE oauth_keys; diff --git a/server/routes/grantOverrides.js b/server/routes/grantOverrides.js index 19cb94be..268fe51c 100644 --- a/server/routes/grantOverrides.js +++ b/server/routes/grantOverrides.js @@ -22,9 +22,13 @@ const config = { const router = Router(); -const mastodonGetOAuthKeys = async (db, instance, dbOnly = false) => { - const existingKeys = await db.get( - SQL`SELECT client_id, client_secret FROM mastodon_oauth WHERE instance = ${instance}`); +const mastodonGetOAuthKeys = async (db, instance) => { + const existingKeys = await db.get(SQL` + SELECT client_id, client_secret + FROM oauth_keys + WHERE instance = ${instance} + AND provider = 'mastodon' + `); if (existingKeys) { return existingKeys; } @@ -43,8 +47,8 @@ const mastodonGetOAuthKeys = async (db, instance, dbOnly = false) => { }).then(res => res.json()); assert(keys.client_id && keys.client_secret && !keys.error); db.get(SQL` - INSERT INTO mastodon_oauth (instance, client_id, client_secret) - VALUES (${instance}, ${keys.client_id}, ${keys.client_secret}) + INSERT INTO oauth_keys (instance, provider, client_id, client_secret) + VALUES (${instance}, 'mastodon', ${keys.client_id}, ${keys.client_secret}) `); return keys; };