From 59e8d85523f7cb7223bf8d0c2394e8bc27a992fb Mon Sep 17 00:00:00 2001 From: tecc Date: Thu, 1 Jun 2023 23:28:58 +0200 Subject: [PATCH 1/2] fix(dev): Disable Apple authentication if required environment variables are not provided apple-auth-dev: Apple authentication support breaks the development environment unless you have the required environment variables set to valid values. Now, it checks for the variables before including it as an authentication method. --- server/social.js | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/server/social.js b/server/social.js index 2b76579ab..c6b761997 100644 --- a/server/social.js +++ b/server/social.js @@ -17,7 +17,34 @@ const getAppleClientSecret = () => { }); } -module.exports.config = { +function appleIsEnabled() { + const conditions = [ + "APPLE_CLIENT_ID", + "APPLE_TEAM_ID", + "APPLE_PRIVATE_KEY" + ]; + let unavailable = []; + for (const condition of conditions) { + const value = process.env[condition]; + // Checks if the value is not a string or empty + if (typeof value !== "string" || value.length < 1 || value.trim().length < 1) { + unavailable.push(condition); + } + } + if (unavailable.length === 0) { + return true; + } + if (unavailable.length === conditions.length) { + console.log("Apple authentication is disabled - provide the APPLE_CLIENT_ID, APPLE_TEAM_ID, and APPLE_PRIVATE_KEY to enable these"); + } else { + console.warn(`Apple authentication is disabled because all required environment values were not provided (missing: ${unavailable.join(', ')})`); + } + return false; +} + +const enableApple = appleIsEnabled(); + +const config = { defaults: { origin: process.env.BASE_URL, transport: 'session', @@ -49,7 +76,13 @@ module.exports.config = { callback: '/api/user/social/discord', scope: ['identify', 'email'], }, - apple: { + // non-grant, but things break if it's not there + mastodon: {}, + indieauth: {}, +} + +if (enableApple) { + config.apple = { key: process.env.APPLE_CLIENT_ID, secret: getAppleClientSecret(), @@ -61,12 +94,11 @@ module.exports.config = { response_type: 'code id_token', response_mode: 'form_post', }, - }, - // non-grant, but things break if it's not there - mastodon: {}, - indieauth: {}, + } } +module.exports.config = config; + module.exports.handlers = { twitter(r) { return { From a89729d15f7f831e0517cfad1f60635bbcef4763 Mon Sep 17 00:00:00 2001 From: tecc Date: Thu, 1 Jun 2023 23:30:34 +0200 Subject: [PATCH 2/2] fix(apple-auth): Add `APPLE_KEY_ID` as a condition for Apple auth --- server/social.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/social.js b/server/social.js index c6b761997..70f62aa5e 100644 --- a/server/social.js +++ b/server/social.js @@ -21,6 +21,7 @@ function appleIsEnabled() { const conditions = [ "APPLE_CLIENT_ID", "APPLE_TEAM_ID", + "APPLE_KEY_ID", "APPLE_PRIVATE_KEY" ]; let unavailable = [];