diff --git a/package-lock.json b/package-lock.json index 684cf133..f4779e28 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5894,6 +5894,11 @@ "node": "*" } }, + "node_modules/crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "node_modules/crypto-random-string": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-2.0.0.tgz", @@ -12235,12 +12240,14 @@ }, "plugins/auth-auth0": { "name": "@amplication/plugin-auth-auth0", - "version": "1.0.7", + "version": "1.0.8", "license": "Apache-2.0", "dependencies": { "@amplication/code-gen-types": "^2.0.23", "@amplication/code-gen-utils": "^0.0.9", + "@types/node": "^20.11.24", "auth0": "^4.1.0", + "crypto-js": "^4.2.0", "lodash": "^4.17.21", "normalize-path": "^3.0.0" }, @@ -12360,11 +12367,13 @@ }, "plugins/auth-keycloak": { "name": "@amplication/plugin-auth-keycloak", - "version": "0.0.4", + "version": "0.0.5", "license": "Apache-2.0", "dependencies": { "@amplication/code-gen-types": "^2.0.23", "@amplication/code-gen-utils": "^0.0.9", + "@types/node": "^20.11.24", + "crypto-js": "^4.2.0", "js-convert-case": "^4.2.0", "lodash": "^4.17.21", "normalize-path": "^3.0.0" diff --git a/plugins/auth-auth0/package.json b/plugins/auth-auth0/package.json index f9adbc12..588b2499 100644 --- a/plugins/auth-auth0/package.json +++ b/plugins/auth-auth0/package.json @@ -1,6 +1,6 @@ { "name": "@amplication/plugin-auth-auth0", - "version": "1.0.7", + "version": "1.0.8", "description": "Auth0 plugin for Amplication", "main": "dist/index.js", "scripts": { @@ -16,6 +16,8 @@ "@amplication/code-gen-types": "^2.0.23", "@amplication/code-gen-utils": "^0.0.9", "auth0": "^4.1.0", + "crypto-js": "^4.2.0", + "@types/node": "^20.11.24", "lodash": "^4.17.21", "normalize-path": "^3.0.0" }, diff --git a/plugins/auth-auth0/src/utils/createAuthProperties.ts b/plugins/auth-auth0/src/utils/createAuthProperties.ts index f46235ea..37fb3b05 100644 --- a/plugins/auth-auth0/src/utils/createAuthProperties.ts +++ b/plugins/auth-auth0/src/utils/createAuthProperties.ts @@ -7,6 +7,7 @@ import { import { builders, namedTypes } from "ast-types"; import { memberExpression } from "@utils/ast"; import { createEnumName, pascalCase } from "@utils/helpers"; +import * as crypto from "crypto"; const DEFAULT_ADDRESS = "(32.085300, 34.781769)"; const DEFAULT_EMAIL = "example@example.com"; @@ -30,6 +31,10 @@ export const DEFAULT_ROLE_LITERAL = builders.arrayExpression([ builders.stringLiteral("user"), ]); +export function generateRandomString(): string { + return crypto.randomBytes(10).toString("hex"); +} + export function createAuthEntityObjectCustomProperties( authEntity: Entity, defaultValues: Record, @@ -135,8 +140,9 @@ export function createDefaultValue( return null; } case EnumDataType.Password: { - // Throw error on presence of password field in auth entity - throw new Error("Password field is not supported with Auth0 plugin"); + return defaultValue + ? builders.stringLiteral(defaultValue as string) + : builders.stringLiteral(generateRandomString()); } default: { throw new Error(`Unexpected data type: ${field.dataType}`); diff --git a/plugins/auth-keycloak/package.json b/plugins/auth-keycloak/package.json index 92ff7436..c35388ed 100644 --- a/plugins/auth-keycloak/package.json +++ b/plugins/auth-keycloak/package.json @@ -1,6 +1,6 @@ { "name": "@amplication/plugin-auth-keycloak", - "version": "0.0.4", + "version": "0.0.5", "description": "Keycloak Authentication plugin for Amplication", "main": "dist/index.js", "nx": {}, @@ -18,7 +18,9 @@ "@amplication/code-gen-utils": "^0.0.9", "js-convert-case": "^4.2.0", "lodash": "^4.17.21", - "normalize-path": "^3.0.0" + "normalize-path": "^3.0.0", + "crypto-js": "^4.2.0", + "@types/node": "^20.11.24" }, "devDependencies": { "@babel/parser": "^7.23.3", diff --git a/plugins/auth-keycloak/src/utils/createAuthProperties.ts b/plugins/auth-keycloak/src/utils/createAuthProperties.ts index 62942459..0c2447e8 100644 --- a/plugins/auth-keycloak/src/utils/createAuthProperties.ts +++ b/plugins/auth-keycloak/src/utils/createAuthProperties.ts @@ -8,6 +8,7 @@ import { builders, namedTypes } from "ast-types"; import { memberExpression } from "./ast"; import { createEnumName } from "./helpers"; import { toPascalCase } from "js-convert-case"; +import * as crypto from "crypto"; const DEFAULT_ADDRESS = "(32.085300, 34.781769)"; const DEFAULT_EMAIL = "example@example.com"; @@ -31,6 +32,10 @@ export const DEFAULT_ROLE_LITERAL = builders.arrayExpression([ builders.stringLiteral("user"), ]); +export function generateRandomString(): string { + return crypto.randomBytes(10).toString("hex"); +} + export function createAuthEntityObjectCustomProperties( authEntity: Entity, defaultValues: Record, @@ -136,8 +141,9 @@ export function createDefaultValue( return null; } case EnumDataType.Password: { - // Throw error on presence of password field in auth entity - throw new Error("Password field is not supported with Keycloak plugin"); + return defaultValue + ? builders.stringLiteral(defaultValue as string) + : builders.stringLiteral(generateRandomString()); } default: { throw new Error(`Unexpected data type: ${field.dataType}`);