Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@amplication/plugin-dotnet-auth-core-identity

Package Overview
Dependencies
Maintainers
7
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amplication/plugin-dotnet-auth-core-identity - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

5

.amplicationrc.json
{
"settings": {},
"systemSettings": {
"requireAuthenticationEntity": "true"
}
"settings": {}
}

6

package.json
{
"name": "@amplication/plugin-dotnet-auth-core-identity",
"version": "0.0.1",
"version": "0.0.2",
"description": "Add Authentication and Authorization to your .NET Services",

@@ -15,5 +15,5 @@ "main": "dist/index.js",

"devDependencies": {
"@amplication/code-gen-types": "2.0.33-beta.23",
"@amplication/code-gen-types": "2.0.34",
"@amplication/code-gen-utils": "^0.0.9",
"@amplication/csharp-ast": "0.0.3-beta.2",
"@amplication/csharp-ast": "0.0.3",
"@babel/parser": "^7.18.11",

@@ -20,0 +20,0 @@ "@babel/types": "^7.18.10",

@@ -6,2 +6,8 @@ import { CodeBlock } from "@amplication/csharp-ast";

new CodeBlock({
code: `app.UseApiAuthentication();`,
})
);
builderServicesBlocks.push(
new CodeBlock({
code: `using (var scope = app.Services.CreateScope())

@@ -8,0 +14,0 @@ {

@@ -1,15 +0,4 @@

import { Entity, EnumDataType } from "@amplication/code-gen-types";
import { CodeBlock, CsharpSupport } from "@amplication/csharp-ast";
import { camelCase } from "lodash";
import { pascalCase } from "pascal-case";
export function CreateSeedDevelopmentDataBody(
resourceName: string,
authEntity: Entity,
entities: Entity[]
): CodeBlock {
const { name, pluralName } = authEntity;
const entityNameToCamelCase = camelCase(name);
const entityNamePluralize = pascalCase(pluralName);
const entityFirstLetter = entityNameToCamelCase.slice(0, 1);
export function CreateSeedDevelopmentDataBody(resourceName: string): CodeBlock {
return new CodeBlock({

@@ -37,13 +26,11 @@ references: [

.ToArray();
${authEntityDto(authEntity, entities)}
if (!context.${entityNamePluralize}.Any(${entityFirstLetter} => ${entityFirstLetter}.UserName == ${entityNameToCamelCase}.UserName))
{
var password = new PasswordHasher<${name}>();
var hashed = password.HashPassword(${entityNameToCamelCase}, "password");
${entityNameToCamelCase}.PasswordHash = hashed;
var userStore = new UserStore<${name}>(context);
await userStore.CreateAsync(${entityNameToCamelCase});
var user = new IdentityUser { Email = "test@email.com", UserName = "admin" };
var password = new PasswordHasher<IdentityUser>();
var hashed = password.HashPassword(user, "password");
user.PasswordHash = hashed;
var userStore = new UserStore<IdentityUser>(context);
await userStore.CreateAsync(user);
var _roleManager = serviceProvider.GetRequiredService<RoleManager<IdentityRole>>();

@@ -53,6 +40,6 @@

{
await userStore.AddToRoleAsync(${entityNameToCamelCase}, _roleManager.NormalizeKey(role));
await userStore.AddToRoleAsync(user, _roleManager.NormalizeKey(role));
}
}
await context.SaveChangesAsync();`,

@@ -62,41 +49,40 @@ });

const authEntityDto = (authEntity: Entity, entities: Entity[]): string => {
const { fields } = authEntity;
let codeBlock = "";
// const authEntityDto = (entities: Entity[]): string => {
// let codeBlock = "";
for (const field of fields) {
const fieldNamePascalCase = pascalCase(field.name);
// for (const field of fields) {
// const fieldNamePascalCase = pascalCase(field.name);
if (field.dataType == EnumDataType.Lookup) {
const relatedEntity = entities.find(
(entity) => entity.id === field.properties?.relatedEntityId
);
// if (field.dataType == EnumDataType.Lookup) {
// const relatedEntity = entities.find(
// (entity) => entity.id === field.properties?.relatedEntityId
// );
const relatedEntityFieldName = pascalCase(field.name);
// const relatedEntityFieldName = pascalCase(field.name);
if (field.properties?.allowMultipleSelection) {
// the "many" side of the relation
codeBlock =
codeBlock +
`${fieldNamePascalCase} = model.${relatedEntityFieldName}.Select(x => new ${relatedEntity?.name}IdDto {Id = x.Id}).ToList(),\n`;
} else {
if (field.properties.fkHolderName === authEntity.name) {
break;
} else {
// the "one" side of the relation
codeBlock =
codeBlock +
`${fieldNamePascalCase} = new ${relatedEntity?.name}IdDto { Id = model.${fieldNamePascalCase}Id},\n`;
}
}
} else {
codeBlock =
codeBlock + `${fieldNamePascalCase} = model.${fieldNamePascalCase},\n`;
}
}
// if (field.properties?.allowMultipleSelection) {
// // the "many" side of the relation
// codeBlock =
// codeBlock +
// `${fieldNamePascalCase} = model.${relatedEntityFieldName}.Select(x => new ${relatedEntity?.name}IdDto {Id = x.Id}).ToList(),\n`;
// } else {
// if (field.properties.fkHolderName === authEntity.name) {
// break;
// } else {
// // the "one" side of the relation
// codeBlock =
// codeBlock +
// `${fieldNamePascalCase} = new ${relatedEntity?.name}IdDto { Id = model.${fieldNamePascalCase}Id},\n`;
// }
// }
// } else {
// codeBlock =
// codeBlock + `${fieldNamePascalCase} = model.${fieldNamePascalCase},\n`;
// }
// }
return `var ${camelCase(authEntity.name)} = new ${authEntity.name}
{
${codeBlock}
};`;
};
// return `var ${camelCase(authEntity.name)} = new ${authEntity.name}
// {
// ${codeBlock}
// };`;
// };

@@ -10,3 +10,3 @@ import { ClassReference, CodeBlock } from "@amplication/csharp-ast";

context: dotnetTypes.DsgContext,
classReference?: ClassReference
classReferences?: ClassReference[]
): Promise<FileMap<CodeBlock>> {

@@ -18,3 +18,3 @@ const fileMap = new FileMap<CodeBlock>(context.logger);

let fileContent = await readFile(filePath, "utf-8");
fileContent = fileContent.replace("ServiceName", resourceName);
fileContent = fileContent.replaceAll("ServiceName", resourceName);

@@ -25,3 +25,3 @@ const file: IFile<CodeBlock> = {

code: fileContent,
references: classReference && [classReference],
references: classReferences && classReferences,
}),

@@ -28,0 +28,0 @@ };

