strapi-identity 0.4.2 → 0.5.0

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.
Files changed (60) hide show
  1. package/dist/admin/{AdminReset-BiWQDTRv.js → AdminReset-BoWx0F06.js} +1 -1
  2. package/dist/admin/{AdminReset-DOmsyqwQ.mjs → AdminReset-D4NNnBDS.mjs} +1 -1
  3. package/dist/admin/{ProfileToggle-BUqs_hxZ.js → ProfileToggle-DtjyJRWN.js} +1 -1
  4. package/dist/admin/{ProfileToggle-k0d-caPC.mjs → ProfileToggle-NJZgrDT_.mjs} +1 -1
  5. package/dist/admin/{SettingsPage-DVVkN1xw.js → SettingsPage-BXl7gVGV.js} +1 -1
  6. package/dist/admin/{SettingsPage-Dm_llkYv.mjs → SettingsPage-CZuOMYvG.mjs} +1 -1
  7. package/dist/admin/{index-B9P8S4CX.js → index-BeqHh5Gz.js} +22 -15
  8. package/dist/admin/{index-DpIJdETG.mjs → index-CKG2ZxYT.mjs} +22 -15
  9. package/dist/admin/index.js +1 -1
  10. package/dist/admin/index.mjs +1 -1
  11. package/dist/admin/src/components/ConfirmModal/ConfirmModal.d.ts +9 -0
  12. package/dist/admin/src/components/ConfirmModal/index.d.ts +1 -0
  13. package/dist/admin/src/components/EmailOTPModal/EmailOTPModal.d.ts +8 -0
  14. package/dist/admin/src/components/Initializer.d.ts +5 -0
  15. package/dist/admin/src/components/InputOTP.d.ts +11 -0
  16. package/dist/admin/src/components/RemoveModal/RemoveModal.d.ts +6 -0
  17. package/dist/admin/src/components/RemoveModal/index.d.ts +1 -0
  18. package/dist/admin/src/components/WarningAlert/WarningAlert.d.ts +10 -0
  19. package/dist/admin/src/components/WarningAlert/index.d.ts +1 -0
  20. package/dist/admin/src/injection/AdminReset.d.ts +4 -0
  21. package/dist/admin/src/injection/ProfileToggle.d.ts +2 -0
  22. package/dist/admin/src/pages/EnforcedPage.d.ts +13 -0
  23. package/dist/admin/src/pluginId.d.ts +1 -0
  24. package/dist/admin/src/public/VerifyPage.d.ts +12 -0
  25. package/dist/admin/src/settings/SettingsPage.d.ts +1 -0
  26. package/dist/admin/src/utils/getTranslation.d.ts +2 -0
  27. package/dist/admin/src/utils/tokenHelpers.d.ts +12 -0
  28. package/dist/server/index.js +71 -47
  29. package/dist/server/index.mjs +71 -47
  30. package/dist/server/src/bootstrap.d.ts +3 -0
  31. package/dist/server/src/config/index.d.ts +3 -0
  32. package/dist/server/src/content-types/config/index.d.ts +72 -0
  33. package/dist/server/src/content-types/config/schema.json.d.ts +72 -0
  34. package/dist/server/src/content-types/email-otp/index.d.ts +48 -0
  35. package/dist/server/src/content-types/email-otp/schema.json.d.ts +48 -0
  36. package/dist/server/src/content-types/index.d.ts +3 -0
  37. package/dist/server/src/content-types/mfa/index.d.ts +55 -0
  38. package/dist/server/src/content-types/mfa/schema.json.d.ts +55 -0
  39. package/dist/server/src/content-types/temp-mfa/index.d.ts +35 -0
  40. package/dist/server/src/content-types/temp-mfa/schema.json.d.ts +35 -0
  41. package/dist/server/src/controllers/admin.d.ts +4 -0
  42. package/dist/server/src/controllers/config.d.ts +4 -0
  43. package/dist/server/src/controllers/controller.d.ts +8 -0
  44. package/dist/server/src/controllers/index.d.ts +3 -0
  45. package/dist/server/src/destroy.d.ts +3 -0
  46. package/dist/server/src/middlewares/index.d.ts +3 -0
  47. package/dist/server/src/policies/has-mfa.d.ts +3 -0
  48. package/dist/server/src/policies/index.d.ts +3 -0
  49. package/dist/server/src/register.d.ts +3 -0
  50. package/dist/server/src/routes/admin/admin.json.d.ts +35 -0
  51. package/dist/server/src/routes/admin/config.json.d.ts +50 -0
  52. package/dist/server/src/routes/admin/index.d.ts +3 -0
  53. package/dist/server/src/routes/admin/mfa.json.d.ts +94 -0
  54. package/dist/server/src/routes/index.d.ts +3 -0
  55. package/dist/server/src/services/admin.d.ts +11 -0
  56. package/dist/server/src/services/config.d.ts +57 -0
  57. package/dist/server/src/services/email.d.ts +8 -0
  58. package/dist/server/src/services/index.d.ts +3 -0
  59. package/dist/server/src/services/mfa.d.ts +82 -0
  60. package/package.json +6 -5
@@ -0,0 +1,35 @@
1
+ declare const _default: {
2
+ "kind": "collectionType",
3
+ "collectionName": "mfa-temps",
4
+ "info": {
5
+ "singularName": "mfa-temp",
6
+ "pluralName": "mfa-temps",
7
+ "displayName": "MFA Temp"
8
+ },
9
+ "options": {
10
+ "draftAndPublish": false
11
+ },
12
+ "pluginOptions": {
13
+ "content-manager": {
14
+ "visible": false
15
+ },
16
+ "content-type-builder": {
17
+ "visible": false
18
+ }
19
+ },
20
+ "attributes": {
21
+ "admin_user": {
22
+ "type": "relation",
23
+ "relation": "oneToOne",
24
+ "target": "admin::user"
25
+ },
26
+ "secret": {
27
+ "type": "string",
28
+ "required": false,
29
+ "private": true
30
+ }
31
+ }
32
+ }
33
+ ;
34
+
35
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import { Plugin } from '@strapi/types';
2
+ type controller = Plugin.LoadedPlugin['controllers'][string];
3
+ declare const _default: controller;
4
+ export default _default;
@@ -0,0 +1,4 @@
1
+ import { Plugin } from '@strapi/types';
2
+ type controller = Plugin.LoadedPlugin['controllers'][string];
3
+ declare const _default: controller;
4
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import { Core } from '@strapi/strapi';
2
+ import { Plugin } from '@strapi/types';
3
+ type controller = Plugin.LoadedPlugin['controllers'][string];
4
+ declare const controller: ({ strapi }: {
5
+ strapi: Core.Strapi;
6
+ }) => controller;
7
+ declare const _default: controller;
8
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from '@strapi/strapi';
2
+ declare const controllers: Plugin.LoadedPlugin['controllers'];
3
+ export default controllers;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from '@strapi/types';
2
+ declare const destroy: Plugin.LoadedPlugin['destroy'];
3
+ export default destroy;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from '@strapi/types';
2
+ declare const middlewares: Plugin.LoadedPlugin['middlewares'];
3
+ export default middlewares;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from '@strapi/types';
2
+ declare const policy: Plugin.LoadedPlugin['policies'][string];
3
+ export default policy;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from '@strapi/types';
2
+ declare const policies: Plugin.LoadedPlugin['policies'];
3
+ export default policies;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from '@strapi/types';
2
+ declare const register: Plugin.LoadedPlugin['register'];
3
+ export default register;
@@ -0,0 +1,35 @@
1
+ declare const _default: [
2
+ {
3
+ "method": "GET",
4
+ "path": "/admin/user/:id",
5
+ "handler": "admin.isEnabled",
6
+ "info": { "apiName": "isEnabled", "pluginName": "strapi-identity", "type": "content-api" },
7
+ "config": {
8
+ "policies": [
9
+ "admin::isAuthenticatedAdmin",
10
+ {
11
+ "name": "admin::hasPermissions",
12
+ "config": { "actions": ["plugin::strapi-identity.settings.read"] }
13
+ }
14
+ ]
15
+ }
16
+ },
17
+ {
18
+ "method": "DELETE",
19
+ "path": "/admin/user/:id",
20
+ "handler": "admin.reset",
21
+ "info": { "apiName": "reset", "pluginName": "strapi-identity", "type": "content-api" },
22
+ "config": {
23
+ "policies": [
24
+ "admin::isAuthenticatedAdmin",
25
+ {
26
+ "name": "admin::hasPermissions",
27
+ "config": { "actions": ["plugin::strapi-identity.settings.update"] }
28
+ }
29
+ ]
30
+ }
31
+ }
32
+ ]
33
+ ;
34
+
35
+ export default _default;
@@ -0,0 +1,50 @@
1
+ declare const _default: [
2
+ {
3
+ "method": "GET",
4
+ "path": "/config/enabled",
5
+ "handler": "config.isEnabled",
6
+ "info": { "apiName": "isEnabled", "pluginName": "strapi-identity", "type": "content-api" },
7
+ "config": {
8
+ "policies": [
9
+ "admin::isAuthenticatedAdmin",
10
+ {
11
+ "name": "admin::hasPermissions",
12
+ "config": { "actions": ["plugin::strapi-identity.settings.read"] }
13
+ }
14
+ ]
15
+ }
16
+ },
17
+ {
18
+ "method": "GET",
19
+ "path": "/config",
20
+ "handler": "config.getConfig",
21
+ "info": { "apiName": "getConfig", "pluginName": "strapi-identity", "type": "content-api" },
22
+ "config": {
23
+ "policies": [
24
+ "admin::isAuthenticatedAdmin",
25
+ {
26
+ "name": "admin::hasPermissions",
27
+ "config": { "actions": ["plugin::strapi-identity.settings.read"] }
28
+ }
29
+ ]
30
+ }
31
+ },
32
+ {
33
+ "method": "PUT",
34
+ "path": "/config",
35
+ "handler": "config.updateConfig",
36
+ "info": { "apiName": "updateConfig", "pluginName": "strapi-identity", "type": "content-api" },
37
+ "config": {
38
+ "policies": [
39
+ "admin::isAuthenticatedAdmin",
40
+ {
41
+ "name": "admin::hasPermissions",
42
+ "config": { "actions": ["plugin::strapi-identity.settings.update"] }
43
+ }
44
+ ]
45
+ }
46
+ }
47
+ ]
48
+ ;
49
+
50
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from '@strapi/types';
2
+ declare const _default: Plugin.LoadedPlugin["routes"]["admin"];
3
+ export default _default;
@@ -0,0 +1,94 @@
1
+ declare const _default: [
2
+ {
3
+ "method": "GET",
4
+ "path": "/verify/info",
5
+ "handler": "controller.verifyInfo",
6
+ "info": { "apiName": "verifyInfo", "pluginName": "strapi-identity", "type": "content-api" },
7
+ "config": {
8
+ "auth": false,
9
+ "policies": ["has-mfa"]
10
+ }
11
+ },
12
+ {
13
+ "method": "POST",
14
+ "path": "/verify",
15
+ "handler": "controller.verify",
16
+ "info": { "apiName": "verify", "pluginName": "strapi-identity", "type": "content-api" },
17
+ "config": {
18
+ "auth": false,
19
+ "policies": ["has-mfa"],
20
+ "middlewares": ["admin::rateLimit"]
21
+ }
22
+ },
23
+ {
24
+ "method": "POST",
25
+ "path": "/enable",
26
+ "handler": "controller.enable",
27
+ "info": { "apiName": "enable", "pluginName": "strapi-identity", "type": "content-api" },
28
+ "config": {}
29
+ },
30
+ {
31
+ "method": "POST",
32
+ "path": "/setup",
33
+ "handler": "controller.setup",
34
+ "info": { "apiName": "setup", "pluginName": "strapi-identity", "type": "content-api" },
35
+ "config": {}
36
+ },
37
+ {
38
+ "method": "POST",
39
+ "path": "/disable",
40
+ "handler": "controller.disable",
41
+ "info": { "apiName": "disable", "pluginName": "strapi-identity", "type": "content-api" },
42
+ "config": {}
43
+ },
44
+ {
45
+ "method": "GET",
46
+ "path": "/status",
47
+ "handler": "controller.checkStatus",
48
+ "info": { "apiName": "checkStatus", "pluginName": "strapi-identity", "type": "content-api" },
49
+ "config": {}
50
+ },
51
+ {
52
+ "method": "POST",
53
+ "path": "/verify/resend",
54
+ "handler": "controller.resendVerifyOTP",
55
+ "info": {
56
+ "apiName": "resendVerifyOTP",
57
+ "pluginName": "strapi-identity",
58
+ "type": "content-api"
59
+ },
60
+ "config": {
61
+ "auth": false,
62
+ "policies": ["has-mfa"],
63
+ "middlewares": []
64
+ }
65
+ },
66
+ {
67
+ "method": "POST",
68
+ "path": "/enable-email",
69
+ "handler": "controller.enableEmail",
70
+ "info": { "apiName": "enableEmail", "pluginName": "strapi-identity", "type": "content-api" },
71
+ "config": {}
72
+ },
73
+ {
74
+ "method": "POST",
75
+ "path": "/setup-email",
76
+ "handler": "controller.setupEmail",
77
+ "info": { "apiName": "setupEmail", "pluginName": "strapi-identity", "type": "content-api" },
78
+ "config": {}
79
+ },
80
+ {
81
+ "method": "POST",
82
+ "path": "/disable-email/request",
83
+ "handler": "controller.requestDisableEmailOTP",
84
+ "info": {
85
+ "apiName": "requestDisableEmailOTP",
86
+ "pluginName": "strapi-identity",
87
+ "type": "content-api"
88
+ },
89
+ "config": {}
90
+ }
91
+ ]
92
+ ;
93
+
94
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from '@strapi/types';
2
+ declare const routes: Plugin.LoadedPlugin['routes'];
3
+ export default routes;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Check if 2FA is enabled for a user by looking for an associated MFA token.
3
+ * @param id the user's ID to check for an associated MFA token, indicating that 2FA is enabled for that user
4
+ * @returns a boolean indicating whether 2FA is enabled for the user (true if an MFA token exists, false otherwise)
5
+ */
6
+ export declare const isEnabled: (id: string) => false | Promise<boolean>;
7
+ /**
8
+ * Resets 2FA for a user by deleting any existing MFA token and temporary secret associated with that user.
9
+ * @param id the user's ID for which to reset 2FA, which will delete any associated MFA token and temporary secret, effectively disabling 2FA for that user until they set it up again
10
+ */
11
+ export declare const reset: (id: string) => Promise<void>;
@@ -0,0 +1,57 @@
1
+ declare const defaultConfig: {
2
+ email_enabled: boolean;
3
+ enabled: boolean;
4
+ enforce: boolean;
5
+ from_email: string;
6
+ from_name: string;
7
+ issuer: string;
8
+ message: string;
9
+ response_email: string;
10
+ subject: string;
11
+ text: string;
12
+ };
13
+ /**
14
+ * Service for managing the Strapi Identity plugin configuration
15
+ * @returns an object containing functions to get and update the plugin configuration
16
+ */
17
+ export declare const isEnabled: () => Promise<boolean>;
18
+ /**
19
+ * Retrieves the current configuration for the Strapi Identity plugin
20
+ * @returns the current configuration
21
+ */
22
+ export declare const getConfig: () => Promise<{
23
+ email_enabled: boolean;
24
+ enabled: boolean;
25
+ enforce: boolean;
26
+ from_email: string;
27
+ from_name: string;
28
+ issuer: string;
29
+ message: string;
30
+ response_email: string;
31
+ subject: string;
32
+ text: string;
33
+ }>;
34
+ /**
35
+ * Updates the Strapi Identity plugin configuration with the provided data
36
+ * @param data partial configuration data to update
37
+ * @returns the updated configuration
38
+ */
39
+ export declare const updateConfig: (data: Partial<typeof defaultConfig>) => Promise<{
40
+ email_enabled: boolean;
41
+ enabled: boolean;
42
+ enforce: boolean;
43
+ from_email: string;
44
+ from_name: string;
45
+ issuer: string;
46
+ message: string;
47
+ response_email: string;
48
+ subject: string;
49
+ text: string;
50
+ }>;
51
+ /**
52
+ * Checks if a user has MFA enabled by verifying the provided JWT token and checking for an associated MFA token in the database
53
+ * @param jwtToken the JWT token to verify and extract the user ID from
54
+ * @returns true if the user has MFA enabled, false otherwise
55
+ */
56
+ export declare const checkUserByJWT: (jwtToken: string) => Promise<boolean>;
57
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare const send: (to: string, otp: string) => Promise<any>;
2
+ /**
3
+ * Replaces template variables in a string with their corresponding values.
4
+ * @param template The template string containing variables in the format <%= VARIABLE %>.
5
+ * @param variables An object containing the variable values to replace in the template.
6
+ * @returns The template string with variables replaced by their corresponding values.
7
+ */
8
+ export declare const replaceTemplateVariables: <T extends Record<string, string>>(template: string, variables: T) => string;
@@ -0,0 +1,3 @@
1
+ import { Plugin } from '@strapi/types';
2
+ declare const services: Plugin.LoadedPlugin['services'];
3
+ export default services;
@@ -0,0 +1,82 @@
1
+ import { Secret } from 'otpauth';
2
+ /**
3
+ * Validates a TOTP token against the temporary secret for a given user
4
+ * @param userId id of the user to validate against
5
+ * @param token TOTP token to validate
6
+ * @returns {Promise<boolean>} is the token valid
7
+ */
8
+ export declare const validateTempToken: (userId: string, token: string) => Promise<boolean>;
9
+ /**
10
+ * Validates a code against both the user's active TOTP secret and their recovery codes
11
+ * @param userId id of the user to validate against
12
+ * @param code code to validate (either TOTP token or recovery code)
13
+ * @returns {Promise<boolean>} is the code valid
14
+ */
15
+ export declare const validateTokenOrRecoveryCode: (userId: string, code: string) => Promise<boolean>;
16
+ /**
17
+ * Sets up a temporary secret for a user during MFA setup
18
+ * @param userId id of the user to set up MFA for
19
+ * @return {Promise<Secret>} the generated temporary secret
20
+ */
21
+ export declare const setupTemporarySecret: (userId: string) => Promise<Secret>;
22
+ /**
23
+ * Finalizes MFA setup by moving the temporary secret to the main token document and generating recovery codes
24
+ * @param userId id of the user to finalize MFA setup for
25
+ * @returns {Promise<string[]>} the generated recovery codes
26
+ */
27
+ export declare const setupFullSecret: (userId: string) => Promise<string[]>;
28
+ /**
29
+ * Generates a 6-digit email OTP for a user, stores it hashed with expiry, and returns the plaintext code
30
+ * @param userId id of the user to generate an OTP for
31
+ * @param purpose the purpose of the OTP: 'login', 'setup', or 'disable'
32
+ * @returns {Promise<string>} the plaintext OTP
33
+ */
34
+ export declare const generateEmailOTP: (userId: string, purpose?: "login" | "setup" | "disable") => Promise<string>;
35
+ /**
36
+ * Validates an email OTP for a given user and purpose.
37
+ * Increments attempt count, rejects on expiry or too many attempts, removes the record on success.
38
+ * @param userId id of the user to validate against
39
+ * @param code plaintext OTP to validate
40
+ * @param purpose the purpose of the OTP
41
+ * @returns {Promise<boolean>} whether the code is valid
42
+ */
43
+ export declare const validateEmailOTP: (userId: string, code: string, purpose?: "login" | "setup" | "disable") => Promise<boolean>;
44
+ /**
45
+ * Enables email OTP MFA for a user, creating or updating their mfa-token record
46
+ * @param userId id of the user to enable email MFA for
47
+ */
48
+ export declare const enableEmailMFA: (userId: string) => Promise<void>;
49
+ /**
50
+ * Returns the MFA status and method type for a given user
51
+ * @param userId id of the user to check
52
+ * @returns the status and type of MFA, or null if not enabled
53
+ */
54
+ export declare const getMFAInfo: (userId: string) => Promise<{
55
+ status: "full";
56
+ type: "totp" | "email";
57
+ } | null>;
58
+ /**
59
+ * Disables MFA for a user after validating the provided code.
60
+ * For TOTP, validates against TOTP token or recovery code.
61
+ * For email OTP, validates against a previously generated disable OTP.
62
+ * @param userId id of the user to disable MFA for
63
+ * @param code a valid TOTP token, recovery code, or email OTP
64
+ */
65
+ export declare const disableSecret: (userId: string, code: string) => Promise<void>;
66
+ /**
67
+ * Disables the temporary secret for a user, effectively canceling the MFA setup process
68
+ * @param userId id of the user to disable the temporary secret for
69
+ */
70
+ export declare const disableTempSecret: (userId: string) => Promise<void>;
71
+ /**
72
+ * Checks if MFA is currently enabled for a given user
73
+ * @param userId id of the user to check
74
+ * @returns {Promise<'full' | null>} is MFA enabled for the user
75
+ */
76
+ export declare const isMFAEnabled: (userId: string) => Promise<"full" | null>;
77
+ /**
78
+ * Generates a secure random recovery code of the specified length
79
+ * @param length length of the recovery code to generate (default: 8)
80
+ * @returns {string} the generated recovery code
81
+ */
82
+ export declare const generateRecoveryCode: (length?: number) => string;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.4.2",
2
+ "version": "0.5.0",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "plugin",
@@ -43,16 +43,17 @@
43
43
  "strapi-admin-portal": "^0.3.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@strapi/sdk-plugin": "^6.0.1",
47
- "@strapi/typescript-utils": "^5.40.0",
46
+ "@strapi/sdk-plugin": "^6.1.0",
47
+ "@strapi/typescript-utils": "^5.43.0",
48
48
  "@types/bcryptjs": "^2.4.6",
49
- "@types/react": "^18.3.27",
49
+ "@types/react": "^18.3.28",
50
50
  "@types/react-dom": "^18.3.7",
51
- "prettier": "^3.8.1",
51
+ "prettier": "^3.8.3",
52
52
  "typescript": "^5.9.3"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@strapi/design-system": "^2.1.2",
56
+ "koa2-ratelimit": "^1.1.3",
56
57
  "@strapi/email": "^5.39.0",
57
58
  "@strapi/icons": "^2.1.2",
58
59
  "@strapi/sdk-plugin": "^5.4.0",