-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #350 from amplication/auth-plugins-support-passwor…
…d-field chore(plugins): allow auth plugins to support auth entity that has a Password field type
- Loading branch information
Showing
5 changed files
with
34 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]"; | ||
|
@@ -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>, | ||
|
@@ -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}`); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]"; | ||
|
@@ -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>, | ||
|
@@ -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}`); | ||
|