@@ -36,5 +36,2 @@ import {

},
CreateEntityModel: {
after: this.afterCreateEntityModel,
},
CreateResourceDbContextFile: {

@@ -110,6 +107,8 @@ after: this.afterCreateResourceDbContextFile,

context,
CsharpSupport.classReference({
name: `${resourceName}`,
namespace: `${resourceName}.Infrastructure`,
})
[
CsharpSupport.classReference({
name: `${resourceName}DbContext`,
namespace: `${resourceName}.Infrastructure`,
}),
]
);

@@ -134,25 +133,2 @@

afterCreateEntityModel(
context: dotnetTypes.DsgContext,
eventParams: dotnet.CreateEntityModelParams,
files: FileMap<Class>
): FileMap<Class> {
const { apisDir, entity } = eventParams;
const { resourceInfo } = context;
const authEntityName = resourceInfo?.settings.authEntityName;
if (entity.name !== authEntityName) return files;
const modelFile = files.get(`${apisDir}${authEntityName}.cs`);
if (!modelFile) return files;
modelFile.code.parentClassReference = CsharpSupport.classReference({
name: "IdentityUser",
namespace: "",
});
return files;
}
afterCreateResourceDbContextFile(

@@ -163,10 +139,4 @@ context: dotnetTypes.DsgContext,

): FileMap<Class> {
const { resourceDbContextPath, entities, resourceName } = eventParams;
const { resourceInfo } = context;
const authEntityName = resourceInfo?.settings.authEntityName;
const { resourceDbContextPath, resourceName } = eventParams;
const authEntityCheck = entities.find((e) => e.name === authEntityName);
if (!authEntityCheck) return files;
const modelFile = files.get(

@@ -178,5 +148,13 @@ `${resourceDbContextPath}${resourceName}DbContext.cs`

modelFile.code.parentClassReference = CsharpSupport.classReference({
name: `IdentityDbContext<${authEntityName}>`,
namespace: "",
modelFile.code.parentClassReference = CsharpSupport.genericClassReference({
reference: CsharpSupport.classReference({
name: `IdentityDbContext`,
namespace: "Microsoft.AspNetCore.Identity.EntityFrameworkCore",
}),
innerType: CsharpSupport.Types.reference(
CsharpSupport.classReference({
name: `IdentityUser`,
namespace: "Microsoft.AspNetCore.Identity",
})
),
});

@@ -199,3 +177,3 @@

const controllerBaseFile = files.get(
`${apisDir}/${entity.name}/base/${pascalPluralName}ControllerBase.cs`
`${apisDir}/${entity.name}/Base/${pascalPluralName}ControllerBase.cs`
);

@@ -386,10 +364,6 @@

const { seedFilePath, resourceName } = eventParams;
const { resourceInfo, entities } = context;
const { entities } = context;
const authEntity = entities?.find(
(e) => e.name === resourceInfo?.settings.authEntityName
);
if (!entities) return files;
if (!authEntity || !entities) return files;
const seedFile = files.get(seedFilePath);

@@ -401,3 +375,3 @@ seedFile?.code.addMethod(

isAsync: true,
body: CreateSeedDevelopmentDataBody(resourceName, authEntity, entities),
body: CreateSeedDevelopmentDataBody(resourceName),
type: MethodType.STATIC,

@@ -410,3 +384,3 @@ parameters: [

name: "IServiceProvider",
namespace: "",
namespace: `${resourceName}.Infrastructure.Models`,
})

@@ -413,0 +387,0 @@ ),

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc