@webiny/api-core 6.5.2-beta.0 → 6.5.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/features/httpClient/HttpClient.js +4 -3
- package/features/httpClient/HttpClient.js.map +1 -1
- package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js +2 -0
- package/features/security/apiKeys/CreateApiKey/CreateApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.d.ts +2 -2
- package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js +7 -1
- package/features/security/apiKeys/GetApiKey/GetApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/GetApiKey/abstractions.d.ts +3 -3
- package/features/security/apiKeys/GetApiKey/abstractions.js.map +1 -1
- package/features/security/apiKeys/ListApiKeys/ListApiKeysUseCase.d.ts +2 -2
- package/features/security/apiKeys/ListApiKeys/ListApiKeysUseCase.js +4 -1
- package/features/security/apiKeys/ListApiKeys/ListApiKeysUseCase.js.map +1 -1
- package/features/security/apiKeys/ListApiKeys/abstractions.d.ts +3 -4
- package/features/security/apiKeys/ListApiKeys/abstractions.js.map +1 -1
- package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js +2 -0
- package/features/security/apiKeys/UpdateApiKey/UpdateApiKeyUseCase.js.map +1 -1
- package/features/security/apiKeys/shared/hideToken.d.ts +8 -0
- package/features/security/apiKeys/shared/hideToken.js +11 -0
- package/features/security/apiKeys/shared/hideToken.js.map +1 -0
- package/features/security/apiKeys/shared/types.d.ts +7 -0
- package/features/security/roles/CreateRole/CreateRoleUseCase.js +6 -0
- package/features/security/roles/CreateRole/CreateRoleUseCase.js.map +1 -1
- package/features/security/roles/DeleteRole/DeleteRoleUseCase.js +2 -1
- package/features/security/roles/DeleteRole/DeleteRoleUseCase.js.map +1 -1
- package/features/security/roles/DeleteRole/abstractions.d.ts +2 -1
- package/features/security/roles/DeleteRole/abstractions.js.map +1 -1
- package/features/security/roles/UpdateRole/UpdateRoleUseCase.js +10 -1
- package/features/security/roles/UpdateRole/UpdateRoleUseCase.js.map +1 -1
- package/features/security/roles/UpdateRole/abstractions.d.ts +2 -1
- package/features/security/roles/UpdateRole/abstractions.js.map +1 -1
- package/features/security/roles/shared/decorators/RolesRepositoryCachingDecorator.d.ts +5 -2
- package/features/security/roles/shared/decorators/RolesRepositoryCachingDecorator.js +16 -3
- package/features/security/roles/shared/decorators/RolesRepositoryCachingDecorator.js.map +1 -1
- package/features/security/roles/shared/errors.d.ts +8 -0
- package/features/security/roles/shared/errors.js +15 -1
- package/features/security/roles/shared/errors.js.map +1 -1
- package/features/security/teams/CreateTeam/CreateTeamUseCase.d.ts +3 -1
- package/features/security/teams/CreateTeam/CreateTeamUseCase.js +17 -2
- package/features/security/teams/CreateTeam/CreateTeamUseCase.js.map +1 -1
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.d.ts +3 -1
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js +20 -2
- package/features/security/teams/UpdateTeam/UpdateTeamUseCase.js.map +1 -1
- package/features/security/utils/canAssignRolesAndTeams.d.ts +16 -0
- package/features/security/utils/canAssignRolesAndTeams.js +31 -0
- package/features/security/utils/canAssignRolesAndTeams.js.map +1 -0
- package/features/security/utils/canGrantPermissions.d.ts +53 -0
- package/features/security/utils/canGrantPermissions.js +122 -0
- package/features/security/utils/canGrantPermissions.js.map +1 -0
- package/features/security/utils/verifyJwtUsingJwk.d.ts +16 -1
- package/features/security/utils/verifyJwtUsingJwk.js +22 -4
- package/features/security/utils/verifyJwtUsingJwk.js.map +1 -1
- package/features/system/InstallSystem/InstallSystemUseCase.d.ts +1 -1
- package/features/tenancy/CreateTenant/CreateTenantRepository.js +1 -0
- package/features/tenancy/CreateTenant/CreateTenantRepository.js.map +1 -1
- package/features/tenancy/CreateTenant/CreateTenantUseCase.d.ts +5 -3
- package/features/tenancy/CreateTenant/CreateTenantUseCase.js +10 -3
- package/features/tenancy/CreateTenant/CreateTenantUseCase.js.map +1 -1
- package/features/tenancy/CreateTenant/abstractions.d.ts +2 -1
- package/features/tenancy/CreateTenant/abstractions.js.map +1 -1
- package/features/tenancy/CreateTenant/decorators/CreateTenantWithWcpIncrement.d.ts +1 -1
- package/features/tenancy/CreateTenant/errors.d.ts +6 -0
- package/features/tenancy/CreateTenant/errors.js +11 -1
- package/features/tenancy/CreateTenant/errors.js.map +1 -1
- package/features/tenancy/DeleteTenant/decorators/DeleteTenantWithWcpDecrement.js +1 -0
- package/features/tenancy/DeleteTenant/decorators/DeleteTenantWithWcpDecrement.js.map +1 -1
- package/features/tenancy/TenantContext/TenantContext.d.ts +2 -0
- package/features/tenancy/TenantContext/TenantContext.js +18 -21
- package/features/tenancy/TenantContext/TenantContext.js.map +1 -1
- package/features/tenancy/TenantContext/abstractions.d.ts +5 -0
- package/features/tenancy/TenantContext/abstractions.js.map +1 -1
- package/features/users/CreateUser/CreateUserUseCase.d.ts +5 -1
- package/features/users/CreateUser/CreateUserUseCase.js +19 -4
- package/features/users/CreateUser/CreateUserUseCase.js.map +1 -1
- package/features/users/UpdateUser/UpdateUserUseCase.d.ts +5 -1
- package/features/users/UpdateUser/UpdateUserUseCase.js +24 -2
- package/features/users/UpdateUser/UpdateUserUseCase.js.map +1 -1
- package/graphql/security/apiKey.gql.js +1 -0
- package/graphql/security/apiKey.gql.js.map +1 -1
- package/idp/OidcJwtIdentityProvider.js +4 -1
- package/idp/OidcJwtIdentityProvider.js.map +1 -1
- package/legacy/security/LegacyContext.d.ts +1 -1
- package/legacy/security/LegacyContext.js.map +1 -1
- package/legacy/security/plugins/authenticateUsingCookie.d.ts +7 -0
- package/legacy/security/plugins/authenticateUsingCookie.js +7 -1
- package/legacy/security/plugins/authenticateUsingCookie.js.map +1 -1
- package/legacy/security/plugins/secureHeaders.js +5 -2
- package/legacy/security/plugins/secureHeaders.js.map +1 -1
- package/package.json +22 -22
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/users/UpdateUser/UpdateUserUseCase.js","sources":["../../../../src/features/users/UpdateUser/UpdateUserUseCase.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { UpdateUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AdminUsersRepository } from \"~/features/users/shared/abstractions.js\";\nimport { updateUserValidation } from \"./schema.js\";\nimport {\n NotAuthorizedError,\n EmailTakenError,\n UserValidationError\n} from \"~/features/users/shared/errors.js\";\nimport { UserBeforeUpdateEvent, UserAfterUpdateEvent } from \"./events.js\";\nimport type { AdminUser } from \"~/features/users/shared/types.js\";\nimport type { UpdateUserInput } from \"~/features/users/shared/types.js\";\n\nclass UpdateUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: AdminUsersRepository.Interface\n ) {}\n\n async execute(\n id: string,\n input: UpdateUserInput\n ): Promise<Result<AdminUser, UseCaseAbstraction.Error>> {\n // 1. Check permission\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n // 2. Validate input\n const validation = updateUserValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new UserValidationError(validation.error.issues[0].message));\n }\n\n // If the input contains email, check if it is free to use.\n if (input.email) {\n const existingUserResult = await this.repository.get({ email: input.email });\n if (existingUserResult.isOk()) {\n if (existingUserResult.value.id !== id) {\n return Result.fail(new EmailTakenError(input.email));\n }\n }\n }\n // 3. Get existing user\n const getUserResult = await this.repository.get({ id });\n if (getUserResult.isFail()) {\n return Result.fail(getUserResult.error);\n }\n\n const originalUser = getUserResult.value;\n\n // 4. Clone update data for event modification\n const updateData = structuredClone(validation.data);\n\n // 5. Publish before event\n await this.eventPublisher.publish(\n new UserBeforeUpdateEvent({ user: originalUser, updateData, input: validation.data })\n );\n\n // 6. Merge updates with existing user\n const updatedUser: AdminUser = {\n ...originalUser,\n ...updateData\n };\n\n // 7. Update user via repository\n const result = await this.repository.update(updatedUser);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n // 8. Publish after event\n await this.eventPublisher.publish(\n new UserAfterUpdateEvent({\n originalUser,\n updatedUser: result.value,\n input: validation.data\n })\n );\n\n return Result.ok(result.value);\n }\n}\n\nexport const UpdateUserUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: UpdateUserUseCaseImpl,\n dependencies: [IdentityContext
|
|
1
|
+
{"version":3,"file":"features/users/UpdateUser/UpdateUserUseCase.js","sources":["../../../../src/features/users/UpdateUser/UpdateUserUseCase.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/feature/api\";\nimport { Result } from \"@webiny/feature/api\";\nimport { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport { EventPublisher } from \"~/features/eventPublisher/index.js\";\nimport { UpdateUserUseCase as UseCaseAbstraction } from \"./abstractions.js\";\nimport { AdminUsersRepository } from \"~/features/users/shared/abstractions.js\";\nimport { RolesRepository } from \"~/features/security/roles/shared/abstractions.js\";\nimport { TeamsRepository } from \"~/features/security/teams/shared/abstractions.js\";\nimport { canAssignRolesAndTeams } from \"~/features/security/utils/canAssignRolesAndTeams.js\";\nimport { CANNOT_GRANT_PERMISSIONS_MESSAGE } from \"~/features/security/utils/canGrantPermissions.js\";\nimport { updateUserValidation } from \"./schema.js\";\nimport {\n NotAuthorizedError,\n EmailTakenError,\n UserValidationError\n} from \"~/features/users/shared/errors.js\";\nimport { UserBeforeUpdateEvent, UserAfterUpdateEvent } from \"./events.js\";\nimport type { AdminUser } from \"~/features/users/shared/types.js\";\nimport type { UpdateUserInput } from \"~/features/users/shared/types.js\";\n\nclass UpdateUserUseCaseImpl implements UseCaseAbstraction.Interface {\n constructor(\n private identityContext: IdentityContext.Interface,\n private eventPublisher: EventPublisher.Interface,\n private repository: AdminUsersRepository.Interface,\n private rolesRepository: RolesRepository.Interface,\n private teamsRepository: TeamsRepository.Interface\n ) {}\n\n async execute(\n id: string,\n input: UpdateUserInput\n ): Promise<Result<AdminUser, UseCaseAbstraction.Error>> {\n // 1. Check permission\n const permission = await this.identityContext.getPermission(\"adminUsers.user\");\n if (!permission) {\n return Result.fail(new NotAuthorizedError());\n }\n\n // 2. Validate input\n const validation = updateUserValidation.safeParse(input);\n if (!validation.success) {\n return Result.fail(new UserValidationError(validation.error.issues[0].message));\n }\n\n // If the input contains email, check if it is free to use.\n if (input.email) {\n const existingUserResult = await this.repository.get({ email: input.email });\n if (existingUserResult.isOk()) {\n if (existingUserResult.value.id !== id) {\n return Result.fail(new EmailTakenError(input.email));\n }\n }\n }\n // 3. Get existing user\n const getUserResult = await this.repository.get({ id });\n if (getUserResult.isFail()) {\n return Result.fail(getUserResult.error);\n }\n\n const originalUser = getUserResult.value;\n\n /**\n * Security: the caller may only assign roles and teams whose permissions they hold, and\n * may only manage a user whose current roles and teams they could assign (otherwise they\n * could, for example, change the password of a user with more access than they have).\n */\n const canAssign = await canAssignRolesAndTeams({\n identityContext: this.identityContext,\n rolesRepository: this.rolesRepository,\n teamsRepository: this.teamsRepository,\n roles: [...(originalUser.roles ?? []), ...(validation.data.roles ?? [])],\n teams: [...(originalUser.teams ?? []), ...(validation.data.teams ?? [])]\n });\n if (!canAssign) {\n return Result.fail(new NotAuthorizedError(CANNOT_GRANT_PERMISSIONS_MESSAGE));\n }\n\n // 4. Clone update data for event modification\n const updateData = structuredClone(validation.data);\n\n // 5. Publish before event\n await this.eventPublisher.publish(\n new UserBeforeUpdateEvent({ user: originalUser, updateData, input: validation.data })\n );\n\n // 6. Merge updates with existing user\n const updatedUser: AdminUser = {\n ...originalUser,\n ...updateData\n };\n\n // 7. Update user via repository\n const result = await this.repository.update(updatedUser);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n // 8. Publish after event\n await this.eventPublisher.publish(\n new UserAfterUpdateEvent({\n originalUser,\n updatedUser: result.value,\n input: validation.data\n })\n );\n\n return Result.ok(result.value);\n }\n}\n\nexport const UpdateUserUseCase = createImplementation({\n abstraction: UseCaseAbstraction,\n implementation: UpdateUserUseCaseImpl,\n dependencies: [\n IdentityContext,\n EventPublisher,\n AdminUsersRepository,\n RolesRepository,\n TeamsRepository\n ]\n});\n"],"names":["UpdateUserUseCaseImpl","identityContext","eventPublisher","repository","rolesRepository","teamsRepository","id","input","permission","Result","NotAuthorizedError","validation","updateUserValidation","UserValidationError","existingUserResult","EmailTakenError","getUserResult","originalUser","canAssign","canAssignRolesAndTeams","CANNOT_GRANT_PERMISSIONS_MESSAGE","updateData","structuredClone","UserBeforeUpdateEvent","updatedUser","result","UserAfterUpdateEvent","UpdateUserUseCase","createImplementation","UseCaseAbstraction","IdentityContext","EventPublisher","AdminUsersRepository","RolesRepository","TeamsRepository"],"mappings":";;;;;;;;;;;;AAoBA,MAAMA;IACF,YACYC,eAA0C,EAC1CC,cAAwC,EACxCC,UAA0C,EAC1CC,eAA0C,EAC1CC,eAA0C,CACpD;aALUJ,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,UAAU,GAAVA;aACAC,eAAe,GAAfA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,QACFC,EAAU,EACVC,KAAsB,EAC8B;QAEpD,MAAMC,aAAa,MAAM,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;QAC5D,IAAI,CAACA,YACD,OAAOC,OAAO,IAAI,CAAC,IAAIC;QAI3B,MAAMC,aAAaC,qBAAqB,SAAS,CAACL;QAClD,IAAI,CAACI,WAAW,OAAO,EACnB,OAAOF,OAAO,IAAI,CAAC,IAAII,oBAAoBF,WAAW,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO;QAIjF,IAAIJ,MAAM,KAAK,EAAE;YACb,MAAMO,qBAAqB,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;gBAAE,OA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AC1B;QAGJ,OAAOF,OAAO,EAAE,CAACgB,OAAO,KAAK;IACjC;AACJ;AAEO,MAAME,sCAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgB7B;IAChB,cAAc;QACV8B;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/security/apiKey.gql.js","sources":["../../../src/graphql/security/apiKey.gql.ts"],"sourcesContent":["import { Response, ErrorResponse } from \"@webiny/handler-graphql/responses.js\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/plugins/GraphQLSchemaPlugin.js\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { CreateApiKeyUseCase } from \"~/features/security/apiKeys/CreateApiKey/index.js\";\nimport { UpdateApiKeyUseCase } from \"~/features/security/apiKeys/UpdateApiKey/index.js\";\nimport { DeleteApiKeyUseCase } from \"~/features/security/apiKeys/DeleteApiKey/index.js\";\nimport { ListApiKeysUseCase } from \"~/features/security/apiKeys/ListApiKeys/index.js\";\nimport { GetApiKeyUseCase } from \"~/features/security/apiKeys/GetApiKey/index.js\";\n\nexport default new GraphQLSchemaPlugin<ApiCoreContext>({\n typeDefs: /* GraphQL */ `\n type SecurityApiKey {\n id: ID\n name: String\n slug: String\n description: String\n token: String\n permissions: [JSON]\n createdOn: DateTime\n createdBy: SecurityCreatedBy\n }\n\n input SecurityApiKeyInput {\n id: ID\n name: String!\n slug: String\n description: String\n token: String\n permissions: [JSON]!\n }\n\n type SecurityApiKeyResponse {\n data: SecurityApiKey\n error: SecurityError\n }\n\n type SecurityApiKeyListResponse {\n data: [SecurityApiKey!]\n error: SecurityError\n }\n\n extend type SecurityQuery {\n listApiKeys: SecurityApiKeyListResponse\n getApiKey(id: ID!): SecurityApiKeyResponse\n }\n\n extend type SecurityMutation {\n createApiKey(data: SecurityApiKeyInput!): SecurityApiKeyResponse\n updateApiKey(id: ID!, data: SecurityApiKeyInput!): SecurityApiKeyResponse\n deleteApiKey(id: ID!): SecurityBooleanResponse\n }\n `,\n resolvers: {\n SecurityQuery: {\n async listApiKeys(_, __, context) {\n const list = context.container.resolve(ListApiKeysUseCase);\n const result = await list.execute();\n\n if (result.isOk()) {\n return new Response(result.value);\n }\n return new ErrorResponse(result.error);\n },\n async getApiKey(_, args: any, context) {\n const getById = context.container.resolve(GetApiKeyUseCase);\n const result = await getById.execute(args.id);\n\n if (result.isOk()) {\n return new Response(result.value);\n }\n return new ErrorResponse(result.error);\n }\n },\n SecurityMutation: {\n async createApiKey(_, args: any, context) {\n const createApiKey = context.container.resolve(CreateApiKeyUseCase);\n const result = await createApiKey.execute(args.data);\n\n if (result.isOk()) {\n return new Response(result.value);\n }\n return new ErrorResponse(result.error);\n },\n async updateApiKey(_, args: any, context) {\n const updateApiKey = context.container.resolve(UpdateApiKeyUseCase);\n const result = await updateApiKey.execute(args.id, args.data);\n\n if (result.isOk()) {\n return new Response(result.value);\n }\n return new ErrorResponse(result.error);\n },\n async deleteApiKey(_, args: any, context) {\n const deleteApiKey = context.container.resolve(DeleteApiKeyUseCase);\n const result = await deleteApiKey.execute(args.id);\n\n if (result.isOk()) {\n return new Response(true);\n }\n return new ErrorResponse(result.error);\n }\n }\n }\n});\n"],"names":["GraphQLSchemaPlugin","_","__","context","list","ListApiKeysUseCase","result","Response","ErrorResponse","args","getById","GetApiKeyUseCase","createApiKey","CreateApiKeyUseCase","updateApiKey","UpdateApiKeyUseCase","deleteApiKey","DeleteApiKeyUseCase"],"mappings":";;;;;;;AASA,mBAAe,IAAIA,oBAAoC;IACnD,UAAwB,CAAC
|
|
1
|
+
{"version":3,"file":"graphql/security/apiKey.gql.js","sources":["../../../src/graphql/security/apiKey.gql.ts"],"sourcesContent":["import { Response, ErrorResponse } from \"@webiny/handler-graphql/responses.js\";\nimport { GraphQLSchemaPlugin } from \"@webiny/handler-graphql/plugins/GraphQLSchemaPlugin.js\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { CreateApiKeyUseCase } from \"~/features/security/apiKeys/CreateApiKey/index.js\";\nimport { UpdateApiKeyUseCase } from \"~/features/security/apiKeys/UpdateApiKey/index.js\";\nimport { DeleteApiKeyUseCase } from \"~/features/security/apiKeys/DeleteApiKey/index.js\";\nimport { ListApiKeysUseCase } from \"~/features/security/apiKeys/ListApiKeys/index.js\";\nimport { GetApiKeyUseCase } from \"~/features/security/apiKeys/GetApiKey/index.js\";\n\nexport default new GraphQLSchemaPlugin<ApiCoreContext>({\n typeDefs: /* GraphQL */ `\n type SecurityApiKey {\n id: ID\n name: String\n slug: String\n description: String\n # Security: null when the caller doesn't have full access.\n token: String\n permissions: [JSON]\n createdOn: DateTime\n createdBy: SecurityCreatedBy\n }\n\n input SecurityApiKeyInput {\n id: ID\n name: String!\n slug: String\n description: String\n token: String\n permissions: [JSON]!\n }\n\n type SecurityApiKeyResponse {\n data: SecurityApiKey\n error: SecurityError\n }\n\n type SecurityApiKeyListResponse {\n data: [SecurityApiKey!]\n error: SecurityError\n }\n\n extend type SecurityQuery {\n listApiKeys: SecurityApiKeyListResponse\n getApiKey(id: ID!): SecurityApiKeyResponse\n }\n\n extend type SecurityMutation {\n createApiKey(data: SecurityApiKeyInput!): SecurityApiKeyResponse\n updateApiKey(id: ID!, data: SecurityApiKeyInput!): SecurityApiKeyResponse\n deleteApiKey(id: ID!): SecurityBooleanResponse\n }\n `,\n resolvers: {\n SecurityQuery: {\n async listApiKeys(_, __, context) {\n const list = context.container.resolve(ListApiKeysUseCase);\n const result = await list.execute();\n\n if (result.isOk()) {\n return new Response(result.value);\n }\n return new ErrorResponse(result.error);\n },\n async getApiKey(_, args: any, context) {\n const getById = context.container.resolve(GetApiKeyUseCase);\n const result = await getById.execute(args.id);\n\n if (result.isOk()) {\n return new Response(result.value);\n }\n return new ErrorResponse(result.error);\n }\n },\n SecurityMutation: {\n async createApiKey(_, args: any, context) {\n const createApiKey = context.container.resolve(CreateApiKeyUseCase);\n const result = await createApiKey.execute(args.data);\n\n if (result.isOk()) {\n return new Response(result.value);\n }\n return new ErrorResponse(result.error);\n },\n async updateApiKey(_, args: any, context) {\n const updateApiKey = context.container.resolve(UpdateApiKeyUseCase);\n const result = await updateApiKey.execute(args.id, args.data);\n\n if (result.isOk()) {\n return new Response(result.value);\n }\n return new ErrorResponse(result.error);\n },\n async deleteApiKey(_, args: any, context) {\n const deleteApiKey = context.container.resolve(DeleteApiKeyUseCase);\n const result = await deleteApiKey.execute(args.id);\n\n if (result.isOk()) {\n return new Response(true);\n }\n return new ErrorResponse(result.error);\n }\n }\n }\n});\n"],"names":["GraphQLSchemaPlugin","_","__","context","list","ListApiKeysUseCase","result","Response","ErrorResponse","args","getById","GetApiKeyUseCase","createApiKey","CreateApiKeyUseCase","updateApiKey","UpdateApiKeyUseCase","deleteApiKey","DeleteApiKeyUseCase"],"mappings":";;;;;;;AASA,mBAAe,IAAIA,oBAAoC;IACnD,UAAwB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA0CzB,CAAC;IACD,WAAW;QACP,eAAe;YACX,MAAM,aAAYC,CAAC,EAAEC,EAAE,EAAEC,OAAO;gBAC5B,MAAMC,OAAOD,QAAQ,SAAS,CAAC,OAAO,CAACE;gBACvC,MAAMC,SAAS,MAAMF,KAAK,OAAO;gBAEjC,IAAIE,OAAO,IAAI,IACX,OAAO,IAAIC,SAASD,OAAO,KAAK;gBAEpC,OAAO,IAAIE,cAAcF,OAAO,KAAK;YACzC;YACA,MAAM,WAAUL,CAAC,EAAEQ,IAAS,EAAEN,OAAO;gBACjC,MAAMO,UAAUP,QAAQ,SAAS,CAAC,OAAO,CAACQ;gBAC1C,MAAML,SAAS,MAAMI,QAAQ,OAAO,CAACD,KAAK,EAAE;gBAE5C,IAAIH,OAAO,IAAI,IACX,OAAO,IAAIC,SAASD,OAAO,KAAK;gBAEpC,OAAO,IAAIE,cAAcF,OAAO,KAAK;YACzC;QACJ;QACA,kBAAkB;YACd,MAAM,cAAaL,CAAC,EAAEQ,IAAS,EAAEN,OAAO;gBACpC,MAAMS,eAAeT,QAAQ,SAAS,CAAC,OAAO,CAACU;gBAC/C,MAAMP,SAAS,MAAMM,aAAa,OAAO,CAACH,KAAK,IAAI;gBAEnD,IAAIH,OAAO,IAAI,IACX,OAAO,IAAIC,SAASD,OAAO,KAAK;gBAEpC,OAAO,IAAIE,cAAcF,OAAO,KAAK;YACzC;YACA,MAAM,cAAaL,CAAC,EAAEQ,IAAS,EAAEN,OAAO;gBACpC,MAAMW,eAAeX,QAAQ,SAAS,CAAC,OAAO,CAACY;gBAC/C,MAAMT,SAAS,MAAMQ,aAAa,OAAO,CAACL,KAAK,EAAE,EAAEA,KAAK,IAAI;gBAE5D,IAAIH,OAAO,IAAI,IACX,OAAO,IAAIC,SAASD,OAAO,KAAK;gBAEpC,OAAO,IAAIE,cAAcF,OAAO,KAAK;YACzC;YACA,MAAM,cAAaL,CAAC,EAAEQ,IAAS,EAAEN,OAAO;gBACpC,MAAMa,eAAeb,QAAQ,SAAS,CAAC,OAAO,CAACc;gBAC/C,MAAMX,SAAS,MAAMU,aAAa,OAAO,CAACP,KAAK,EAAE;gBAEjD,IAAIH,OAAO,IAAI,IACX,OAAO,IAAIC,SAAS;gBAExB,OAAO,IAAIC,cAAcF,OAAO,KAAK;YACzC;QACJ;IACJ;AACJ"}
|
|
@@ -41,7 +41,10 @@ class OidcJwtIdentityProviderImpl {
|
|
|
41
41
|
const jwks = await this.jwksCache.getKeys(provider.issuer);
|
|
42
42
|
const jwk = jwks.find((key)=>key.kid === header.kid);
|
|
43
43
|
if (!jwk) return null;
|
|
44
|
-
if (!verifiedPayload) verifiedPayload = await verifyJwtUsingJwk(token, jwk
|
|
44
|
+
if (!verifiedPayload) verifiedPayload = await verifyJwtUsingJwk(token, jwk, {
|
|
45
|
+
issuer: provider.issuer,
|
|
46
|
+
audience: provider.clientId
|
|
47
|
+
});
|
|
45
48
|
if (provider.verifyTokenClaims) await provider.verifyTokenClaims(verifiedPayload);
|
|
46
49
|
return verifiedPayload;
|
|
47
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idp/OidcJwtIdentityProvider.js","sources":["../../src/idp/OidcJwtIdentityProvider.ts"],"sourcesContent":["import { verifyJwtUsingJwk } from \"~/features/security/utils/verifyJwtUsingJwk.js\";\nimport type { IdentityData } from \"~/features/security/IdentityContext/Identity.js\";\nimport { JwkCache, JwtIdentityProvider, OidcIdentityProvider } from \"./abstractions.js\";\n\nclass OidcJwtIdentityProviderImpl implements JwtIdentityProvider.Interface {\n constructor(\n private oidcIdentityProviders: OidcIdentityProvider.Interface[],\n private jwksCache: JwkCache.Interface\n ) {}\n\n isApplicable(token: JwtIdentityProvider.JwtPayload): boolean {\n return this.oidcIdentityProviders.some(provider => provider.isApplicable(token));\n }\n\n async getIdentity(token: string, jwt: JwtIdentityProvider.Jwt): Promise<IdentityData | null> {\n const { header, payload } = jwt;\n\n const provider = this.getApplicableProvider(payload);\n\n if (!provider) {\n return null;\n }\n\n const verifiedPayload = await this.verifyToken(provider, token, header);\n\n if (!verifiedPayload) {\n return null;\n }\n\n // Call config.getIdentity to get IdentityData\n const providerIdentity = await provider.getIdentity(verifiedPayload);\n\n const identity: IdentityData = {\n ...providerIdentity,\n type: providerIdentity.type ?? \"admin\"\n };\n\n // Handle default values\n const context = identity.context ?? { canAccessTenant: true, defaultTenantId: \"root\" };\n if (context.canAccessTenant === undefined) {\n context.canAccessTenant = true;\n }\n if (context.defaultTenantId === undefined) {\n context.defaultTenantId = \"root\";\n }\n\n identity.context = context;\n\n return identity;\n }\n\n private getApplicableProvider(\n payload: JwtIdentityProvider.JwtPayload\n ): OidcIdentityProvider.Interface | undefined {\n return this.oidcIdentityProviders.find(provider => provider.isApplicable(payload));\n }\n\n private async verifyToken(\n provider: OidcIdentityProvider.Interface,\n token: string,\n header: JwtIdentityProvider.JwtHeader\n ) {\n // If the implementation specifies a custom verification function, use it.\n let verifiedPayload: JwtIdentityProvider.JwtPayload | undefined;\n if (typeof provider.verifyToken === \"function\") {\n // Use custom verification\n const result = await provider.verifyToken(token);\n if (result) {\n return result;\n }\n return null;\n }\n\n // Otherwise, continue with OIDC best practices, using JWKs.\n\n // Fetch JWKs from cache\n const jwks = await this.jwksCache.getKeys(provider.issuer);\n\n // Find matching JWK using header.kid\n const jwk = jwks.find(key => key.kid === header.kid);\n if (!jwk) {\n return null;\n }\n\n if (!verifiedPayload) {\n // Default JWK verification\n verifiedPayload = await verifyJwtUsingJwk(token, jwk);\n }\n\n // Call verifyTokenClaims if provided\n if (provider.verifyTokenClaims) {\n await provider.verifyTokenClaims(verifiedPayload);\n }\n\n return verifiedPayload;\n }\n}\n\nexport const OidcJwtIdentityProvider = JwtIdentityProvider.createImplementation({\n implementation: OidcJwtIdentityProviderImpl,\n dependencies: [[OidcIdentityProvider, { multiple: true }], JwkCache]\n});\n"],"names":["OidcJwtIdentityProviderImpl","oidcIdentityProviders","jwksCache","token","provider","jwt","header","payload","verifiedPayload","providerIdentity","identity","context","undefined","result","jwks","jwk","key","verifyJwtUsingJwk","OidcJwtIdentityProvider","JwtIdentityProvider","OidcIdentityProvider","JwkCache"],"mappings":";;AAIA,MAAMA;IACF,YACYC,qBAAuD,EACvDC,SAA6B,CACvC;aAFUD,qBAAqB,GAArBA;aACAC,SAAS,GAATA;IACT;IAEH,aAAaC,KAAqC,EAAW;QACzD,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAACC,CAAAA,WAAYA,SAAS,YAAY,CAACD;IAC7E;IAEA,MAAM,YAAYA,KAAa,EAAEE,GAA4B,EAAgC;QACzF,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGF;QAE5B,MAAMD,WAAW,IAAI,CAAC,qBAAqB,CAACG;QAE5C,IAAI,CAACH,UACD,OAAO;QAGX,MAAMI,kBAAkB,MAAM,IAAI,CAAC,WAAW,CAACJ,UAAUD,OAAOG;QAEhE,IAAI,CAACE,iBACD,OAAO;QAIX,MAAMC,mBAAmB,MAAML,SAAS,WAAW,CAACI;QAEpD,MAAME,WAAyB;YAC3B,GAAGD,gBAAgB;YACnB,MAAMA,iBAAiB,IAAI,IAAI;QACnC;QAGA,MAAME,UAAUD,SAAS,OAAO,IAAI;YAAE,iBAAiB;YAAM,iBAAiB;QAAO;QACrF,IAAIC,AAA4BC,WAA5BD,QAAQ,eAAe,EACvBA,QAAQ,eAAe,GAAG;QAE9B,IAAIA,AAA4BC,WAA5BD,QAAQ,eAAe,EACvBA,QAAQ,eAAe,GAAG;QAG9BD,SAAS,OAAO,GAAGC;QAEnB,OAAOD;IACX;IAEQ,sBACJH,OAAuC,EACG;QAC1C,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAACH,CAAAA,WAAYA,SAAS,YAAY,CAACG;IAC7E;IAEA,MAAc,YACVH,QAAwC,EACxCD,KAAa,EACbG,MAAqC,EACvC;QAEE,IAAIE;QACJ,IAAI,AAAgC,cAAhC,OAAOJ,SAAS,WAAW,EAAiB;YAE5C,MAAMS,SAAS,MAAMT,SAAS,WAAW,CAACD;YAC1C,IAAIU,QACA,OAAOA;YAEX,OAAO;QACX;QAKA,MAAMC,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACV,SAAS,MAAM;QAGzD,MAAMW,MAAMD,KAAK,IAAI,CAACE,CAAAA,MAAOA,IAAI,GAAG,KAAKV,OAAO,GAAG;QACnD,IAAI,CAACS,KACD,OAAO;QAGX,IAAI,CAACP,
|
|
1
|
+
{"version":3,"file":"idp/OidcJwtIdentityProvider.js","sources":["../../src/idp/OidcJwtIdentityProvider.ts"],"sourcesContent":["import { verifyJwtUsingJwk } from \"~/features/security/utils/verifyJwtUsingJwk.js\";\nimport type { IdentityData } from \"~/features/security/IdentityContext/Identity.js\";\nimport { JwkCache, JwtIdentityProvider, OidcIdentityProvider } from \"./abstractions.js\";\n\nclass OidcJwtIdentityProviderImpl implements JwtIdentityProvider.Interface {\n constructor(\n private oidcIdentityProviders: OidcIdentityProvider.Interface[],\n private jwksCache: JwkCache.Interface\n ) {}\n\n isApplicable(token: JwtIdentityProvider.JwtPayload): boolean {\n return this.oidcIdentityProviders.some(provider => provider.isApplicable(token));\n }\n\n async getIdentity(token: string, jwt: JwtIdentityProvider.Jwt): Promise<IdentityData | null> {\n const { header, payload } = jwt;\n\n const provider = this.getApplicableProvider(payload);\n\n if (!provider) {\n return null;\n }\n\n const verifiedPayload = await this.verifyToken(provider, token, header);\n\n if (!verifiedPayload) {\n return null;\n }\n\n // Call config.getIdentity to get IdentityData\n const providerIdentity = await provider.getIdentity(verifiedPayload);\n\n const identity: IdentityData = {\n ...providerIdentity,\n type: providerIdentity.type ?? \"admin\"\n };\n\n // Handle default values\n const context = identity.context ?? { canAccessTenant: true, defaultTenantId: \"root\" };\n if (context.canAccessTenant === undefined) {\n context.canAccessTenant = true;\n }\n if (context.defaultTenantId === undefined) {\n context.defaultTenantId = \"root\";\n }\n\n identity.context = context;\n\n return identity;\n }\n\n private getApplicableProvider(\n payload: JwtIdentityProvider.JwtPayload\n ): OidcIdentityProvider.Interface | undefined {\n return this.oidcIdentityProviders.find(provider => provider.isApplicable(payload));\n }\n\n private async verifyToken(\n provider: OidcIdentityProvider.Interface,\n token: string,\n header: JwtIdentityProvider.JwtHeader\n ) {\n // If the implementation specifies a custom verification function, use it.\n let verifiedPayload: JwtIdentityProvider.JwtPayload | undefined;\n if (typeof provider.verifyToken === \"function\") {\n // Use custom verification\n const result = await provider.verifyToken(token);\n if (result) {\n return result;\n }\n return null;\n }\n\n // Otherwise, continue with OIDC best practices, using JWKs.\n\n // Fetch JWKs from cache\n const jwks = await this.jwksCache.getKeys(provider.issuer);\n\n // Find matching JWK using header.kid\n const jwk = jwks.find(key => key.kid === header.kid);\n if (!jwk) {\n return null;\n }\n\n if (!verifiedPayload) {\n // Default JWK verification\n // Security: audience/issuer are enforced only when the provider has them configured.\n verifiedPayload = await verifyJwtUsingJwk(token, jwk, {\n issuer: provider.issuer,\n audience: provider.clientId\n });\n }\n\n // Call verifyTokenClaims if provided\n if (provider.verifyTokenClaims) {\n await provider.verifyTokenClaims(verifiedPayload);\n }\n\n return verifiedPayload;\n }\n}\n\nexport const OidcJwtIdentityProvider = JwtIdentityProvider.createImplementation({\n implementation: OidcJwtIdentityProviderImpl,\n dependencies: [[OidcIdentityProvider, { multiple: true }], JwkCache]\n});\n"],"names":["OidcJwtIdentityProviderImpl","oidcIdentityProviders","jwksCache","token","provider","jwt","header","payload","verifiedPayload","providerIdentity","identity","context","undefined","result","jwks","jwk","key","verifyJwtUsingJwk","OidcJwtIdentityProvider","JwtIdentityProvider","OidcIdentityProvider","JwkCache"],"mappings":";;AAIA,MAAMA;IACF,YACYC,qBAAuD,EACvDC,SAA6B,CACvC;aAFUD,qBAAqB,GAArBA;aACAC,SAAS,GAATA;IACT;IAEH,aAAaC,KAAqC,EAAW;QACzD,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAACC,CAAAA,WAAYA,SAAS,YAAY,CAACD;IAC7E;IAEA,MAAM,YAAYA,KAAa,EAAEE,GAA4B,EAAgC;QACzF,MAAM,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGF;QAE5B,MAAMD,WAAW,IAAI,CAAC,qBAAqB,CAACG;QAE5C,IAAI,CAACH,UACD,OAAO;QAGX,MAAMI,kBAAkB,MAAM,IAAI,CAAC,WAAW,CAACJ,UAAUD,OAAOG;QAEhE,IAAI,CAACE,iBACD,OAAO;QAIX,MAAMC,mBAAmB,MAAML,SAAS,WAAW,CAACI;QAEpD,MAAME,WAAyB;YAC3B,GAAGD,gBAAgB;YACnB,MAAMA,iBAAiB,IAAI,IAAI;QACnC;QAGA,MAAME,UAAUD,SAAS,OAAO,IAAI;YAAE,iBAAiB;YAAM,iBAAiB;QAAO;QACrF,IAAIC,AAA4BC,WAA5BD,QAAQ,eAAe,EACvBA,QAAQ,eAAe,GAAG;QAE9B,IAAIA,AAA4BC,WAA5BD,QAAQ,eAAe,EACvBA,QAAQ,eAAe,GAAG;QAG9BD,SAAS,OAAO,GAAGC;QAEnB,OAAOD;IACX;IAEQ,sBACJH,OAAuC,EACG;QAC1C,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAACH,CAAAA,WAAYA,SAAS,YAAY,CAACG;IAC7E;IAEA,MAAc,YACVH,QAAwC,EACxCD,KAAa,EACbG,MAAqC,EACvC;QAEE,IAAIE;QACJ,IAAI,AAAgC,cAAhC,OAAOJ,SAAS,WAAW,EAAiB;YAE5C,MAAMS,SAAS,MAAMT,SAAS,WAAW,CAACD;YAC1C,IAAIU,QACA,OAAOA;YAEX,OAAO;QACX;QAKA,MAAMC,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACV,SAAS,MAAM;QAGzD,MAAMW,MAAMD,KAAK,IAAI,CAACE,CAAAA,MAAOA,IAAI,GAAG,KAAKV,OAAO,GAAG;QACnD,IAAI,CAACS,KACD,OAAO;QAGX,IAAI,CAACP,iBAGDA,kBAAkB,MAAMS,kBAAkBd,OAAOY,KAAK;YAClD,QAAQX,SAAS,MAAM;YACvB,UAAUA,SAAS,QAAQ;QAC/B;QAIJ,IAAIA,SAAS,iBAAiB,EAC1B,MAAMA,SAAS,iBAAiB,CAACI;QAGrC,OAAOA;IACX;AACJ;AAEO,MAAMU,0BAA0BC,oBAAoB,oBAAoB,CAAC;IAC5E,gBAAgBnB;IAChB,cAAc;QAAC;YAACoB;YAAsB;gBAAE,UAAU;YAAK;SAAE;QAAEC;KAAS;AACxE"}
|
|
@@ -13,7 +13,7 @@ export declare class LegacyContext {
|
|
|
13
13
|
addAuthenticator(authenticator: Authenticator.Interface["authenticate"]): void;
|
|
14
14
|
authenticate(token: string): Promise<void>;
|
|
15
15
|
getIdentity(): SecurityIdentity;
|
|
16
|
-
setIdentity(identity: SecurityIdentity): void;
|
|
16
|
+
setIdentity(identity: SecurityIdentity | undefined | null): void;
|
|
17
17
|
getToken(): string | undefined;
|
|
18
18
|
isAuthorizationEnabled(): boolean;
|
|
19
19
|
withoutAuthorization<T = any>(cb: () => Promise<T>): Promise<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy/security/LegacyContext.js","sources":["../../../src/legacy/security/LegacyContext.ts"],"sourcesContent":["import { type Container } from \"@webiny/di\";\nimport type { SecurityIdentity, SecurityPermission } from \"~/types/security.js\";\nimport { AuthenticationContext } from \"~/features/security/authentication/AuthenticationContext/index.js\";\nimport { Authenticator } from \"~/features/security/authentication/Authenticator/index.js\";\nimport { Authorizer } from \"~/features/security/authorization/Authorizer/abstractions.js\";\nimport {\n AuthenticatedIdentity,\n IdentityContext,\n IdentityData\n} from \"~/features/security/IdentityContext/index.js\";\nimport { GetRoleUseCase } from \"~/features/security/roles/GetRole/index.js\";\nimport { ListRolesUseCase } from \"~/features/security/roles/ListRoles/index.js\";\nimport { CreateRoleUseCase } from \"~/features/security/roles/CreateRole/index.js\";\nimport { UpdateRoleUseCase } from \"~/features/security/roles/UpdateRole/index.js\";\nimport { DeleteRoleUseCase } from \"~/features/security/roles/DeleteRole/index.js\";\nimport { GetTeamUseCase } from \"~/features/security/teams/GetTeam/index.js\";\nimport { ListTeamsUseCase } from \"~/features/security/teams/ListTeams/index.js\";\nimport { CreateTeam } from \"~/features/security/teams/CreateTeam/index.js\";\nimport { UpdateTeam } from \"~/features/security/teams/UpdateTeam/index.js\";\nimport { DeleteTeam } from \"~/features/security/teams/DeleteTeam/index.js\";\n\n/**\n * Legacy bridge that implements the old Security interface.\n * As we implement each phase, we'll replace forwarding with delegation.\n */\nexport class LegacyContext {\n constructor(private container: Container) {}\n\n private get identityContext() {\n return this.container.resolve(IdentityContext);\n }\n\n private get authenticationContext() {\n return this.container.resolve(AuthenticationContext);\n }\n\n addAuthenticator(authenticator: Authenticator.Interface[\"authenticate\"]): void {\n this.container.registerFactory(Authenticator, () => {\n return {\n authenticate(token: string): Promise<IdentityData | null> {\n return authenticator(token);\n }\n };\n });\n }\n\n async authenticate(token: string): Promise<void> {\n // Authenticate using new context\n const identity = await this.authenticationContext.authenticate(token);\n\n // Set identity in IdentityContext\n this.identityContext.setIdentity(identity);\n }\n\n getIdentity(): SecurityIdentity {\n const identity = this.identityContext.getIdentity();\n\n // Convert our Identity class to old SecurityIdentity format\n if (identity.isAnonymous()) {\n return undefined as any;\n }\n\n return identity;\n }\n\n setIdentity(identity: SecurityIdentity): void {\n if (!identity) {\n this.identityContext.setIdentity(undefined);\n return;\n }\n\n // Wrap old identity format in AuthenticatedIdentity\n const { id, displayName, type, ...rest } = identity;\n const authenticatedIdentity = new AuthenticatedIdentity({\n id,\n displayName,\n type,\n ...rest\n });\n\n this.identityContext.setIdentity(authenticatedIdentity);\n }\n\n getToken() {\n return this.authenticationContext.getAuthToken();\n }\n\n isAuthorizationEnabled(): boolean {\n return this.identityContext.isAuthorizationEnabled();\n }\n\n withoutAuthorization<T = any>(cb: () => Promise<T>): Promise<T> {\n return this.identityContext.withoutAuthorization(cb);\n }\n\n withIdentity<T = any>(\n identity: SecurityIdentity | undefined,\n cb: () => Promise<T>\n ): Promise<T> {\n if (!identity) {\n return this.identityContext.withIdentity(undefined, cb);\n }\n\n const { id, displayName, type, ...rest } = identity;\n const authenticatedIdentity = new AuthenticatedIdentity({\n id,\n displayName,\n type,\n ...rest\n });\n\n return this.identityContext.withIdentity(authenticatedIdentity, cb);\n }\n\n async getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n permission: string\n ) {\n return this.identityContext.getPermission<TPermission>(permission);\n }\n\n async getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n permission: string\n ) {\n return this.identityContext.getPermissions<TPermission>(permission);\n }\n\n async listPermissions() {\n return this.identityContext.listPermissions();\n }\n\n async hasFullAccess(): Promise<boolean> {\n return this.identityContext.hasFullAccess();\n }\n\n async getRole(params: any) {\n const useCase = this.container.resolve(GetRoleUseCase);\n const result = await useCase.execute(params.where);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async listRoles(params?: any) {\n const useCase = this.container.resolve(ListRolesUseCase);\n const result = await useCase.execute(params);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async createRole(input: any) {\n const useCase = this.container.resolve(CreateRoleUseCase);\n const result = await useCase.execute(input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async updateRole(id: string, input: any) {\n const useCase = this.container.resolve(UpdateRoleUseCase);\n const result = await useCase.execute(id, input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async deleteRole(id: string) {\n const useCase = this.container.resolve(DeleteRoleUseCase);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw result.error;\n }\n }\n\n addAuthorizer(authorizer: any) {\n // @ts-expect-error\n this.container.registerFactory(Authorizer, () => {\n return {\n authorize(): Promise<Permissions[]> {\n return authorizer();\n }\n };\n });\n }\n\n async getTeam(params: any) {\n const useCase = this.container.resolve(GetTeamUseCase);\n const result = await useCase.execute(params.where);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async listTeams(params?: any) {\n const useCase = this.container.resolve(ListTeamsUseCase);\n const result = await useCase.execute(params);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async createTeam(input: any) {\n const useCase = this.container.resolve(CreateTeam);\n const result = await useCase.execute(input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async updateTeam(id: string, input: any) {\n const useCase = this.container.resolve(UpdateTeam);\n const result = await useCase.execute(id, input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async deleteTeam(id: string) {\n const useCase = this.container.resolve(DeleteTeam);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw result.error;\n }\n }\n}\n"],"names":["LegacyContext","container","IdentityContext","AuthenticationContext","authenticator","Authenticator","token","identity","undefined","id","displayName","type","rest","authenticatedIdentity","AuthenticatedIdentity","cb","permission","params","useCase","GetRoleUseCase","result","ListRolesUseCase","input","CreateRoleUseCase","UpdateRoleUseCase","DeleteRoleUseCase","authorizer","Authorizer","GetTeamUseCase","ListTeamsUseCase","CreateTeam","UpdateTeam","DeleteTeam"],"mappings":";;;;;;;;;;;;;;AAyBO,MAAMA;IACT,YAAoBC,SAAoB,CAAE;aAAtBA,SAAS,GAATA;IAAuB;IAE3C,IAAY,kBAAkB;QAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;IAClC;IAEA,IAAY,wBAAwB;QAChC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;IAClC;IAEA,iBAAiBC,aAAsD,EAAQ;QAC3E,IAAI,CAAC,SAAS,CAAC,eAAe,CAACC,eAAe,IACnC;gBACH,cAAaC,KAAa;oBACtB,OAAOF,cAAcE;gBACzB;YACJ;IAER;IAEA,MAAM,aAAaA,KAAa,EAAiB;QAE7C,MAAMC,WAAW,MAAM,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAACD;QAG/D,IAAI,CAAC,eAAe,CAAC,WAAW,CAACC;IACrC;IAEA,cAAgC;QAC5B,MAAMA,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAGjD,IAAIA,SAAS,WAAW,IACpB;QAGJ,OAAOA;IACX;IAEA,YAAYA,QAA0B,EAAQ;QAC1C,IAAI,CAACA,UAAU,YACX,IAAI,CAAC,eAAe,CAAC,WAAW,CAACC;QAKrC,MAAM,EAAEC,EAAE,EAAEC,WAAW,EAAEC,IAAI,EAAE,GAAGC,MAAM,GAAGL;QAC3C,MAAMM,wBAAwB,IAAIC,sBAAsB;YACpDL;YACAC;YACAC;YACA,GAAGC,IAAI;QACX;QAEA,IAAI,CAAC,eAAe,CAAC,WAAW,CAACC;IACrC;IAEA,WAAW;QACP,OAAO,IAAI,CAAC,qBAAqB,CAAC,YAAY;IAClD;IAEA,yBAAkC;QAC9B,OAAO,IAAI,CAAC,eAAe,CAAC,sBAAsB;IACtD;IAEA,qBAA8BE,EAAoB,EAAc;QAC5D,OAA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,CAACI;QAErC,IAAIF,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WAAWX,EAAU,EAAEa,KAAU,EAAE;QACrC,MAAMJ,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACa;QACvC,MAAMX,SAAS,MAAMF,QAAQ,OAAO,CAACT,IAAIa;QAEzC,IAAIF,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WAAWX,EAAU,EAAE;QACzB,MAAMS,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACc;QACvC,MAAMZ,SAAS,MAAMF,QAAQ,OAAO,CAACT;QAErC,IAAIW,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;IAE1B;AACJ"}
|
|
1
|
+
{"version":3,"file":"legacy/security/LegacyContext.js","sources":["../../../src/legacy/security/LegacyContext.ts"],"sourcesContent":["import { type Container } from \"@webiny/di\";\nimport type { SecurityIdentity, SecurityPermission } from \"~/types/security.js\";\nimport { AuthenticationContext } from \"~/features/security/authentication/AuthenticationContext/index.js\";\nimport { Authenticator } from \"~/features/security/authentication/Authenticator/index.js\";\nimport { Authorizer } from \"~/features/security/authorization/Authorizer/abstractions.js\";\nimport {\n AuthenticatedIdentity,\n IdentityContext,\n IdentityData\n} from \"~/features/security/IdentityContext/index.js\";\nimport { GetRoleUseCase } from \"~/features/security/roles/GetRole/index.js\";\nimport { ListRolesUseCase } from \"~/features/security/roles/ListRoles/index.js\";\nimport { CreateRoleUseCase } from \"~/features/security/roles/CreateRole/index.js\";\nimport { UpdateRoleUseCase } from \"~/features/security/roles/UpdateRole/index.js\";\nimport { DeleteRoleUseCase } from \"~/features/security/roles/DeleteRole/index.js\";\nimport { GetTeamUseCase } from \"~/features/security/teams/GetTeam/index.js\";\nimport { ListTeamsUseCase } from \"~/features/security/teams/ListTeams/index.js\";\nimport { CreateTeam } from \"~/features/security/teams/CreateTeam/index.js\";\nimport { UpdateTeam } from \"~/features/security/teams/UpdateTeam/index.js\";\nimport { DeleteTeam } from \"~/features/security/teams/DeleteTeam/index.js\";\n\n/**\n * Legacy bridge that implements the old Security interface.\n * As we implement each phase, we'll replace forwarding with delegation.\n */\nexport class LegacyContext {\n constructor(private container: Container) {}\n\n private get identityContext() {\n return this.container.resolve(IdentityContext);\n }\n\n private get authenticationContext() {\n return this.container.resolve(AuthenticationContext);\n }\n\n addAuthenticator(authenticator: Authenticator.Interface[\"authenticate\"]): void {\n this.container.registerFactory(Authenticator, () => {\n return {\n authenticate(token: string): Promise<IdentityData | null> {\n return authenticator(token);\n }\n };\n });\n }\n\n async authenticate(token: string): Promise<void> {\n // Authenticate using new context\n const identity = await this.authenticationContext.authenticate(token);\n\n // Set identity in IdentityContext\n this.identityContext.setIdentity(identity);\n }\n\n getIdentity(): SecurityIdentity {\n const identity = this.identityContext.getIdentity();\n\n // Convert our Identity class to old SecurityIdentity format\n if (identity.isAnonymous()) {\n return undefined as any;\n }\n\n return identity;\n }\n\n setIdentity(identity: SecurityIdentity | undefined | null): void {\n if (!identity) {\n this.identityContext.setIdentity(undefined);\n return;\n }\n\n // Wrap old identity format in AuthenticatedIdentity\n const { id, displayName, type, ...rest } = identity;\n const authenticatedIdentity = new AuthenticatedIdentity({\n id,\n displayName,\n type,\n ...rest\n });\n\n this.identityContext.setIdentity(authenticatedIdentity);\n }\n\n getToken() {\n return this.authenticationContext.getAuthToken();\n }\n\n isAuthorizationEnabled(): boolean {\n return this.identityContext.isAuthorizationEnabled();\n }\n\n withoutAuthorization<T = any>(cb: () => Promise<T>): Promise<T> {\n return this.identityContext.withoutAuthorization(cb);\n }\n\n withIdentity<T = any>(\n identity: SecurityIdentity | undefined,\n cb: () => Promise<T>\n ): Promise<T> {\n if (!identity) {\n return this.identityContext.withIdentity(undefined, cb);\n }\n\n const { id, displayName, type, ...rest } = identity;\n const authenticatedIdentity = new AuthenticatedIdentity({\n id,\n displayName,\n type,\n ...rest\n });\n\n return this.identityContext.withIdentity(authenticatedIdentity, cb);\n }\n\n async getPermission<TPermission extends SecurityPermission = SecurityPermission>(\n permission: string\n ) {\n return this.identityContext.getPermission<TPermission>(permission);\n }\n\n async getPermissions<TPermission extends SecurityPermission = SecurityPermission>(\n permission: string\n ) {\n return this.identityContext.getPermissions<TPermission>(permission);\n }\n\n async listPermissions() {\n return this.identityContext.listPermissions();\n }\n\n async hasFullAccess(): Promise<boolean> {\n return this.identityContext.hasFullAccess();\n }\n\n async getRole(params: any) {\n const useCase = this.container.resolve(GetRoleUseCase);\n const result = await useCase.execute(params.where);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async listRoles(params?: any) {\n const useCase = this.container.resolve(ListRolesUseCase);\n const result = await useCase.execute(params);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async createRole(input: any) {\n const useCase = this.container.resolve(CreateRoleUseCase);\n const result = await useCase.execute(input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async updateRole(id: string, input: any) {\n const useCase = this.container.resolve(UpdateRoleUseCase);\n const result = await useCase.execute(id, input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async deleteRole(id: string) {\n const useCase = this.container.resolve(DeleteRoleUseCase);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw result.error;\n }\n }\n\n addAuthorizer(authorizer: any) {\n // @ts-expect-error\n this.container.registerFactory(Authorizer, () => {\n return {\n authorize(): Promise<Permissions[]> {\n return authorizer();\n }\n };\n });\n }\n\n async getTeam(params: any) {\n const useCase = this.container.resolve(GetTeamUseCase);\n const result = await useCase.execute(params.where);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async listTeams(params?: any) {\n const useCase = this.container.resolve(ListTeamsUseCase);\n const result = await useCase.execute(params);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async createTeam(input: any) {\n const useCase = this.container.resolve(CreateTeam);\n const result = await useCase.execute(input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async updateTeam(id: string, input: any) {\n const useCase = this.container.resolve(UpdateTeam);\n const result = await useCase.execute(id, input);\n\n if (result.isFail()) {\n throw result.error;\n }\n\n return result.value;\n }\n\n async deleteTeam(id: string) {\n const useCase = this.container.resolve(DeleteTeam);\n const result = await useCase.execute(id);\n\n if (result.isFail()) {\n throw result.error;\n }\n }\n}\n"],"names":["LegacyContext","container","IdentityContext","AuthenticationContext","authenticator","Authenticator","token","identity","undefined","id","displayName","type","rest","authenticatedIdentity","AuthenticatedIdentity","cb","permission","params","useCase","GetRoleUseCase","result","ListRolesUseCase","input","CreateRoleUseCase","UpdateRoleUseCase","DeleteRoleUseCase","authorizer","Authorizer","GetTeamUseCase","ListTeamsUseCase","CreateTeam","UpdateTeam","DeleteTeam"],"mappings":";;;;;;;;;;;;;;AAyBO,MAAMA;IACT,YAAoBC,SAAoB,CAAE;aAAtBA,SAAS,GAATA;IAAuB;IAE3C,IAAY,kBAAkB;QAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;IAClC;IAEA,IAAY,wBAAwB;QAChC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACC;IAClC;IAEA,iBAAiBC,aAAsD,EAAQ;QAC3E,IAAI,CAAC,SAAS,CAAC,eAAe,CAACC,eAAe,IACnC;gBACH,cAAaC,KAAa;oBACtB,OAAOF,cAAcE;gBACzB;YACJ;IAER;IAEA,MAAM,aAAaA,KAAa,EAAiB;QAE7C,MAAMC,WAAW,MAAM,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAACD;QAG/D,IAAI,CAAC,eAAe,CAAC,WAAW,CAACC;IACrC;IAEA,cAAgC;QAC5B,MAAMA,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QAGjD,IAAIA,SAAS,WAAW,IACpB;QAGJ,OAAOA;IACX;IAEA,YAA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MF,QAAQ,OAAO,CAACD,OAAO,KAAK;QAEjD,IAAIG,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,UAAUH,MAAY,EAAE;QAC1B,MAAMC,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACW;QACvC,MAAMT,SAAS,MAAMF,QAAQ,OAAO,CAACD;QAErC,IAAIG,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WAAWE,KAAU,EAAE;QACzB,MAAMJ,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACY;QACvC,MAAMV,SAAS,MAAMF,QAAQ,OAAO,CAACI;QAErC,IAAIF,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WAAWX,EAAU,EAAEa,KAAU,EAAE;QACrC,MAAMJ,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACa;QACvC,MAAMX,SAAS,MAAMF,QAAQ,OAAO,CAACT,IAAIa;QAEzC,IAAIF,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;QAGtB,OAAOA,OAAO,KAAK;IACvB;IAEA,MAAM,WAAWX,EAAU,EAAE;QACzB,MAAMS,UAAU,IAAI,CAAC,SAAS,CAAC,OAAO,CAACc;QACvC,MAAMZ,SAAS,MAAMF,QAAQ,OAAO,CAACT;QAErC,IAAIW,OAAO,MAAM,IACb,MAAMA,OAAO,KAAK;IAE1B;AACJ"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { Request } from "@webiny/handler";
|
|
1
2
|
import type { ApiCoreContext } from "../../../types/core.js";
|
|
3
|
+
/**
|
|
4
|
+
* The `wby-id-token` cookie exists only for private file delivery: an `<img src>` cannot send an
|
|
5
|
+
* `Authorization` header. It must not log users in anywhere else, because the browser attaches it
|
|
6
|
+
* to cross-site requests too (`SameSite=None`), which would let any website call the API as the user.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isCookieAuthenticationAllowed: (request: Pick<Request.Interface, "method" | "url">) => boolean;
|
|
2
9
|
/**
|
|
3
10
|
* @internal
|
|
4
11
|
*/
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { createContextPlugin } from "@webiny/api";
|
|
2
2
|
import { Request, createBeforeHandlerPlugin } from "@webiny/handler";
|
|
3
3
|
import { SetIdTokenCookie } from "../../../features/security/authentication/AuthenticationContext/SetIdTokenCookie.js";
|
|
4
|
+
const isCookieAuthenticationAllowed = (request)=>{
|
|
5
|
+
const method = request.method.toUpperCase();
|
|
6
|
+
if ("GET" !== method && "HEAD" !== method) return false;
|
|
7
|
+
return request.url.startsWith("/private/");
|
|
8
|
+
};
|
|
4
9
|
function authenticateUsingCookie() {
|
|
5
10
|
return [
|
|
6
11
|
createBeforeHandlerPlugin(async (context)=>{
|
|
7
12
|
const request = context.container.resolve(Request);
|
|
13
|
+
if (!isCookieAuthenticationAllowed(request)) return;
|
|
8
14
|
const { cookies } = request;
|
|
9
15
|
const token = cookies["wby-id-token"];
|
|
10
16
|
if (!context.security.getIdentity() && token) try {
|
|
@@ -18,6 +24,6 @@ function authenticateUsingCookie() {
|
|
|
18
24
|
})
|
|
19
25
|
];
|
|
20
26
|
}
|
|
21
|
-
export { authenticateUsingCookie };
|
|
27
|
+
export { authenticateUsingCookie, isCookieAuthenticationAllowed };
|
|
22
28
|
|
|
23
29
|
//# sourceMappingURL=authenticateUsingCookie.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy/security/plugins/authenticateUsingCookie.js","sources":["../../../../src/legacy/security/plugins/authenticateUsingCookie.ts"],"sourcesContent":["import { createContextPlugin } from \"@webiny/api\";\nimport { createBeforeHandlerPlugin, Request } from \"@webiny/handler\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { SetIdTokenCookie } from \"~/features/security/authentication/AuthenticationContext/SetIdTokenCookie.js\";\n\n/**\n * @internal\n */\nexport function authenticateUsingCookie() {\n return [\n createBeforeHandlerPlugin<ApiCoreContext>(async context => {\n const request = context.container.resolve(Request);\n const { cookies } = request;\n const token = cookies[\"wby-id-token\"];\n\n if (!context.security.getIdentity() && token) {\n try {\n await context.security.authenticate(token);\n } catch (err) {\n console.log(err);\n }\n }\n }),\n\n createContextPlugin<ApiCoreContext>(context => {\n context.container.register(SetIdTokenCookie);\n })\n ];\n}\n"],"names":["authenticateUsingCookie","createBeforeHandlerPlugin","context","
|
|
1
|
+
{"version":3,"file":"legacy/security/plugins/authenticateUsingCookie.js","sources":["../../../../src/legacy/security/plugins/authenticateUsingCookie.ts"],"sourcesContent":["import { createContextPlugin } from \"@webiny/api\";\nimport { createBeforeHandlerPlugin, Request } from \"@webiny/handler\";\nimport type { ApiCoreContext } from \"~/types/core.js\";\nimport { SetIdTokenCookie } from \"~/features/security/authentication/AuthenticationContext/SetIdTokenCookie.js\";\n\n/**\n * The `wby-id-token` cookie exists only for private file delivery: an `<img src>` cannot send an\n * `Authorization` header. It must not log users in anywhere else, because the browser attaches it\n * to cross-site requests too (`SameSite=None`), which would let any website call the API as the user.\n */\nexport const isCookieAuthenticationAllowed = (\n request: Pick<Request.Interface, \"method\" | \"url\">\n) => {\n const method = request.method.toUpperCase();\n if (method !== \"GET\" && method !== \"HEAD\") {\n return false;\n }\n return request.url.startsWith(\"/private/\");\n};\n\n/**\n * @internal\n */\nexport function authenticateUsingCookie() {\n return [\n createBeforeHandlerPlugin<ApiCoreContext>(async context => {\n const request = context.container.resolve(Request);\n if (!isCookieAuthenticationAllowed(request)) {\n return;\n }\n const { cookies } = request;\n const token = cookies[\"wby-id-token\"];\n\n if (!context.security.getIdentity() && token) {\n try {\n await context.security.authenticate(token);\n } catch (err) {\n console.log(err);\n }\n }\n }),\n\n createContextPlugin<ApiCoreContext>(context => {\n context.container.register(SetIdTokenCookie);\n })\n ];\n}\n"],"names":["isCookieAuthenticationAllowed","request","method","authenticateUsingCookie","createBeforeHandlerPlugin","context","Request","cookies","token","err","console","createContextPlugin","SetIdTokenCookie"],"mappings":";;;AAUO,MAAMA,gCAAgC,CACzCC;IAEA,MAAMC,SAASD,QAAQ,MAAM,CAAC,WAAW;IACzC,IAAIC,AAAW,UAAXA,UAAoBA,AAAW,WAAXA,QACpB,OAAO;IAEX,OAAOD,QAAQ,GAAG,CAAC,UAAU,CAAC;AAClC;AAKO,SAASE;IACZ,OAAO;QACHC,0BAA0C,OAAMC;YAC5C,MAAMJ,UAAUI,QAAQ,SAAS,CAAC,OAAO,CAACC;YAC1C,IAAI,CAACN,8BAA8BC,UAC/B;YAEJ,MAAM,EAAEM,OAAO,EAAE,GAAGN;YACpB,MAAMO,QAAQD,OAAO,CAAC,eAAe;YAErC,IAAI,CAACF,QAAQ,QAAQ,CAAC,WAAW,MAAMG,OACnC,IAAI;gBACA,MAAMH,QAAQ,QAAQ,CAAC,YAAY,CAACG;YACxC,EAAE,OAAOC,KAAK;gBACVC,QAAQ,GAAG,CAACD;YAChB;QAER;QAEAE,oBAAoCN,CAAAA;YAChCA,QAAQ,SAAS,CAAC,QAAQ,CAACO;QAC/B;KACH;AACL"}
|
|
@@ -12,8 +12,11 @@ const whitelistedHeaders = [
|
|
|
12
12
|
const setupSecureHeaders = ()=>createHandlerOnRequest(async (request, reply)=>{
|
|
13
13
|
const isOptions = "OPTIONS" === request.method;
|
|
14
14
|
const headers = ResponseHeaders.create();
|
|
15
|
-
headers.set("access-control-allow-origin",
|
|
16
|
-
|
|
15
|
+
if (request.url.startsWith("/private/")) headers.set("access-control-allow-origin", "*");
|
|
16
|
+
else {
|
|
17
|
+
headers.set("access-control-allow-origin", request.headers["origin"]);
|
|
18
|
+
headers.set("access-control-allow-credentials", "true");
|
|
19
|
+
}
|
|
17
20
|
if (isOptions) {
|
|
18
21
|
headers.set("cache-control", "public, max-age=86400");
|
|
19
22
|
headers.set("content-type", "application/json; charset=utf-8");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"legacy/security/plugins/secureHeaders.js","sources":["../../../../src/legacy/security/plugins/secureHeaders.ts"],"sourcesContent":["import { createHandlerOnRequest, ResponseHeaders } from \"@webiny/handler\";\n\nconst whitelistedHeaders = [\n \"accept\",\n \"authorization\",\n \"cache-control\",\n \"content-type\",\n \"x-tenant\",\n \"x-apollo-tracing\",\n \"x-webiny-debug\",\n \"apollo-query-plan-experimental\"\n];\n\nexport const setupSecureHeaders = () => {\n return createHandlerOnRequest(async (request, reply) => {\n const isOptions = request.method === \"OPTIONS\";\n\n const headers = ResponseHeaders.create();\n headers.set(\"access-control-allow-origin\", request.headers[\"origin\"]);\n
|
|
1
|
+
{"version":3,"file":"legacy/security/plugins/secureHeaders.js","sources":["../../../../src/legacy/security/plugins/secureHeaders.ts"],"sourcesContent":["import { createHandlerOnRequest, ResponseHeaders } from \"@webiny/handler\";\n\nconst whitelistedHeaders = [\n \"accept\",\n \"authorization\",\n \"cache-control\",\n \"content-type\",\n \"x-tenant\",\n \"x-apollo-tracing\",\n \"x-webiny-debug\",\n \"apollo-query-plan-experimental\"\n];\n\nexport const setupSecureHeaders = () => {\n return createHandlerOnRequest(async (request, reply) => {\n const isOptions = request.method === \"OPTIONS\";\n\n const headers = ResponseHeaders.create();\n /**\n * Private files are authenticated with the `wby-id-token` cookie. Their responses must not\n * be readable by other websites through a credentialed `fetch`, so they get a wildcard origin\n * without credentials. `<img src>`, links and plain `fetch` calls are not affected.\n */\n if (request.url.startsWith(\"/private/\")) {\n headers.set(\"access-control-allow-origin\", \"*\");\n } else {\n headers.set(\"access-control-allow-origin\", request.headers[\"origin\"]);\n headers.set(\"access-control-allow-credentials\", \"true\");\n }\n\n if (isOptions) {\n headers.set(\"cache-control\", \"public, max-age=86400\");\n headers.set(\"content-type\", \"application/json; charset=utf-8\");\n headers.set(\"access-control-max-age\", \"86400\");\n headers.set(\"access-control-allow-methods\", \"OPTIONS,POST,GET,DELETE,PUT,PATCH\");\n headers.set(\"access-control-allow-headers\", whitelistedHeaders.join(\", \"));\n } else {\n headers.set(\"x-tenant\", request.headers[\"x-tenant\"] || \"root\");\n headers.set(\"vary\", \"origin\");\n }\n\n reply.headers(headers.getHeaders());\n });\n};\n"],"names":["whitelistedHeaders","setupSecureHeaders","createHandlerOnRequest","request","reply","isOptions","headers","ResponseHeaders"],"mappings":";AAEA,MAAMA,qBAAqB;IACvB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACH;AAEM,MAAMC,qBAAqB,IACvBC,uBAAuB,OAAOC,SAASC;QAC1C,MAAMC,YAAYF,AAAmB,cAAnBA,QAAQ,MAAM;QAEhC,MAAMG,UAAUC,gBAAgB,MAAM;QAMtC,IAAIJ,QAAQ,GAAG,CAAC,UAAU,CAAC,cACvBG,QAAQ,GAAG,CAAC,+BAA+B;aACxC;YACHA,QAAQ,GAAG,CAAC,+BAA+BH,QAAQ,OAAO,CAAC,SAAS;YACpEG,QAAQ,GAAG,CAAC,oCAAoC;QACpD;QAEA,IAAID,WAAW;YACXC,QAAQ,GAAG,CAAC,iBAAiB;YAC7BA,QAAQ,GAAG,CAAC,gBAAgB;YAC5BA,QAAQ,GAAG,CAAC,0BAA0B;YACtCA,QAAQ,GAAG,CAAC,gCAAgC;YAC5CA,QAAQ,GAAG,CAAC,gCAAgCN,mBAAmB,IAAI,CAAC;QACxE,OAAO;YACHM,QAAQ,GAAG,CAAC,YAAYH,QAAQ,OAAO,CAAC,WAAW,IAAI;YACvDG,QAAQ,GAAG,CAAC,QAAQ;QACxB;QAEAF,MAAM,OAAO,CAACE,QAAQ,UAAU;IACpC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-core",
|
|
3
|
-
"version": "6.5.2-beta.
|
|
3
|
+
"version": "6.5.2-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,39 +14,39 @@
|
|
|
14
14
|
"./*": "./*"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ai-sdk/anthropic": "4.0.
|
|
18
|
-
"@ai-sdk/google": "4.0.
|
|
19
|
-
"@ai-sdk/openai": "4.0.
|
|
17
|
+
"@ai-sdk/anthropic": "4.0.99",
|
|
18
|
+
"@ai-sdk/google": "4.0.114",
|
|
19
|
+
"@ai-sdk/openai": "4.0.111",
|
|
20
20
|
"@openrouter/ai-sdk-provider": "3.1.0",
|
|
21
|
-
"@webiny/api": "6.5.2-beta.
|
|
21
|
+
"@webiny/api": "6.5.2-beta.2",
|
|
22
22
|
"@webiny/di": "1.1.0",
|
|
23
|
-
"@webiny/error": "6.5.2-beta.
|
|
24
|
-
"@webiny/feature": "6.5.2-beta.
|
|
25
|
-
"@webiny/feature-flags": "6.5.2-beta.
|
|
26
|
-
"@webiny/handler": "6.5.2-beta.
|
|
27
|
-
"@webiny/handler-db": "6.5.2-beta.
|
|
28
|
-
"@webiny/handler-graphql": "6.5.2-beta.
|
|
29
|
-
"@webiny/plugins": "6.5.2-beta.
|
|
30
|
-
"@webiny/utils": "6.5.2-beta.
|
|
31
|
-
"@webiny/wcp": "6.5.2-beta.
|
|
32
|
-
"ai": "7.0.
|
|
23
|
+
"@webiny/error": "6.5.2-beta.2",
|
|
24
|
+
"@webiny/feature": "6.5.2-beta.2",
|
|
25
|
+
"@webiny/feature-flags": "6.5.2-beta.2",
|
|
26
|
+
"@webiny/handler": "6.5.2-beta.2",
|
|
27
|
+
"@webiny/handler-db": "6.5.2-beta.2",
|
|
28
|
+
"@webiny/handler-graphql": "6.5.2-beta.2",
|
|
29
|
+
"@webiny/plugins": "6.5.2-beta.2",
|
|
30
|
+
"@webiny/utils": "6.5.2-beta.2",
|
|
31
|
+
"@webiny/wcp": "6.5.2-beta.2",
|
|
32
|
+
"ai": "7.0.166",
|
|
33
33
|
"dataloader": "2.2.3",
|
|
34
|
-
"jose": "6.2.
|
|
34
|
+
"jose": "6.2.16",
|
|
35
35
|
"jsonwebtoken": "9.0.3",
|
|
36
36
|
"lodash": "4.18.1",
|
|
37
|
-
"minimatch": "11.0.
|
|
37
|
+
"minimatch": "11.0.5",
|
|
38
38
|
"pino": "10.4.0",
|
|
39
39
|
"pino-lambda": "4.4.1",
|
|
40
40
|
"zod": "4.6.7"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/jsonwebtoken": "9.0.10",
|
|
44
|
-
"@webiny/build-tools": "6.5.2-beta.
|
|
45
|
-
"@webiny/handler-aws": "6.5.2-beta.
|
|
46
|
-
"@webiny/project-utils": "6.5.2-beta.
|
|
47
|
-
"rimraf": "6.1.
|
|
44
|
+
"@webiny/build-tools": "6.5.2-beta.2",
|
|
45
|
+
"@webiny/handler-aws": "6.5.2-beta.2",
|
|
46
|
+
"@webiny/project-utils": "6.5.2-beta.2",
|
|
47
|
+
"rimraf": "6.1.4",
|
|
48
48
|
"typescript": "7.0.2",
|
|
49
|
-
"vitest": "5.0
|
|
49
|
+
"vitest": "5.1.0"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"access": "public"
|