Skip to content

Commit

Permalink
Merge pull request #350 from amplication/auth-plugins-support-passwor…
Browse files Browse the repository at this point in the history
…d-field

chore(plugins): allow auth plugins to support auth entity that has a Password field type
  • Loading branch information
mulygottlieb authored Mar 11, 2024
2 parents f349e87 + 50a2ec5 commit 1c49a69
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
13 changes: 11 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion plugins/auth-auth0/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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"
},
Expand Down
10 changes: 8 additions & 2 deletions plugins/auth-auth0/src/utils/createAuthProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]";
Expand All @@ -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<string, unknown>,
Expand Down Expand Up @@ -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}`);
Expand Down
6 changes: 4 additions & 2 deletions plugins/auth-keycloak/package.json
Original file line number Diff line number Diff line change
@@ -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": {},
Expand All @@ -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",
Expand Down
10 changes: 8 additions & 2 deletions plugins/auth-keycloak/src/utils/createAuthProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "[email protected]";
Expand All @@ -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<string, unknown>,
Expand Down Expand Up @@ -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}`);
Expand Down

0 comments on commit 1c49a69

Please sign in to comment.