@3sixty/api-auth-entity-storage-service 0.20.0-next.0 → 0.20.0-next.1
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/README.md +1 -1
- package/dist/es/entities/authenticationUser.js +1 -9
- package/dist/es/entities/authenticationUser.js.map +1 -1
- package/dist/es/entities/authenticationUserV0.js +69 -0
- package/dist/es/entities/authenticationUserV0.js.map +1 -0
- package/dist/es/index.js +1 -9
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/IAuthHeaderProcessorConfig.js.map +1 -1
- package/dist/es/models/IAuthHeaderProcessorConstructorOptions.js.map +1 -1
- package/dist/es/models/IAuthTokenContext.js.map +1 -1
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConfig.js.map +1 -1
- package/dist/es/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.js.map +1 -1
- package/dist/es/models/IEntityStorageAuthenticationServiceConfig.js.map +1 -1
- package/dist/es/models/IEntityStorageAuthenticationServiceConstructorOptions.js.map +1 -1
- package/dist/es/processors/authHeaderProcessor.js +9 -14
- package/dist/es/processors/authHeaderProcessor.js.map +1 -1
- package/dist/es/restEntryPoints.js +1 -8
- package/dist/es/restEntryPoints.js.map +1 -1
- package/dist/es/routes/entityStorageAuthenticationAdminRoutes.js +22 -14
- package/dist/es/routes/entityStorageAuthenticationAdminRoutes.js.map +1 -1
- package/dist/es/routes/entityStorageAuthenticationRoutes.js +45 -1
- package/dist/es/routes/entityStorageAuthenticationRoutes.js.map +1 -1
- package/dist/es/schema.js +2 -4
- package/dist/es/schema.js.map +1 -1
- package/dist/es/services/entityStorageAuthenticationAdminService.js +69 -68
- package/dist/es/services/entityStorageAuthenticationAdminService.js.map +1 -1
- package/dist/es/services/entityStorageAuthenticationService.js +29 -17
- package/dist/es/services/entityStorageAuthenticationService.js.map +1 -1
- package/dist/es/utils/passwordHelper.js +7 -5
- package/dist/es/utils/passwordHelper.js.map +1 -1
- package/dist/es/utils/tokenHelper.js +2 -23
- package/dist/es/utils/tokenHelper.js.map +1 -1
- package/dist/types/entities/authenticationUser.d.ts +0 -4
- package/dist/types/entities/authenticationUserV0.d.ts +33 -0
- package/dist/types/index.d.ts +1 -9
- package/dist/types/models/IAuthHeaderProcessorConfig.d.ts +1 -2
- package/dist/types/models/IAuthTokenContext.d.ts +0 -4
- package/dist/types/models/IEntityStorageAuthenticationAdminServiceConfig.d.ts +14 -3
- package/dist/types/models/IEntityStorageAuthenticationAdminServiceConstructorOptions.d.ts +6 -1
- package/dist/types/models/IEntityStorageAuthenticationServiceConfig.d.ts +7 -2
- package/dist/types/restEntryPoints.d.ts +1 -1
- package/dist/types/routes/entityStorageAuthenticationRoutes.d.ts +10 -2
- package/dist/types/services/entityStorageAuthenticationAdminService.d.ts +6 -2
- package/dist/types/services/entityStorageAuthenticationService.d.ts +6 -1
- package/dist/types/utils/passwordHelper.d.ts +6 -3
- package/dist/types/utils/tokenHelper.d.ts +2 -11
- package/docs/changelog.md +19 -0
- package/docs/examples.md +9 -93
- package/docs/open-api/spec.json +178 -956
- package/docs/reference/classes/AuthHeaderProcessor.md +4 -0
- package/docs/reference/classes/AuthenticationUser.md +0 -8
- package/docs/reference/classes/AuthenticationUserV0.md +69 -0
- package/docs/reference/classes/EntityStorageAuthenticationAdminService.md +11 -3
- package/docs/reference/classes/EntityStorageAuthenticationService.md +18 -0
- package/docs/reference/classes/PasswordHelper.md +4 -4
- package/docs/reference/classes/TokenHelper.md +2 -44
- package/docs/reference/functions/authenticationPasswordPolicy.md +31 -0
- package/docs/reference/index.md +2 -15
- package/docs/reference/interfaces/IAuthHeaderProcessorConfig.md +1 -2
- package/docs/reference/interfaces/IAuthTokenContext.md +0 -8
- package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConfig.md +38 -4
- package/docs/reference/interfaces/IEntityStorageAuthenticationAdminServiceConstructorOptions.md +15 -1
- package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConfig.md +15 -1
- package/docs/reference/variables/restEntryPoints.md +1 -1
- package/locales/en.json +1 -16
- package/package.json +7 -8
- package/dist/es/entities/authenticationAuditEntry.js +0 -121
- package/dist/es/entities/authenticationAuditEntry.js.map +0 -1
- package/dist/es/entities/authenticationRateEntry.js +0 -37
- package/dist/es/entities/authenticationRateEntry.js.map +0 -1
- package/dist/es/models/IEntityStorageAuthenticationAuditServiceConfig.js +0 -4
- package/dist/es/models/IEntityStorageAuthenticationAuditServiceConfig.js.map +0 -1
- package/dist/es/models/IEntityStorageAuthenticationAuditServiceConstructorOptions.js +0 -2
- package/dist/es/models/IEntityStorageAuthenticationAuditServiceConstructorOptions.js.map +0 -1
- package/dist/es/models/IEntityStorageAuthenticationRateServiceConfig.js +0 -2
- package/dist/es/models/IEntityStorageAuthenticationRateServiceConfig.js.map +0 -1
- package/dist/es/models/IEntityStorageAuthenticationRateServiceConstructorOptions.js +0 -2
- package/dist/es/models/IEntityStorageAuthenticationRateServiceConstructorOptions.js.map +0 -1
- package/dist/es/routes/entityStorageAuthenticationAuditRoutes.js +0 -343
- package/dist/es/routes/entityStorageAuthenticationAuditRoutes.js.map +0 -1
- package/dist/es/services/entityStorageAuthenticationAuditService.js +0 -240
- package/dist/es/services/entityStorageAuthenticationAuditService.js.map +0 -1
- package/dist/es/services/entityStorageAuthenticationRateService.js +0 -213
- package/dist/es/services/entityStorageAuthenticationRateService.js.map +0 -1
- package/dist/types/entities/authenticationAuditEntry.d.ts +0 -49
- package/dist/types/entities/authenticationRateEntry.d.ts +0 -17
- package/dist/types/models/IEntityStorageAuthenticationAuditServiceConfig.d.ts +0 -9
- package/dist/types/models/IEntityStorageAuthenticationAuditServiceConstructorOptions.d.ts +0 -15
- package/dist/types/models/IEntityStorageAuthenticationRateServiceConfig.d.ts +0 -10
- package/dist/types/models/IEntityStorageAuthenticationRateServiceConstructorOptions.d.ts +0 -25
- package/dist/types/routes/entityStorageAuthenticationAuditRoutes.d.ts +0 -54
- package/dist/types/services/entityStorageAuthenticationAuditService.d.ts +0 -72
- package/dist/types/services/entityStorageAuthenticationRateService.d.ts +0 -60
- package/docs/reference/classes/AuthenticationAuditEntry.md +0 -101
- package/docs/reference/classes/AuthenticationRateEntry.md +0 -37
- package/docs/reference/classes/EntityStorageAuthenticationAuditService.md +0 -241
- package/docs/reference/classes/EntityStorageAuthenticationRateService.md +0 -227
- package/docs/reference/functions/authenticationAuditCreate.md +0 -37
- package/docs/reference/functions/authenticationAuditGet.md +0 -31
- package/docs/reference/functions/authenticationAuditQuery.md +0 -31
- package/docs/reference/functions/authenticationAuditRemove.md +0 -31
- package/docs/reference/functions/authenticationAuditUpdate.md +0 -31
- package/docs/reference/functions/generateRestRoutesAuthenticationAudit.md +0 -25
- package/docs/reference/interfaces/IEntityStorageAuthenticationAuditServiceConfig.md +0 -11
- package/docs/reference/interfaces/IEntityStorageAuthenticationAuditServiceConstructorOptions.md +0 -25
- package/docs/reference/interfaces/IEntityStorageAuthenticationRateServiceConfig.md +0 -17
- package/docs/reference/interfaces/IEntityStorageAuthenticationRateServiceConstructorOptions.md +0 -53
- package/docs/reference/variables/tagsAuthenticationAudit.md +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityStorageAuthenticationAdminRoutes.js","sourceRoot":"","sources":["../../../src/routes/entityStorageAuthenticationAdminRoutes.ts"],"names":[],"mappings":"AAYA,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EAOb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EAAE,cAAc,EAAqB,MAAM,aAAa,CAAC;AAEhE;;GAEG;AACH,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAW;IAC9C;QACC,IAAI,EAAE,sBAAsB;QAC5B,WAAW,EAAE,qDAAqD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AAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAE7D,OAAO;QACN,IAAI,EAAE,MAAM;KACZ,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oCAAoC,CACzD,kBAAuC,EACvC,aAAqB,EACrB,OAAuC;IAEvC,MAAM,CAAC,MAAM,CAAiC,aAAa,aAAmB,OAAO,CAAC,CAAC;IACvF,MAAM,CAAC,MAAM,CACZ,aAAa,wBAEb,OAAO,CAAC,UAAU,CAClB,CAAC;IAEF,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAgC,aAAa,CAAC,CAAC;IACrF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAE1E,OAAO;QACN,IAAI,EAAE,MAAM;KACZ,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CAClD,kBAAuC,EACvC,aAAqB,EACrB,OAAgC;IAEhC,MAAM,CAAC,MAAM,CAA0B,aAAa,aAAmB,OAAO,CAAC,CAAC;IAChF,MAAM,CAAC,MAAM,CACZ,aAAa,wBAEb,OAAO,CAAC,UAAU,CAClB,CAAC;IAEF,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAgC,aAAa,CAAC,CAAC;IACrF,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAEjD,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,SAAS;KACpC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAdminUserCreateRequest,\n\tIAdminUserGetByIdentityRequest,\n\tIAdminUserGetRequest,\n\tIAdminUserGetResponse,\n\tIAdminUserRemoveRequest,\n\tIAdminUserUpdatePasswordRequest,\n\tIAdminUserUpdateRequest,\n\tIAuthenticationAdminComponent\n} from \"@3sixty/api-auth-entity-storage-models\";\nimport {\n\tHttpContextIdKeys,\n\tHttpHeaderHelper,\n\tHttpUrlHelper,\n\ttype ICreatedResponse,\n\ttype IHttpRequestContext,\n\ttype INoContentResponse,\n\ttype IRestRoute,\n\ttype ITag,\n\ttype IUnauthorizedResponse\n} from \"@3sixty/api-models\";\nimport { ContextIdStore } from \"@3sixty/context\";\nimport { ComponentFactory, Guards } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport { HttpStatusCode, type IHttpHeaders } from \"@3sixty/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"authenticationAdminRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsAuthenticationAdmin: ITag[] = [\n\t{\n\t\tname: \"Authentication Admin\",\n\t\tdescription: \"Authentication Admin endpoints for the REST server.\"\n\t}\n];\n\n/**\n * The REST routes for authentication admin.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesAuthenticationAdmin(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createUserRoute: IRestRoute<IAdminUserCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"authenticationAdminCreateUser\",\n\t\tsummary: \"Create a new user\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/users`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminCreateUser(httpRequestContext, componentName, request, baseRouteName),\n\t\trequestType: {\n\t\t\ttype: nameof<IAdminUserCreateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"createUserRequestExample\",\n\t\t\t\t\tdescription: \"The request to create a new user.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\temail: \"user@example.com\",\n\t\t\t\t\t\t\tpassword: \"MyPassword123!\",\n\t\t\t\t\t\t\tuserIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\torganizationIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\tscope: [\"scope1\", \"scope2\"]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst updateUserRoute: IRestRoute<IAdminUserUpdateRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationAdminUpdateUser\",\n\t\tsummary: \"Update an existing user\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/users/:email`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminUpdateUser(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAdminUserUpdateRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"updateUserRequestExample\",\n\t\t\t\t\tdescription: \"The request to update an existing user.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\temail: \"user@example.com\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tuserIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\torganizationIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\tscope: [\"scope1\", \"scope2\"]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst updateUserPasswordRoute: IRestRoute<IAdminUserUpdatePasswordRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationAdminUpdateUserPassword\",\n\t\tsummary: \"Update an existing user password\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/users/:email/password`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminUpdateUserPassword(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAdminUserUpdatePasswordRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"updateUserPasswordRequestExample\",\n\t\t\t\t\tdescription: \"The request to update an existing user password.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\temail: \"user@example.com\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tnewPassword: \"MyNewPassword123!\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst getUserRoute: IRestRoute<IAdminUserGetRequest, IAdminUserGetResponse> = {\n\t\toperationId: \"authenticationAdminGetUser\",\n\t\tsummary: \"Get existing user\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/users/:email`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminGetUser(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAdminUserGetRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"getUserRequestExample\",\n\t\t\t\t\tdescription: \"The request to get an existing user.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\temail: \"user@example.com\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IAdminUserGetResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"getUserResponseExample\",\n\t\t\t\t\t\tdescription: \"The response to get an existing user.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\temail: \"user@example.com\",\n\t\t\t\t\t\t\t\tuserIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\t\torganizationIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\t\tscope: [\"scope1\", \"scope2\"]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\tconst getByIdentityUserRoute: IRestRoute<IAdminUserGetByIdentityRequest, IAdminUserGetResponse> =\n\t\t{\n\t\t\toperationId: \"authenticationAdminGetByIdentityUser\",\n\t\t\tsummary: \"Get existing user by identity\",\n\t\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\t\tmethod: \"GET\",\n\t\t\tpath: `${baseRouteName}/users/identity/:identity`,\n\t\t\thandler: async (httpRequestContext, request) =>\n\t\t\t\tauthenticationAdminGetUserByIdentity(httpRequestContext, componentName, request),\n\t\t\trequestType: {\n\t\t\t\ttype: nameof<IAdminUserGetByIdentityRequest>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"getUserByIdentityRequestExample\",\n\t\t\t\t\t\tdescription: \"The request to get an existing user by identity.\",\n\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\t\tidentity: \"did:example:123456789abcdefghi\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\tresponseType: [\n\t\t\t\t{\n\t\t\t\t\ttype: nameof<IAdminUserGetResponse>(),\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"getUserResponseExample\",\n\t\t\t\t\t\t\tdescription: \"The response to get an existing user.\",\n\t\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\temail: \"user@example.com\",\n\t\t\t\t\t\t\t\t\tuserIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\t\t\torganizationIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\t\t\tscope: [\"scope1\", \"scope2\"]\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t\t}\n\t\t\t],\n\t\t\trequiredScope: [\"user-admin\"]\n\t\t};\n\n\tconst removeUserRoute: IRestRoute<IAdminUserRemoveRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationAdminRemoveUser\",\n\t\tsummary: \"Remove existing user\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/users/:email`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminRemoveUser(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IAdminUserRemoveRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"removeUserRequestExample\",\n\t\t\t\t\tdescription: \"The request to remove an existing user.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\temail: \"user@example.com\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\trequiredScope: [\"user-admin\"]\n\t};\n\n\treturn [\n\t\tcreateUserRoute,\n\t\tupdateUserRoute,\n\t\tupdateUserPasswordRoute,\n\t\tgetUserRoute,\n\t\tgetByIdentityUserRoute,\n\t\tremoveUserRoute\n\t];\n}\n\n/**\n * Create a new user.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @param baseRouteName The base route name to use for the location header.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAdminCreateUser(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserCreateRequest,\n\tbaseRouteName: string\n): Promise<ICreatedResponse> {\n\tGuards.object<IAdminUserCreateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAdminUserCreateRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tawait component.create(request.body);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\n\tconst headers: IHttpHeaders = {};\n\tHttpHeaderHelper.buildId(\n\t\theaders,\n\t\trequest.body.email,\n\t\tHttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/users/:id`)\n\t);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders\n\t};\n}\n\n/**\n * Update an existing user.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAdminUpdateUser(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserUpdateRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IAdminUserUpdateRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAdminUserUpdateRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.object<IAdminUserUpdateRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tawait component.update({\n\t\t...request.body,\n\t\temail: request.pathParams.email\n\t});\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Update an existing user password.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAdminUpdateUserPassword(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserUpdatePasswordRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IAdminUserUpdatePasswordRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAdminUserUpdatePasswordRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.object<IAdminUserUpdatePasswordRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tawait component.updatePassword(request.pathParams.email, request.body.newPassword);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Get an existing user.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAdminGetUser(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserGetRequest\n): Promise<IAdminUserGetResponse> {\n\tGuards.object<IAdminUserGetRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAdminUserGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tconst result = await component.get(request.pathParams.email);\n\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Get an existing user by identity.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAdminGetUserByIdentity(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserGetByIdentityRequest\n): Promise<IAdminUserGetResponse> {\n\tGuards.object<IAdminUserGetByIdentityRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAdminUserGetByIdentityRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tconst result = await component.getByIdentity(request.pathParams.identity);\n\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Remove an existing user.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAdminRemoveUser(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IAdminUserRemoveRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IAdminUserRemoveRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tawait component.remove(request.pathParams.email);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"entityStorageAuthenticationAdminRoutes.js","sources":["../../../src/routes/entityStorageAuthenticationAdminRoutes.ts"],"names":[],"mappings":"AAYA,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EAQb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EAAE,cAAc,EAAqB,MAAM,aAAa,CAAC;AAEhE;;GAEG;AACH,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAElD;;GAEG;AACH,MAAM,4BAA4B,GAAwB;IACzD,UAAU,EAAE,iBAAiB;IAC7B,IAAI,EAAE,YAAY;CAClB,CAAC;AACF,MAAM,4BAA4B,GAAwB;IACzD,UAAU,EAAE,kBAAkB;IAC9B,IAAI,EAAE,YAAY;IAClB,QAAQ,EAAE,CAAC,4BAA4B,CAAC,UAAU,CAAC;CACnD,CAAC;AACF;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAW;IAC9C;QACC,IAAI,EAAE,sBAAsB;QAC5B,WAAW,EAAE,qDAAqD;KAClE;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,qCAAqC,CACpD,aAAqB,EACrB,aAAqB;IAErB,MAAM,eAAe,GAA0D;QAC9E,WAAW,EAAE,+BAA+B;QAC5C,OAAO,EAAE,mBAAmB;QAC5B,GAAG,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC,IAAI;QACpC,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,GAAG,aAAa,QAAQ;QAC9B,OAAO,EAAE,KAAK,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CAClB,CAAC;IAEF,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAgC,aAAa,CAAC,CAAC;IACrF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAE1E,OAAO;QACN,IAAI,EAAE,MAAM;KACZ,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CAClD,kBAAuC,EACvC,aAAqB,EACrB,OAAgC;IAEhC,MAAM,CAAC,MAAM,CAA0B,aAAa,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IAC1E,MAAM,CAAC,MAAM,CACZ,aAAa,EACb,oBAAoB,EACpB,OAAO,CAAC,UAAU,CAClB,CAAC;IAEF,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAgC,aAAa,CAAC,CAAC;IACrF,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAEjD,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,SAAS;KACpC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAdminUserCreateRequest,\n\tIAdminUserGetByIdentityRequest,\n\tIAdminUserGetRequest,\n\tIAdminUserGetResponse,\n\tIAdminUserRemoveRequest,\n\tIAdminUserUpdatePasswordRequest,\n\tIAdminUserUpdateRequest,\n\tIAuthenticationAdminComponent\n} from \"@3sixty/api-auth-entity-storage-models\";\nimport {\n\tHttpContextIdKeys,\n\tHttpHeaderHelper,\n\tHttpUrlHelper,\n\ttype ICreatedResponse,\n\ttype IHttpRequestContext,\n\ttype INoContentResponse,\n\ttype IRestRoute,\n\ttype IRouteAuthorization,\n\ttype ITag,\n\ttype IUnauthorizedResponse\n} from \"@3sixty/api-models\";\nimport { ContextIdStore } from \"@3sixty/context\";\nimport { ComponentFactory, Guards } from \"@3sixty/core\";\n\nimport { HttpStatusCode, type IHttpHeaders } from \"@3sixty/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"authenticationAdminRoutes\";\n\n/**\n * The default authorization for the routes, used to seed authorization rules.\n */\nconst DEFAULT_AUTHORIZATION_READER: IRouteAuthorization = {\n\tpermission: \"user-admin:read\",\n\trole: \"user-admin\"\n};\nconst DEFAULT_AUTHORIZATION_WRITER: IRouteAuthorization = {\n\tpermission: \"user-admin:write\",\n\trole: \"user-admin\",\n\tinherits: [DEFAULT_AUTHORIZATION_READER.permission]\n};\n/**\n * The tag to associate with the routes.\n */\nexport const tagsAuthenticationAdmin: ITag[] = [\n\t{\n\t\tname: \"Authentication Admin\",\n\t\tdescription: \"Authentication Admin endpoints for the REST server.\"\n\t}\n];\n\n/**\n * The REST routes for authentication admin.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesAuthenticationAdmin(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createUserRoute: IRestRoute<IAdminUserCreateRequest, ICreatedResponse> = {\n\t\toperationId: \"authenticationAdminCreateUser\",\n\t\tsummary: \"Create a new user\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/users`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminCreateUser(httpRequestContext, componentName, request, baseRouteName),\n\t\trequestType: {\n\t\t\ttype: \"IAdminUserCreateRequest\",\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"createUserRequestExample\",\n\t\t\t\t\tdescription: \"The request to create a new user.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\temail: \"user@example.com\",\n\t\t\t\t\t\t\tpassword: \"MyPassword123!\",\n\t\t\t\t\t\t\tuserIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\torganizationIdentity: \"did:example:123456789abcdefghi\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: \"INoContentResponse\"\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: \"IUnauthorizedResponse\"\n\t\t\t}\n\t\t],\n\t\tdefaultAuthorization: DEFAULT_AUTHORIZATION_WRITER\n\t};\n\n\tconst updateUserRoute: IRestRoute<IAdminUserUpdateRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationAdminUpdateUser\",\n\t\tsummary: \"Update an existing user\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/users/:email`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminUpdateUser(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: \"IAdminUserUpdateRequest\",\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"updateUserRequestExample\",\n\t\t\t\t\tdescription: \"The request to update an existing user.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\temail: \"user@example.com\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tuserIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\torganizationIdentity: \"did:example:123456789abcdefghi\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: \"INoContentResponse\"\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: \"IUnauthorizedResponse\"\n\t\t\t}\n\t\t],\n\t\tdefaultAuthorization: DEFAULT_AUTHORIZATION_WRITER\n\t};\n\n\tconst updateUserPasswordRoute: IRestRoute<IAdminUserUpdatePasswordRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationAdminUpdateUserPassword\",\n\t\tsummary: \"Update an existing user password\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/users/:email/password`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminUpdateUserPassword(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: \"IAdminUserUpdatePasswordRequest\",\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"updateUserPasswordRequestExample\",\n\t\t\t\t\tdescription: \"The request to update an existing user password.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\temail: \"user@example.com\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tnewPassword: \"MyNewPassword123!\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: \"INoContentResponse\"\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: \"IUnauthorizedResponse\"\n\t\t\t}\n\t\t],\n\t\tdefaultAuthorization: DEFAULT_AUTHORIZATION_WRITER\n\t};\n\n\tconst getUserRoute: IRestRoute<IAdminUserGetRequest, IAdminUserGetResponse> = {\n\t\toperationId: \"authenticationAdminGetUser\",\n\t\tsummary: \"Get existing user\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/users/:email`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminGetUser(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: \"IAdminUserGetRequest\",\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"getUserRequestExample\",\n\t\t\t\t\tdescription: \"The request to get an existing user.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\temail: \"user@example.com\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: \"IAdminUserGetResponse\",\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"getUserResponseExample\",\n\t\t\t\t\t\tdescription: \"The response to get an existing user.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\temail: \"user@example.com\",\n\t\t\t\t\t\t\t\tuserIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\t\torganizationIdentity: \"did:example:123456789abcdefghi\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: \"IUnauthorizedResponse\"\n\t\t\t}\n\t\t],\n\t\tdefaultAuthorization: DEFAULT_AUTHORIZATION_READER\n\t};\n\n\tconst getByIdentityUserRoute: IRestRoute<IAdminUserGetByIdentityRequest, IAdminUserGetResponse> =\n\t\t{\n\t\t\toperationId: \"authenticationAdminGetByIdentityUser\",\n\t\t\tsummary: \"Get existing user by identity\",\n\t\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\t\tmethod: \"GET\",\n\t\t\tpath: `${baseRouteName}/users/identity/:identity`,\n\t\t\thandler: async (httpRequestContext, request) =>\n\t\t\t\tauthenticationAdminGetUserByIdentity(httpRequestContext, componentName, request),\n\t\t\trequestType: {\n\t\t\t\ttype: \"IAdminUserGetByIdentityRequest\",\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"getUserByIdentityRequestExample\",\n\t\t\t\t\t\tdescription: \"The request to get an existing user by identity.\",\n\t\t\t\t\t\trequest: {\n\t\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\t\tidentity: \"did:example:123456789abcdefghi\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\tresponseType: [\n\t\t\t\t{\n\t\t\t\t\ttype: \"IAdminUserGetResponse\",\n\t\t\t\t\texamples: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tid: \"getUserResponseExample\",\n\t\t\t\t\t\t\tdescription: \"The response to get an existing user.\",\n\t\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\t\temail: \"user@example.com\",\n\t\t\t\t\t\t\t\t\tuserIdentity: \"did:example:123456789abcdefghi\",\n\t\t\t\t\t\t\t\t\torganizationIdentity: \"did:example:123456789abcdefghi\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: \"IUnauthorizedResponse\"\n\t\t\t\t}\n\t\t\t],\n\t\t\tdefaultAuthorization: DEFAULT_AUTHORIZATION_READER\n\t\t};\n\n\tconst removeUserRoute: IRestRoute<IAdminUserRemoveRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationAdminRemoveUser\",\n\t\tsummary: \"Remove existing user\",\n\t\ttag: tagsAuthenticationAdmin[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/users/:email`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationAdminRemoveUser(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: \"IAdminUserRemoveRequest\",\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"removeUserRequestExample\",\n\t\t\t\t\tdescription: \"The request to remove an existing user.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\temail: \"user@example.com\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: \"INoContentResponse\"\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: \"IUnauthorizedResponse\"\n\t\t\t}\n\t\t],\n\t\tdefaultAuthorization: DEFAULT_AUTHORIZATION_WRITER\n\t};\n\n\treturn [\n\t\tcreateUserRoute,\n\t\tupdateUserRoute,\n\t\tupdateUserPasswordRoute,\n\t\tgetUserRoute,\n\t\tgetByIdentityUserRoute,\n\t\tremoveUserRoute\n\t];\n}\n\n/**\n * Create a new user.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @param baseRouteName The base route name to use for the location header.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAdminCreateUser(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserCreateRequest,\n\tbaseRouteName: string\n): Promise<ICreatedResponse> {\n\tGuards.object<IAdminUserCreateRequest>(ROUTES_SOURCE, \"request\", request);\n\tGuards.object<IAdminUserCreateRequest[\"body\"]>(ROUTES_SOURCE, \"request.body\", request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tawait component.create(request.body);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\n\tconst headers: IHttpHeaders = {};\n\tHttpHeaderHelper.buildId(\n\t\theaders,\n\t\trequest.body.email,\n\t\tHttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/users/:id`)\n\t);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders\n\t};\n}\n\n/**\n * Update an existing user.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAdminUpdateUser(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserUpdateRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IAdminUserUpdateRequest>(ROUTES_SOURCE, \"request\", request);\n\tGuards.object<IAdminUserUpdateRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\t\"request.pathParams\",\n\t\trequest.pathParams\n\t);\n\tGuards.object<IAdminUserUpdateRequest[\"body\"]>(ROUTES_SOURCE, \"request.body\", request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tawait component.update({\n\t\t...request.body,\n\t\temail: request.pathParams.email\n\t});\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Update an existing user password.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAdminUpdateUserPassword(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserUpdatePasswordRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IAdminUserUpdatePasswordRequest>(ROUTES_SOURCE, \"request\", request);\n\tGuards.object<IAdminUserUpdatePasswordRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\t\"request.pathParams\",\n\t\trequest.pathParams\n\t);\n\tGuards.object<IAdminUserUpdatePasswordRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\t\"request.body\",\n\t\trequest.body\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tawait component.updatePassword(request.pathParams.email, request.body.newPassword);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Get an existing user.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAdminGetUser(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserGetRequest\n): Promise<IAdminUserGetResponse> {\n\tGuards.object<IAdminUserGetRequest>(ROUTES_SOURCE, \"request\", request);\n\tGuards.object<IAdminUserGetRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\t\"request.pathParams\",\n\t\trequest.pathParams\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tconst result = await component.get(request.pathParams.email);\n\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Get an existing user by identity.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAdminGetUserByIdentity(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserGetByIdentityRequest\n): Promise<IAdminUserGetResponse> {\n\tGuards.object<IAdminUserGetByIdentityRequest>(ROUTES_SOURCE, \"request\", request);\n\tGuards.object<IAdminUserGetByIdentityRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\t\"request.pathParams\",\n\t\trequest.pathParams\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tconst result = await component.getByIdentity(request.pathParams.identity);\n\n\treturn {\n\t\tbody: result\n\t};\n}\n\n/**\n * Remove an existing user.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationAdminRemoveUser(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IAdminUserRemoveRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IAdminUserRemoveRequest>(ROUTES_SOURCE, \"request\", request);\n\tGuards.object<IAdminUserRemoveRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\t\"request.pathParams\",\n\t\trequest.pathParams\n\t);\n\n\tconst component = ComponentFactory.get<IAuthenticationAdminComponent>(componentName);\n\tawait component.remove(request.pathParams.email);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n"]}
|
|
@@ -162,7 +162,37 @@ export function generateRestRoutesAuthentication(baseRouteName, componentName) {
|
|
|
162
162
|
}
|
|
163
163
|
]
|
|
164
164
|
};
|
|
165
|
-
|
|
165
|
+
const passwordPolicyRoute = {
|
|
166
|
+
operationId: "authenticationPasswordPolicy",
|
|
167
|
+
summary: "Get the password policy",
|
|
168
|
+
tag: tagsAuthentication[0].name,
|
|
169
|
+
method: "GET",
|
|
170
|
+
path: `${baseRouteName}/policy`,
|
|
171
|
+
handler: async (httpRequestContext, request) => authenticationPasswordPolicy(httpRequestContext, componentName, request),
|
|
172
|
+
requestType: {
|
|
173
|
+
type: "INoContentRequest"
|
|
174
|
+
},
|
|
175
|
+
responseType: [
|
|
176
|
+
{
|
|
177
|
+
type: "IPasswordPolicyResponse",
|
|
178
|
+
examples: [
|
|
179
|
+
{
|
|
180
|
+
id: "passwordPolicyResponseExample",
|
|
181
|
+
description: "The response for the password policy request.",
|
|
182
|
+
response: {
|
|
183
|
+
body: {
|
|
184
|
+
minPasswordLength: 15,
|
|
185
|
+
maxPasswordLength: 128
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
skipAuth: true,
|
|
193
|
+
skipTenant: true
|
|
194
|
+
};
|
|
195
|
+
return [loginRoute, logoutRoute, refreshTokenRoute, updatePasswordRoute, passwordPolicyRoute];
|
|
166
196
|
}
|
|
167
197
|
/**
|
|
168
198
|
* Login to the server.
|
|
@@ -244,4 +274,18 @@ export async function authenticationUpdatePassword(httpRequestContext, component
|
|
|
244
274
|
statusCode: HttpStatusCode.noContent
|
|
245
275
|
};
|
|
246
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Get the password policy.
|
|
279
|
+
* @param httpRequestContext The request context for the API.
|
|
280
|
+
* @param componentName The name of the component to use in the routes.
|
|
281
|
+
* @param request The request.
|
|
282
|
+
* @returns The response object with additional http response properties.
|
|
283
|
+
*/
|
|
284
|
+
export async function authenticationPasswordPolicy(httpRequestContext, componentName, request) {
|
|
285
|
+
const component = ComponentFactory.get(componentName);
|
|
286
|
+
const result = await component.passwordPolicy();
|
|
287
|
+
return {
|
|
288
|
+
body: result
|
|
289
|
+
};
|
|
290
|
+
}
|
|
247
291
|
//# sourceMappingURL=entityStorageAuthenticationRoutes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entityStorageAuthenticationRoutes.js","sourceRoot":"","sources":["../../../src/routes/entityStorageAuthenticationRoutes.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AACH,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAW;IACzC;QACC,IAAI,EAAE,gBAAgB;QACtB,WAAW,EAAE,+CAA+C;KAC5D;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC/C,aAAqB,EACrB,aAAqB;IAErB,MAAM,UAAU,GAA8C;QAC7D,WAAW,EAAE,qBAAqB;QAClC,OAAO,EAAE,qBAAqB;QAC9B,GAAG,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,IAAI;QAC/B,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,GAAG,aAAa,QAAQ;QAC9B,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,EAAE,CAC9C,mBAAmB,CAAC,kBAAkB,EAAE,aAAa,EAAE,OAAO,CAAC;QAChE,WAAW,EAAE;YACZ,IAAI,iBAAyB;YAC7B,QAAQ,EAAE;gBACT;oBACC,EAAE,EAAE,qBAAqB;oBACzB,WAAW,EAAE,qCAAqC;oBAClD,OAAO,EAAE;wBACR,IAAI,EAAE;4BACL,KAAK,EAAE,kBAAkB;4BACzB,QAAQ,EAAE,gBAAgB;yBAC1B;qBAC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B;IAE7B,MAAM,CAAC,MAAM,CAAuB,aAAa,aAAmB,OAAO,CAAC,CAAC;IAE7E,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAA2B,aAAa,CAAC,CAAC;IAEhF,iFAAiF;IACjF,uCAAuC;IACvC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,EAAE,KAAK,IAAK,kBAAkB,CAAC,cAAc,CAAC,SAAoB,CAAC;IAC7F,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE9C,iEAAiE;IACjE,+CAA+C;IAC/C,kBAAkB,CAAC,cAAc,CAAC,aAAa,GAAG,SAAS,CAAC;IAC5D,kBAAkB,CAAC,cAAc,CAAC,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC;IAE3D,OAAO;QACN,IAAI,EAAE;YACL,MAAM,EAAE,MAAM,CAAC,MAAM;SACrB;KACD,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CACjD,kBAAuC,EACvC,aAAqB,EACrB,OAA+B;IAE/B,MAAM,CAAC,MAAM,CAAyB,aAAa,aAAmB,OAAO,CAAC,CAAC;IAC/E,MAAM,CAAC,MAAM,CAAiC,aAAa,kBAAwB,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjG,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAA2B,aAAa,CAAC,CAAC;IAEhF,MAAM,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAEvF,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,SAAS;KACpC,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAuthenticationComponent,\n\tILoginRequest,\n\tILoginResponse,\n\tILogoutRequest,\n\tIRefreshTokenRequest,\n\tIRefreshTokenResponse,\n\tIUpdatePasswordRequest\n} from \"@3sixty/api-auth-entity-storage-models\";\nimport type {\n\tIHttpRequestContext,\n\tINoContentResponse,\n\tIRestRoute,\n\tIRestRouteResponseOptions,\n\tITag,\n\tIUnauthorizedResponse\n} from \"@3sixty/api-models\";\nimport { ComponentFactory, Guards } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport { HttpStatusCode } from \"@3sixty/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"authenticationRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsAuthentication: ITag[] = [\n\t{\n\t\tname: \"Authentication\",\n\t\tdescription: \"Authentication endpoints for the REST server.\"\n\t}\n];\n\n/**\n * The REST routes for authentication.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesAuthentication(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst loginRoute: IRestRoute<ILoginRequest, ILoginResponse> = {\n\t\toperationId: \"authenticationLogin\",\n\t\tsummary: \"Login to the server\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/login`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationLogin(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ILoginRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"loginRequestExample\",\n\t\t\t\t\tdescription: \"The request to login to the server.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\temail: \"user@example.com\",\n\t\t\t\t\t\t\tpassword: \"MyPassword123!\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ILoginResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"loginResponseExample\",\n\t\t\t\t\t\tdescription: \"The response for the login request.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\texpiry: 1722514341067\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t],\n\t\tskipAuth: true\n\t};\n\n\tconst logoutRoute: IRestRoute<ILogoutRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationLogout\",\n\t\tsummary: \"Logout from the server\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/logout`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationLogout(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ILogoutRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"logoutRequestExample\",\n\t\t\t\t\tdescription: \"The request to logout from the server.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\ttoken: \"eyJhbGciOiJIU...sw5c\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst refreshTokenRoute: IRestRoute<IRefreshTokenRequest, IRefreshTokenResponse> = {\n\t\toperationId: \"authenticationRefreshToken\",\n\t\tsummary: \"Refresh an authentication token\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/refresh`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationRefreshToken(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IRefreshTokenRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"refreshTokenRequestExample\",\n\t\t\t\t\tdescription: \"The request to refresh an auth token.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\ttoken: \"eyJhbGciOiJIU...sw5c\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<IRefreshTokenResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"refreshTokenResponseExample\",\n\t\t\t\t\t\tdescription: \"The response for the refresh token request.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\texpiry: 1722514341067\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst updatePasswordRoute: IRestRoute<IUpdatePasswordRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationUpdatePassword\",\n\t\tsummary: \"Update the current user's password\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/password`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationUpdatePassword(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<IUpdatePasswordRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"updatePasswordRequestExample\",\n\t\t\t\t\tdescription: \"The request to update the current user's password.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tcurrentPassword: \"MyNewPassword123!\",\n\t\t\t\t\t\t\tnewPassword: \"MyNewPassword123!\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: nameof<IUnauthorizedResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [loginRoute, logoutRoute, refreshTokenRoute, updatePasswordRoute];\n}\n\n/**\n * Login to the server.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationLogin(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ILoginRequest\n): Promise<ILoginResponse & IRestRouteResponseOptions> {\n\tGuards.object<ILoginRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ILoginRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\tconst result = await component.login(request.body.email, request.body.password);\n\n\t// Need to give a hint to any auth processors about the operation\n\t// in case they need to manipulate the response\n\thttpRequestContext.processorState.authOperation = \"login\";\n\thttpRequestContext.processorState.authToken = result.token;\n\n\treturn {\n\t\tbody: {\n\t\t\texpiry: result.expiry\n\t\t}\n\t};\n}\n\n/**\n * Logout from the server.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationLogout(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ILogoutRequest\n): Promise<INoContentResponse & IRestRouteResponseOptions> {\n\tGuards.object<ILogoutRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\tawait component.logout(request.body?.token);\n\n\t// Need to give a hint to any auth processors about the operation\n\t// in case they need to manipulate the response\n\thttpRequestContext.processorState.authOperation = \"logout\";\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Refresh the login token.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationRefreshToken(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IRefreshTokenRequest\n): Promise<IRefreshTokenResponse & IRestRouteResponseOptions> {\n\tGuards.object<IRefreshTokenRequest>(ROUTES_SOURCE, nameof(request), request);\n\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\n\t// If the token is not in the body, then maybe an auth processor has extracted it\n\t// and stored it in the processor state\n\tconst token = request.body?.token ?? (httpRequestContext.processorState.authToken as string);\n\tconst result = await component.refresh(token);\n\n\t// Need to give a hint to any auth processors about the operation\n\t// in case they need to manipulate the response\n\thttpRequestContext.processorState.authOperation = \"refresh\";\n\thttpRequestContext.processorState.authToken = result.token;\n\n\treturn {\n\t\tbody: {\n\t\t\texpiry: result.expiry\n\t\t}\n\t};\n}\n\n/**\n * Update the user's password.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationUpdatePassword(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IUpdatePasswordRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IUpdatePasswordRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<IUpdatePasswordRequest[\"body\"]>(ROUTES_SOURCE, nameof(request.body), request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\n\tawait component.updatePassword(request.body.currentPassword, request.body.newPassword);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"entityStorageAuthenticationRoutes.js","sources":["../../../src/routes/entityStorageAuthenticationRoutes.ts"],"names":[],"mappings":"AAqBA,OAAO,EA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AAC;IACzE,MAAM,CAAC,MAAM,CAAiC,aAAa,EAAE,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3F,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAA2B,aAAa,CAAC,CAAC;IAEhF,MAAM,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAEvF,OAAO;QACN,UAAU,EAAE,cAAc,CAAC,SAAS;KACpC,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CACjD,kBAAuC,EACvC,aAAqB,EACrB,OAA0B;IAE1B,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAA2B,aAAa,CAAC,CAAC;IAChF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,cAAc,EAAE,CAAC;IAEhD,OAAO;QACN,IAAI,EAAE,MAAM;KACZ,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAuthenticationComponent,\n\tILoginRequest,\n\tILoginResponse,\n\tILogoutRequest,\n\tIPasswordPolicyResponse,\n\tIRefreshTokenRequest,\n\tIRefreshTokenResponse,\n\tIUpdatePasswordRequest\n} from \"@3sixty/api-auth-entity-storage-models\";\nimport type {\n\tIHttpRequestContext,\n\tINoContentRequest,\n\tINoContentResponse,\n\tIRestRoute,\n\tIRestRouteResponseOptions,\n\tITag,\n\tIUnauthorizedResponse\n} from \"@3sixty/api-models\";\nimport { ComponentFactory, Guards } from \"@3sixty/core\";\n\nimport { HttpStatusCode } from \"@3sixty/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"authenticationRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsAuthentication: ITag[] = [\n\t{\n\t\tname: \"Authentication\",\n\t\tdescription: \"Authentication endpoints for the REST server.\"\n\t}\n];\n\n/**\n * The REST routes for authentication.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesAuthentication(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst loginRoute: IRestRoute<ILoginRequest, ILoginResponse> = {\n\t\toperationId: \"authenticationLogin\",\n\t\tsummary: \"Login to the server\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/login`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationLogin(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: \"ILoginRequest\",\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"loginRequestExample\",\n\t\t\t\t\tdescription: \"The request to login to the server.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\temail: \"user@example.com\",\n\t\t\t\t\t\t\tpassword: \"MyPassword123!\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: \"ILoginResponse\",\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"loginResponseExample\",\n\t\t\t\t\t\tdescription: \"The response for the login request.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\texpiry: 1722514341067\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: \"IUnauthorizedResponse\"\n\t\t\t}\n\t\t],\n\t\tskipAuth: true\n\t};\n\n\tconst logoutRoute: IRestRoute<ILogoutRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationLogout\",\n\t\tsummary: \"Logout from the server\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/logout`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationLogout(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: \"ILogoutRequest\",\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"logoutRequestExample\",\n\t\t\t\t\tdescription: \"The request to logout from the server.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\ttoken: \"eyJhbGciOiJIU...sw5c\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: \"INoContentResponse\"\n\t\t\t}\n\t\t]\n\t};\n\n\tconst refreshTokenRoute: IRestRoute<IRefreshTokenRequest, IRefreshTokenResponse> = {\n\t\toperationId: \"authenticationRefreshToken\",\n\t\tsummary: \"Refresh an authentication token\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/refresh`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationRefreshToken(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: \"IRefreshTokenRequest\",\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"refreshTokenRequestExample\",\n\t\t\t\t\tdescription: \"The request to refresh an auth token.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\ttoken: \"eyJhbGciOiJIU...sw5c\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: \"IRefreshTokenResponse\",\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"refreshTokenResponseExample\",\n\t\t\t\t\t\tdescription: \"The response for the refresh token request.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\texpiry: 1722514341067\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: \"IUnauthorizedResponse\"\n\t\t\t}\n\t\t]\n\t};\n\n\tconst updatePasswordRoute: IRestRoute<IUpdatePasswordRequest, INoContentResponse> = {\n\t\toperationId: \"authenticationUpdatePassword\",\n\t\tsummary: \"Update the current user's password\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/password`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationUpdatePassword(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: \"IUpdatePasswordRequest\",\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"updatePasswordRequestExample\",\n\t\t\t\t\tdescription: \"The request to update the current user's password.\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tcurrentPassword: \"MyNewPassword123!\",\n\t\t\t\t\t\t\tnewPassword: \"MyNewPassword123!\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: \"INoContentResponse\"\n\t\t\t},\n\t\t\t{\n\t\t\t\ttype: \"IUnauthorizedResponse\"\n\t\t\t}\n\t\t]\n\t};\n\n\tconst passwordPolicyRoute: IRestRoute<INoContentRequest, IPasswordPolicyResponse> = {\n\t\toperationId: \"authenticationPasswordPolicy\",\n\t\tsummary: \"Get the password policy\",\n\t\ttag: tagsAuthentication[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/policy`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\tauthenticationPasswordPolicy(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: \"INoContentRequest\"\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: \"IPasswordPolicyResponse\",\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"passwordPolicyResponseExample\",\n\t\t\t\t\t\tdescription: \"The response for the password policy request.\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tminPasswordLength: 15,\n\t\t\t\t\t\t\t\tmaxPasswordLength: 128\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t],\n\t\tskipAuth: true,\n\t\tskipTenant: true\n\t};\n\n\treturn [loginRoute, logoutRoute, refreshTokenRoute, updatePasswordRoute, passwordPolicyRoute];\n}\n\n/**\n * Login to the server.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationLogin(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ILoginRequest\n): Promise<ILoginResponse & IRestRouteResponseOptions> {\n\tGuards.object<ILoginRequest>(ROUTES_SOURCE, \"request\", request);\n\tGuards.object<ILoginRequest[\"body\"]>(ROUTES_SOURCE, \"request.body\", request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\tconst result = await component.login(request.body.email, request.body.password);\n\n\t// Need to give a hint to any auth processors about the operation\n\t// in case they need to manipulate the response\n\thttpRequestContext.processorState.authOperation = \"login\";\n\thttpRequestContext.processorState.authToken = result.token;\n\n\treturn {\n\t\tbody: {\n\t\t\texpiry: result.expiry\n\t\t}\n\t};\n}\n\n/**\n * Logout from the server.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationLogout(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ILogoutRequest\n): Promise<INoContentResponse & IRestRouteResponseOptions> {\n\tGuards.object<ILogoutRequest>(ROUTES_SOURCE, \"request\", request);\n\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\tawait component.logout(request.body?.token);\n\n\t// Need to give a hint to any auth processors about the operation\n\t// in case they need to manipulate the response\n\thttpRequestContext.processorState.authOperation = \"logout\";\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Refresh the login token.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationRefreshToken(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IRefreshTokenRequest\n): Promise<IRefreshTokenResponse & IRestRouteResponseOptions> {\n\tGuards.object<IRefreshTokenRequest>(ROUTES_SOURCE, \"request\", request);\n\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\n\t// If the token is not in the body, then maybe an auth processor has extracted it\n\t// and stored it in the processor state\n\tconst token = request.body?.token ?? (httpRequestContext.processorState.authToken as string);\n\tconst result = await component.refresh(token);\n\n\t// Need to give a hint to any auth processors about the operation\n\t// in case they need to manipulate the response\n\thttpRequestContext.processorState.authOperation = \"refresh\";\n\thttpRequestContext.processorState.authToken = result.token;\n\n\treturn {\n\t\tbody: {\n\t\t\texpiry: result.expiry\n\t\t}\n\t};\n}\n\n/**\n * Update the user's password.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationUpdatePassword(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: IUpdatePasswordRequest\n): Promise<INoContentResponse> {\n\tGuards.object<IUpdatePasswordRequest>(ROUTES_SOURCE, \"request\", request);\n\tGuards.object<IUpdatePasswordRequest[\"body\"]>(ROUTES_SOURCE, \"request.body\", request.body);\n\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\n\tawait component.updatePassword(request.body.currentPassword, request.body.newPassword);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Get the password policy.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function authenticationPasswordPolicy(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: INoContentRequest\n): Promise<IPasswordPolicyResponse & IRestRouteResponseOptions> {\n\tconst component = ComponentFactory.get<IAuthenticationComponent>(componentName);\n\tconst result = await component.passwordPolicy();\n\n\treturn {\n\t\tbody: result\n\t};\n}\n"]}
|
package/dist/es/schema.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
// Copyright 2024 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
3
|
import { EntitySchemaFactory, EntitySchemaHelper } from "@3sixty/entity";
|
|
4
|
-
import { AuthenticationAuditEntry } from "./entities/authenticationAuditEntry.js";
|
|
5
|
-
import { AuthenticationRateEntry } from "./entities/authenticationRateEntry.js";
|
|
6
4
|
import { AuthenticationUser } from "./entities/authenticationUser.js";
|
|
5
|
+
import { AuthenticationUserV0 } from "./entities/authenticationUserV0.js";
|
|
7
6
|
/**
|
|
8
7
|
* Initialize the schema for the authentication service.
|
|
9
8
|
*/
|
|
10
9
|
export function initSchema() {
|
|
11
10
|
EntitySchemaFactory.register("AuthenticationUser", () => EntitySchemaHelper.getSchema(AuthenticationUser));
|
|
12
|
-
EntitySchemaFactory.register("
|
|
13
|
-
EntitySchemaFactory.register("AuthenticationRateEntry", () => EntitySchemaHelper.getSchema(AuthenticationRateEntry));
|
|
11
|
+
EntitySchemaFactory.register("AuthenticationUserV0", () => EntitySchemaHelper.getSchema(AuthenticationUserV0));
|
|
14
12
|
}
|
|
15
13
|
//# sourceMappingURL=schema.js.map
|
package/dist/es/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","
|
|
1
|
+
{"version":3,"file":"schema.js","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E;;GAEG;AACH,MAAM,UAAU,UAAU;IACzB,mBAAmB,CAAC,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE,CACvD,kBAAkB,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAChD,CAAC;IACF,mBAAmB,CAAC,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE,CACzD,kBAAkB,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAClD,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { EntitySchemaFactory, EntitySchemaHelper } from \"@3sixty/entity\";\n\nimport { AuthenticationUser } from \"./entities/authenticationUser.js\";\nimport { AuthenticationUserV0 } from \"./entities/authenticationUserV0.js\";\n\n/**\n * Initialize the schema for the authentication service.\n */\nexport function initSchema(): void {\n\tEntitySchemaFactory.register(\"AuthenticationUser\", () =>\n\t\tEntitySchemaHelper.getSchema(AuthenticationUser)\n\t);\n\tEntitySchemaFactory.register(\"AuthenticationUserV0\", () =>\n\t\tEntitySchemaHelper.getSchema(AuthenticationUserV0)\n\t);\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthAuditEvent } from "@3sixty/api-auth-
|
|
2
|
-
import { ForbiddenError, HttpContextIdKeys
|
|
1
|
+
import { AuthAuditEvent } from "@3sixty/api-auth-models";
|
|
2
|
+
import { ForbiddenError, HttpContextIdKeys } from "@3sixty/api-models";
|
|
3
3
|
import { ContextIdKeys, ContextIdStore } from "@3sixty/context";
|
|
4
4
|
import { BaseError, ComponentFactory, Converter, GeneralError, Guards, Is, NotFoundError, RandomHelper } from "@3sixty/core";
|
|
5
5
|
import { PasswordGenerator, PasswordValidator } from "@3sixty/crypto";
|
|
@@ -14,29 +14,48 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
14
14
|
*/
|
|
15
15
|
static CLASS_NAME = "EntityStorageAuthenticationAdminService";
|
|
16
16
|
/**
|
|
17
|
-
* The
|
|
17
|
+
* The default role that grants escalated privilege.
|
|
18
18
|
*/
|
|
19
|
-
static
|
|
19
|
+
static DEFAULT_ESCALATED_PRIVILEGE_ROLE = "global-admin";
|
|
20
|
+
/**
|
|
21
|
+
* The default authorization model ID used to look up roles.
|
|
22
|
+
*/
|
|
23
|
+
static DEFAULT_AUTHORIZATION_MODEL_ID = "system";
|
|
20
24
|
/**
|
|
21
25
|
* The entity storage for users.
|
|
22
26
|
* @internal
|
|
23
27
|
*/
|
|
24
28
|
_userEntityStorage;
|
|
25
29
|
/**
|
|
26
|
-
* The audit
|
|
30
|
+
* The audit component.
|
|
27
31
|
* @internal
|
|
28
32
|
*/
|
|
29
33
|
_authenticationAuditService;
|
|
34
|
+
/**
|
|
35
|
+
* The authorization component used to guard accounts with escalated privilege.
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
_authorizationComponent;
|
|
39
|
+
/**
|
|
40
|
+
* The role that grants escalated privilege.
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
_escalatedPrivilegeRole;
|
|
44
|
+
/**
|
|
45
|
+
* The authorization model ID used to look up roles.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
_authorizationModelId;
|
|
30
49
|
/**
|
|
31
50
|
* The minimum password length.
|
|
32
51
|
* @internal
|
|
33
52
|
*/
|
|
34
53
|
_minPasswordLength;
|
|
35
54
|
/**
|
|
36
|
-
* The
|
|
55
|
+
* The maximum password length.
|
|
37
56
|
* @internal
|
|
38
57
|
*/
|
|
39
|
-
|
|
58
|
+
_maxPasswordLength;
|
|
40
59
|
/**
|
|
41
60
|
* Create a new instance of EntityStorageAuthentication.
|
|
42
61
|
* @param options The dependencies for the identity connector.
|
|
@@ -44,10 +63,15 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
44
63
|
constructor(options) {
|
|
45
64
|
this._userEntityStorage = EntityStorageConnectorFactory.get(options?.userEntityStorageType ?? "authentication-user");
|
|
46
65
|
this._authenticationAuditService = ComponentFactory.getIfExists(options?.authenticationAuditServiceType ?? "authentication-audit");
|
|
66
|
+
this._authorizationComponent = ComponentFactory.getIfExists(options?.authorizationComponentType ?? "authorization");
|
|
47
67
|
this._minPasswordLength = options?.config?.minPasswordLength;
|
|
48
|
-
this.
|
|
49
|
-
|
|
50
|
-
|
|
68
|
+
this._maxPasswordLength = options?.config?.maxPasswordLength;
|
|
69
|
+
this._escalatedPrivilegeRole =
|
|
70
|
+
options?.config?.escalatedPrivilegeRole ??
|
|
71
|
+
EntityStorageAuthenticationAdminService.DEFAULT_ESCALATED_PRIVILEGE_ROLE;
|
|
72
|
+
this._authorizationModelId =
|
|
73
|
+
options?.config?.authorizationModelId ??
|
|
74
|
+
EntityStorageAuthenticationAdminService.DEFAULT_AUTHORIZATION_MODEL_ID;
|
|
51
75
|
}
|
|
52
76
|
/**
|
|
53
77
|
* Returns the class name of the component.
|
|
@@ -67,16 +91,17 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
67
91
|
Guards.stringValue(EntityStorageAuthenticationAdminService.CLASS_NAME, "user.password", user.password);
|
|
68
92
|
Guards.stringValue(EntityStorageAuthenticationAdminService.CLASS_NAME, "user.userIdentity", user.userIdentity);
|
|
69
93
|
Guards.stringValue(EntityStorageAuthenticationAdminService.CLASS_NAME, "user.organizationIdentity", user.organizationIdentity);
|
|
70
|
-
Guards.array(EntityStorageAuthenticationAdminService.CLASS_NAME, "user.scope", user.scope);
|
|
71
|
-
await this.guardEscalatedPrivilegeScopeAssignment(user.scope);
|
|
72
94
|
try {
|
|
73
95
|
PasswordValidator.validatePassword(user.password, {
|
|
74
|
-
minLength: this._minPasswordLength
|
|
96
|
+
minLength: this._minPasswordLength,
|
|
97
|
+
maxLength: this._maxPasswordLength
|
|
75
98
|
});
|
|
76
99
|
const existingUser = await this._userEntityStorage.get(user.email);
|
|
77
100
|
if (Is.object(existingUser)) {
|
|
78
101
|
throw new GeneralError(EntityStorageAuthenticationAdminService.CLASS_NAME, "userExists");
|
|
79
102
|
}
|
|
103
|
+
// Roles belong to the identity, so a login mapped to an escalated identity inherits them.
|
|
104
|
+
await this.guardEscalatedPrivilegeTarget(user.userIdentity);
|
|
80
105
|
const saltBytes = RandomHelper.generate(16);
|
|
81
106
|
const passwordBytes = Converter.utf8ToBytes(user.password);
|
|
82
107
|
const hashedPassword = await PasswordGenerator.hashPassword(passwordBytes, saltBytes);
|
|
@@ -86,7 +111,6 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
86
111
|
password: hashedPassword,
|
|
87
112
|
identity: user.userIdentity,
|
|
88
113
|
organization: user.organizationIdentity,
|
|
89
|
-
scope: ScopeHelper.toString(user.scope),
|
|
90
114
|
passwordVersion: 0
|
|
91
115
|
};
|
|
92
116
|
await this._userEntityStorage.set(newUser);
|
|
@@ -100,12 +124,14 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
100
124
|
userIdentity: user.userIdentity,
|
|
101
125
|
organizationIdentity: user.organizationIdentity,
|
|
102
126
|
tenantId: requestorTenantId,
|
|
103
|
-
originalTenantId
|
|
104
|
-
scope: user.scope
|
|
127
|
+
originalTenantId
|
|
105
128
|
}
|
|
106
129
|
});
|
|
107
130
|
}
|
|
108
131
|
catch (error) {
|
|
132
|
+
if (BaseError.isErrorName(error, ForbiddenError.CLASS_NAME)) {
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
109
135
|
throw new GeneralError(EntityStorageAuthenticationAdminService.CLASS_NAME, "createUserFailed", undefined, error);
|
|
110
136
|
}
|
|
111
137
|
}
|
|
@@ -123,20 +149,16 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
123
149
|
if (!Is.empty(user.organizationIdentity)) {
|
|
124
150
|
Guards.stringValue(EntityStorageAuthenticationAdminService.CLASS_NAME, "user.organizationIdentity", user.organizationIdentity);
|
|
125
151
|
}
|
|
126
|
-
if (!Is.empty(user.scope)) {
|
|
127
|
-
Guards.array(EntityStorageAuthenticationAdminService.CLASS_NAME, "user.scope", user.scope);
|
|
128
|
-
await this.guardEscalatedPrivilegeScopeAssignment(user.scope);
|
|
129
|
-
}
|
|
130
152
|
try {
|
|
131
153
|
const existingUser = await this._userEntityStorage.get(user.email);
|
|
132
154
|
if (!Is.object(existingUser)) {
|
|
133
155
|
throw new NotFoundError(EntityStorageAuthenticationAdminService.CLASS_NAME, "userNotFound", user.email);
|
|
134
156
|
}
|
|
135
|
-
await this.guardEscalatedPrivilegeTarget(existingUser.
|
|
157
|
+
await this.guardEscalatedPrivilegeTarget(existingUser.identity);
|
|
158
|
+
if (Is.stringValue(user.userIdentity) && user.userIdentity !== existingUser.identity) {
|
|
159
|
+
await this.guardEscalatedPrivilegeTarget(user.userIdentity);
|
|
160
|
+
}
|
|
136
161
|
const updatedFields = [];
|
|
137
|
-
const updatedScope = Is.array(user.scope)
|
|
138
|
-
? ScopeHelper.toString(user.scope)
|
|
139
|
-
: existingUser.scope;
|
|
140
162
|
if (user.userIdentity !== undefined && user.userIdentity !== existingUser.identity) {
|
|
141
163
|
updatedFields.push("userIdentity");
|
|
142
164
|
}
|
|
@@ -144,12 +166,8 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
144
166
|
user.organizationIdentity !== existingUser.organization) {
|
|
145
167
|
updatedFields.push("organizationIdentity");
|
|
146
168
|
}
|
|
147
|
-
if (Is.array(user.scope) && updatedScope !== existingUser.scope) {
|
|
148
|
-
updatedFields.push("scope");
|
|
149
|
-
}
|
|
150
169
|
existingUser.identity = user.userIdentity ?? existingUser.identity;
|
|
151
170
|
existingUser.organization = user.organizationIdentity ?? existingUser.organization;
|
|
152
|
-
existingUser.scope = Is.array(user.scope) ? updatedScope : existingUser.scope;
|
|
153
171
|
await this._userEntityStorage.set(existingUser);
|
|
154
172
|
const contextIds = await ContextIdStore.getContextIds();
|
|
155
173
|
const requestorTenantId = contextIds?.[ContextIdKeys.Tenant];
|
|
@@ -162,8 +180,7 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
162
180
|
userIdentity: existingUser.identity,
|
|
163
181
|
organizationIdentity: existingUser.organization,
|
|
164
182
|
tenantId: requestorTenantId,
|
|
165
|
-
originalTenantId
|
|
166
|
-
scope: ScopeHelper.toArray(existingUser.scope)
|
|
183
|
+
originalTenantId
|
|
167
184
|
}
|
|
168
185
|
});
|
|
169
186
|
}
|
|
@@ -189,8 +206,7 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
189
206
|
return {
|
|
190
207
|
email: user.email,
|
|
191
208
|
userIdentity: user.identity,
|
|
192
|
-
organizationIdentity: user.organization
|
|
193
|
-
scope: ScopeHelper.toArray(user.scope)
|
|
209
|
+
organizationIdentity: user.organization
|
|
194
210
|
};
|
|
195
211
|
}
|
|
196
212
|
catch (error) {
|
|
@@ -212,8 +228,7 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
212
228
|
return {
|
|
213
229
|
email: user.email,
|
|
214
230
|
userIdentity: user.identity,
|
|
215
|
-
organizationIdentity: user.organization
|
|
216
|
-
scope: ScopeHelper.toArray(user.scope)
|
|
231
|
+
organizationIdentity: user.organization
|
|
217
232
|
};
|
|
218
233
|
}
|
|
219
234
|
catch (error) {
|
|
@@ -232,7 +247,7 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
232
247
|
if (!Is.object(user)) {
|
|
233
248
|
throw new NotFoundError(EntityStorageAuthenticationAdminService.CLASS_NAME, "userNotFound", email);
|
|
234
249
|
}
|
|
235
|
-
await this.guardEscalatedPrivilegeTarget(user.
|
|
250
|
+
await this.guardEscalatedPrivilegeTarget(user.identity);
|
|
236
251
|
await this._userEntityStorage.remove(email);
|
|
237
252
|
const contextIds = await ContextIdStore.getContextIds();
|
|
238
253
|
const requestorTenantId = contextIds?.[ContextIdKeys.Tenant];
|
|
@@ -244,8 +259,7 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
244
259
|
userIdentity: user.identity,
|
|
245
260
|
organizationIdentity: user.organization,
|
|
246
261
|
tenantId: requestorTenantId,
|
|
247
|
-
originalTenantId
|
|
248
|
-
scope: ScopeHelper.toArray(user.scope)
|
|
262
|
+
originalTenantId
|
|
249
263
|
}
|
|
250
264
|
});
|
|
251
265
|
}
|
|
@@ -271,8 +285,11 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
271
285
|
if (!Is.object(user)) {
|
|
272
286
|
throw new NotFoundError(EntityStorageAuthenticationAdminService.CLASS_NAME, "userNotFound", email);
|
|
273
287
|
}
|
|
274
|
-
await this.guardEscalatedPrivilegeTarget(user.
|
|
275
|
-
await PasswordHelper.updatePassword(this._userEntityStorage, this._authenticationAuditService, user, newPassword, currentPassword,
|
|
288
|
+
await this.guardEscalatedPrivilegeTarget(user.identity);
|
|
289
|
+
await PasswordHelper.updatePassword(this._userEntityStorage, this._authenticationAuditService, user, newPassword, currentPassword, {
|
|
290
|
+
minPasswordLength: this._minPasswordLength,
|
|
291
|
+
maxPasswordLength: this._maxPasswordLength
|
|
292
|
+
});
|
|
276
293
|
}
|
|
277
294
|
catch (error) {
|
|
278
295
|
if (BaseError.isErrorName(error, ForbiddenError.CLASS_NAME)) {
|
|
@@ -282,42 +299,26 @@ export class EntityStorageAuthenticationAdminService {
|
|
|
282
299
|
}
|
|
283
300
|
}
|
|
284
301
|
/**
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
* @
|
|
302
|
+
* Ensure the caller holds escalated privilege when the target identity holds it.
|
|
303
|
+
* @param targetIdentity The identity of the account being modified.
|
|
304
|
+
* @throws ForbiddenError if the target holds escalated privilege and the caller does not.
|
|
288
305
|
* @internal
|
|
289
306
|
*/
|
|
290
|
-
async
|
|
291
|
-
if (
|
|
307
|
+
async guardEscalatedPrivilegeTarget(targetIdentity) {
|
|
308
|
+
if (Is.empty(this._authorizationComponent)) {
|
|
292
309
|
return;
|
|
293
310
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Throws ForbiddenError when the account being written to already holds the escalated privilege
|
|
300
|
-
* scope but the calling request does not hold that scope itself. Without this an admin with a
|
|
301
|
-
* lesser scope could reset the password of, remove, or demote a privileged account.
|
|
302
|
-
* @param targetScope The scopes currently held by the account being written to.
|
|
303
|
-
* @internal
|
|
304
|
-
*/
|
|
305
|
-
async guardEscalatedPrivilegeTarget(targetScope) {
|
|
306
|
-
if (!ScopeHelper.includes(targetScope, this._escalatedPrivilegeScope)) {
|
|
311
|
+
const targetIsEscalated = await this._authorizationComponent.hasRoleForSubject(this._authorizationModelId, targetIdentity, this._escalatedPrivilegeRole);
|
|
312
|
+
if (!targetIsEscalated) {
|
|
307
313
|
return;
|
|
308
314
|
}
|
|
309
|
-
if (!(await this.callerHasEscalatedPrivilege())) {
|
|
310
|
-
throw new ForbiddenError(EntityStorageAuthenticationAdminService.CLASS_NAME, "insufficientScopeForEscalatedTarget", { scopeName: this._escalatedPrivilegeScope });
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Does the calling request hold the escalated privilege scope.
|
|
315
|
-
* @returns True when the caller holds the escalated privilege scope.
|
|
316
|
-
* @internal
|
|
317
|
-
*/
|
|
318
|
-
async callerHasEscalatedPrivilege() {
|
|
319
315
|
const contextIds = await ContextIdStore.getContextIds();
|
|
320
|
-
|
|
316
|
+
const callerIdentity = contextIds?.[ContextIdKeys.User];
|
|
317
|
+
const callerIsEscalated = Is.stringValue(callerIdentity) &&
|
|
318
|
+
(await this._authorizationComponent.hasRoleForSubject(this._authorizationModelId, callerIdentity, this._escalatedPrivilegeRole));
|
|
319
|
+
if (!callerIsEscalated) {
|
|
320
|
+
throw new ForbiddenError(EntityStorageAuthenticationAdminService.CLASS_NAME, "insufficientRoleForEscalatedTarget", { roleName: this._escalatedPrivilegeRole });
|
|
321
|
+
}
|
|
321
322
|
}
|
|
322
323
|
}
|
|
323
324
|
//# sourceMappingURL=entityStorageAuthenticationAdminService.js.map
|