From 6d81c79e8fce7ab382afe7670cfbcd62063bda6d Mon Sep 17 00:00:00 2001 From: Rob Cameron Date: Fri, 22 Jul 2022 10:00:14 -0700 Subject: [PATCH 01/10] Make base64url a dependency install only if setting up dbAuth + webAuthn --- packages/api/package.json | 2 +- .../cli/src/commands/setup/auth/providers/dbAuth.webAuthn.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/api/package.json b/packages/api/package.json index f28d617b12d4..4d8548c855c7 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -32,7 +32,6 @@ "dependencies": { "@babel/runtime-corejs3": "7.16.7", "@prisma/client": "3.15.2", - "base64url": "3.0.1", "core-js": "3.23.5", "cross-undici-fetch": "0.4.14", "crypto-js": "4.1.1", @@ -59,6 +58,7 @@ "@types/split2": "3.2.1", "@types/uuid": "8.3.4", "aws-lambda": "1.0.7", + "base64url": "3.0.1", "jest": "27.5.1", "split2": "4.1.0", "typescript": "4.7.4" diff --git a/packages/cli/src/commands/setup/auth/providers/dbAuth.webAuthn.js b/packages/cli/src/commands/setup/auth/providers/dbAuth.webAuthn.js index 0c1bd8fa1b9e..f183dad3feb8 100644 --- a/packages/cli/src/commands/setup/auth/providers/dbAuth.webAuthn.js +++ b/packages/cli/src/commands/setup/auth/providers/dbAuth.webAuthn.js @@ -20,7 +20,7 @@ export const config = { // required packages to install export const webPackages = ['@simplewebauthn/browser'] -export const apiPackages = ['@simplewebauthn/server'] +export const apiPackages = ['@simplewebauthn/server', 'base64url'] // any notes to print out when the job is done export const notes = [ From eb47db5d73403e5ad91abbb45f933fa3f36b2d35 Mon Sep 17 00:00:00 2001 From: Rob Cameron Date: Fri, 22 Jul 2022 10:32:49 -0700 Subject: [PATCH 02/10] Adds flag to force/skip install of WebAuthn and avoid terminal prompt when setting up dbAuth --- packages/cli/src/commands/setup/auth/auth.js | 24 +++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/commands/setup/auth/auth.js b/packages/cli/src/commands/setup/auth/auth.js index 138c29bd28e3..b28144bb1f54 100644 --- a/packages/cli/src/commands/setup/auth/auth.js +++ b/packages/cli/src/commands/setup/auth/auth.js @@ -31,6 +31,8 @@ const OUTPUT_PATHS = { ), } +const WEBAUTHN_SUPPORTED_PROVIDERS = ['dbAuth'] + const getWebAppPath = () => getPaths().web.app const getSupportedProviders = () => @@ -313,6 +315,12 @@ export const builder = (yargs) => { description: 'Overwrite existing configuration', type: 'boolean', }) + .option('webauthn', { + alias: 'w', + default: null, + description: 'Include WebAuthn support (TouchID/FaceID)', + type: 'boolean', + }) .epilogue( `Also see the ${terminalLink( 'Redwood CLI Reference', @@ -324,7 +332,7 @@ export const builder = (yargs) => { export const handler = async (yargs) => { const { provider, rwVersion } = yargs let force = yargs.force - let webAuthn = false + let includeWebAuthn = yargs.webauthn let providerData // check if api/src/lib/auth.js already exists and if so, ask the user to overwrite @@ -344,18 +352,22 @@ export const handler = async (yargs) => { } // only dbAuth supports WebAuthn right now, but in theory it could work with - // any provider - if (provider === 'dbAuth') { + // any provider, so we'll do a check here and potentially use any other + // providers webAuthn version of templates + if ( + includeWebAuthn === null && + WEBAUTHN_SUPPORTED_PROVIDERS.includes(provider) + ) { const webAuthnResponse = await prompts({ type: 'confirm', name: 'answer', message: `Enable WebAuthn support (TouchID/FaceID)? See https://redwoodjs.com/docs/auth/dbAuth#webAuthn`, initial: false, }) - webAuthn = webAuthnResponse.answer + includeWebAuthn = webAuthnResponse.answer } - if (webAuthn) { + if (includeWebAuthn) { providerData = await import(`./providers/${provider}.webAuthn`) } else { providerData = await import(`./providers/${provider}`) @@ -367,7 +379,7 @@ export const handler = async (yargs) => { title: 'Generating auth lib...', task: (_ctx, task) => { if (apiSrcDoesExist()) { - return writeFilesTask(files({ ...yargs, webAuthn }), { + return writeFilesTask(files({ ...yargs, includeWebAuthn }), { overwriteExisting: force, }) } else { From 5a0c512df9976ed44596f7e24ce5b2c5d86c75a8 Mon Sep 17 00:00:00 2001 From: Rob Cameron Date: Fri, 22 Jul 2022 10:37:16 -0700 Subject: [PATCH 03/10] Adds flag to force/skip install of WebAuthn and avoid terminal prompt when generating login pages --- .../src/commands/generate/dbAuth/dbAuth.js | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/cli/src/commands/generate/dbAuth/dbAuth.js b/packages/cli/src/commands/generate/dbAuth/dbAuth.js index 1bc683cbf191..a6f52cec0895 100644 --- a/packages/cli/src/commands/generate/dbAuth/dbAuth.js +++ b/packages/cli/src/commands/generate/dbAuth/dbAuth.js @@ -86,6 +86,13 @@ export const builder = (yargs) => { type: 'boolean', default: false, }) + .option('webauthn', { + alias: 'w', + default: null, + description: 'Include WebAuthn support (TouchID/FaceID)', + type: 'boolean', + }) + .epilogue( `Also see the ${terminalLink( 'Redwood CLI Reference', @@ -249,16 +256,20 @@ const tasks = ({ ) } -export const handler = async (options) => { - const response = await prompts({ - type: 'confirm', - name: 'answer', - message: `Enable WebAuthn support (TouchID/FaceID) on LoginPage? See https://redwoodjs.com/docs/auth/dbAuth#webAuthn`, - initial: false, - }) - const webAuthn = response.answer +export const handler = async (yargs) => { + let includeWebAuthn = yargs.webauthn + + if (includeWebAuthn === null) { + const response = await prompts({ + type: 'confirm', + name: 'answer', + message: `Enable WebAuthn support (TouchID/FaceID) on LoginPage? See https://redwoodjs.com/docs/auth/dbAuth#webAuthn`, + initial: false, + }) + includeWebAuthn = response.answer + } - const t = tasks({ ...options, webAuthn }) + const t = tasks({ ...yargs, webAuthn: includeWebAuthn }) try { await t.run() From e7f792e5b2837eed6b85b246fc13f4bfa772f98f Mon Sep 17 00:00:00 2001 From: Rob Cameron Date: Fri, 22 Jul 2022 10:37:51 -0700 Subject: [PATCH 04/10] =?UTF-8?q?Set=20=E2=80=94no-webauthn=20flags=20on?= =?UTF-8?q?=20test=20project=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/test-project/tasks.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tasks/test-project/tasks.js b/tasks/test-project/tasks.js index 0d810e3c1c23..181dc708aebf 100644 --- a/tasks/test-project/tasks.js +++ b/tasks/test-project/tasks.js @@ -307,7 +307,7 @@ async function apiTasks(outputPath, { verbose, linkWithLatestFwBuild }) { const addDbAuth = async () => { await execa( - 'yarn rw setup auth dbAuth --force', + 'yarn rw setup auth dbAuth --force --no-webauthn', [], getExecaOptions(outputPath) ) @@ -316,7 +316,11 @@ async function apiTasks(outputPath, { verbose, linkWithLatestFwBuild }) { await execa('yarn rwfw project:copy', [], getExecaOptions(outputPath)) } - await execa('yarn rw g dbAuth', [], getExecaOptions(outputPath)) + await execa( + 'yarn rw g dbAuth --no-webauthn', + [], + getExecaOptions(outputPath) + ) // add dbAuth User model const { user } = await import('./codemods/models.js') From 3e6859ebda83741437b705935146a07c8bc60342 Mon Sep 17 00:00:00 2001 From: Rob Cameron Date: Fri, 22 Jul 2022 10:47:35 -0700 Subject: [PATCH 05/10] Rename prop --- packages/cli/src/commands/setup/auth/auth.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/setup/auth/auth.js b/packages/cli/src/commands/setup/auth/auth.js index b28144bb1f54..d00b3a2a1a79 100644 --- a/packages/cli/src/commands/setup/auth/auth.js +++ b/packages/cli/src/commands/setup/auth/auth.js @@ -379,9 +379,12 @@ export const handler = async (yargs) => { title: 'Generating auth lib...', task: (_ctx, task) => { if (apiSrcDoesExist()) { - return writeFilesTask(files({ ...yargs, includeWebAuthn }), { - overwriteExisting: force, - }) + return writeFilesTask( + files({ ...yargs, webAuthn: includeWebAuthn }), + { + overwriteExisting: force, + } + ) } else { task.skip('api/src not found, skipping') } From a1e53b0dd8adefb1637837f967e56f626cf4a1de Mon Sep 17 00:00:00 2001 From: Rob Cameron Date: Sat, 23 Jul 2022 09:37:04 -0700 Subject: [PATCH 06/10] Require base64url in regular dbAuth setup --- packages/cli/src/commands/setup/auth/providers/dbAuth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/commands/setup/auth/providers/dbAuth.js b/packages/cli/src/commands/setup/auth/providers/dbAuth.js index eeaef15a64e8..e63b17cb6a5a 100644 --- a/packages/cli/src/commands/setup/auth/providers/dbAuth.js +++ b/packages/cli/src/commands/setup/auth/providers/dbAuth.js @@ -17,7 +17,7 @@ export const config = { // required packages to install export const webPackages = [] -export const apiPackages = [] +export const apiPackages = ['base64url'] export const libPath = getPaths().api.lib.replace(getPaths().base, '') export const functionsPath = getPaths().api.functions.replace( From 887af667d405943680d04f624a2f5e952a0447e0 Mon Sep 17 00:00:00 2001 From: Rob Cameron Date: Sat, 23 Jul 2022 09:39:11 -0700 Subject: [PATCH 07/10] Destructure webauthn rather than get from yargs.webauthn --- packages/cli/src/commands/setup/auth/auth.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/commands/setup/auth/auth.js b/packages/cli/src/commands/setup/auth/auth.js index d00b3a2a1a79..d775972df3a2 100644 --- a/packages/cli/src/commands/setup/auth/auth.js +++ b/packages/cli/src/commands/setup/auth/auth.js @@ -330,9 +330,9 @@ export const builder = (yargs) => { } export const handler = async (yargs) => { - const { provider, rwVersion } = yargs + const { provider, rwVersion, webauthn } = yargs let force = yargs.force - let includeWebAuthn = yargs.webauthn + let includeWebAuthn = webauthn let providerData // check if api/src/lib/auth.js already exists and if so, ask the user to overwrite @@ -352,8 +352,8 @@ export const handler = async (yargs) => { } // only dbAuth supports WebAuthn right now, but in theory it could work with - // any provider, so we'll do a check here and potentially use any other - // providers webAuthn version of templates + // any provider, so we'll do a check here and potentially use any the webAuthn + // version of its provider if ( includeWebAuthn === null && WEBAUTHN_SUPPORTED_PROVIDERS.includes(provider) From 2b9ebccdb2ee6ec76ba6f7ffc22b1e5b5113cb44 Mon Sep 17 00:00:00 2001 From: Rob Cameron Date: Mon, 25 Jul 2022 11:36:25 -0700 Subject: [PATCH 08/10] Revert "Require base64url in regular dbAuth setup" This reverts commit a1e53b0dd8adefb1637837f967e56f626cf4a1de. --- packages/cli/src/commands/setup/auth/providers/dbAuth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/commands/setup/auth/providers/dbAuth.js b/packages/cli/src/commands/setup/auth/providers/dbAuth.js index e63b17cb6a5a..eeaef15a64e8 100644 --- a/packages/cli/src/commands/setup/auth/providers/dbAuth.js +++ b/packages/cli/src/commands/setup/auth/providers/dbAuth.js @@ -17,7 +17,7 @@ export const config = { // required packages to install export const webPackages = [] -export const apiPackages = ['base64url'] +export const apiPackages = [] export const libPath = getPaths().api.lib.replace(getPaths().base, '') export const functionsPath = getPaths().api.functions.replace( From ff7032633f2e99dffb2857346b2bd4132f77a636 Mon Sep 17 00:00:00 2001 From: Rob Cameron Date: Mon, 25 Jul 2022 11:36:39 -0700 Subject: [PATCH 09/10] Revert "Make base64url a dependency install only if setting up dbAuth + webAuthn" This reverts commit 6d81c79e8fce7ab382afe7670cfbcd62063bda6d. --- packages/api/package.json | 2 +- .../cli/src/commands/setup/auth/providers/dbAuth.webAuthn.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/api/package.json b/packages/api/package.json index 1b2d429e3f0d..fdd4fc102997 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -32,6 +32,7 @@ "dependencies": { "@babel/runtime-corejs3": "7.16.7", "@prisma/client": "3.15.2", + "base64url": "3.0.1", "core-js": "3.23.5", "cross-undici-fetch": "0.4.14", "crypto-js": "4.1.1", @@ -58,7 +59,6 @@ "@types/split2": "3.2.1", "@types/uuid": "8.3.4", "aws-lambda": "1.0.7", - "base64url": "3.0.1", "jest": "27.5.1", "split2": "4.1.0", "typescript": "4.7.4" diff --git a/packages/cli/src/commands/setup/auth/providers/dbAuth.webAuthn.js b/packages/cli/src/commands/setup/auth/providers/dbAuth.webAuthn.js index f183dad3feb8..0c1bd8fa1b9e 100644 --- a/packages/cli/src/commands/setup/auth/providers/dbAuth.webAuthn.js +++ b/packages/cli/src/commands/setup/auth/providers/dbAuth.webAuthn.js @@ -20,7 +20,7 @@ export const config = { // required packages to install export const webPackages = ['@simplewebauthn/browser'] -export const apiPackages = ['@simplewebauthn/server', 'base64url'] +export const apiPackages = ['@simplewebauthn/server'] // any notes to print out when the job is done export const notes = [ From ca5f28eb3a9038ad9c1d4dffe1bcb4756c81b7c0 Mon Sep 17 00:00:00 2001 From: Rob Cameron Date: Mon, 25 Jul 2022 11:51:50 -0700 Subject: [PATCH 10/10] Test fixture depdendency update --- __fixtures__/test-project/web/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__fixtures__/test-project/web/package.json b/__fixtures__/test-project/web/package.json index f39145c8da22..08768f8a3338 100644 --- a/__fixtures__/test-project/web/package.json +++ b/__fixtures__/test-project/web/package.json @@ -25,7 +25,7 @@ "autoprefixer": "^10.4.7", "postcss": "^8.4.14", "postcss-loader": "^7.0.1", - "prettier-plugin-tailwindcss": "^0.1.12", + "prettier-plugin-tailwindcss": "^0.1.13", "tailwindcss": "^3.1.6" } }