strapi-custom-auth 1.2.37 → 1.2.39

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.
@@ -27,7 +27,6 @@ const Initializer = ({ setPlugin }) => {
27
27
  return null;
28
28
  };
29
29
  const isTokenExpired = (token) => {
30
- console.log("---isTokenExpired, token---", token);
31
30
  if (!token) return true;
32
31
  try {
33
32
  const payload = JSON.parse(atob(token.split(".")[1]));
@@ -39,7 +38,6 @@ const isTokenExpired = (token) => {
39
38
  };
40
39
  const renewToken = async (storage, originalFetch2) => {
41
40
  const refreshToken = storage.getItem("refreshToken");
42
- console.log("---renewToken, refreshToken---", refreshToken);
43
41
  if (!refreshToken) {
44
42
  throw new Error("No refresh token available");
45
43
  }
@@ -69,45 +67,26 @@ const renewToken = async (storage, originalFetch2) => {
69
67
  const originalFetch = window.fetch;
70
68
  const fetchInterceptor = (storage) => {
71
69
  window.fetch = async (input, init = {}) => {
72
- console.log("---input---", JSON.stringify(input));
73
- console.log("---init---", JSON.stringify(init));
74
70
  const url = input instanceof Request ? input.url : input;
75
- console.log("---url---", url);
76
71
  const byPass = init.headers ? await init.headers.get("x-by-pass") : false;
77
72
  if (url.includes("/admin/renew-token") || url.includes("/auth/login") || url.includes("repos/strapi/strapi/releases/latest") || url.includes("/admin/init") || init.body instanceof FormData || byPass == true) {
78
- console.log("---skip renewal---");
79
- try {
80
- const _token = storage.getItem("jwtToken").replace(/"/g, "");
81
- console.log("---skip renewal, _token---", _token);
82
- const _init = {
83
- ...init,
84
- headers: {
85
- ...init.headers,
86
- Authorization: `Bearer ${_token}`
87
- }
88
- };
89
- console.log("---skip renewal, init---", JSON.stringify(_init));
90
- const response = await originalFetch(input, _init);
91
- console.log("---response--", JSON.stringify(response));
92
- console.log("---response, json--", await response.json());
93
- return response;
94
- } catch (e) {
95
- console.log("----fetch---, e", e);
96
- console.log("----fetch---, e", JSON.stringify(e));
97
- }
73
+ const _token = storage.getItem("jwtToken").replace(/"/g, "");
74
+ const _init = {
75
+ ...init,
76
+ headers: {
77
+ ...init.headers,
78
+ Authorization: `Bearer ${_token}`
79
+ }
80
+ };
81
+ const response = await originalFetch(input, _init);
82
+ return response;
98
83
  }
99
- console.log("---renewal---");
100
84
  let token = storage.getItem("jwtToken").replace(/"/g, "");
101
- console.log("---token---", token);
102
85
  if (isTokenExpired(token)) {
103
- console.log("---Token IS EXPIRED---");
104
86
  try {
105
87
  token = await renewToken(storage, originalFetch);
106
- console.log("---Token IS EXPIRED---, token", token);
107
88
  console.log("Token renewed successfully");
108
89
  } catch (error) {
109
- console.log("---Token IS EXPIRED---, error", error);
110
- console.log("---Token IS EXPIRED---, error", JSON.stringify(error));
111
90
  console.error("Token renewal failed. Logging out...");
112
91
  storage.clear();
113
92
  if (!window.location.pathname.includes("/admin/auth/login")) {
@@ -134,14 +113,8 @@ const fetchInterceptor = (storage) => {
134
113
  };
135
114
  try {
136
115
  const response = await originalFetch(input, modifiedInit);
137
- console.log("----originalFetch /2, input", input);
138
- console.log("----originalFetch /2, input", JSON.stringify(input));
139
- console.log("----originalFetch /2, modifiedInit", modifiedInit);
140
- console.log("----originalFetch /2, modifiedInit", JSON.stringify(modifiedInit));
141
- console.log("----originalFetch /2, response", response);
142
116
  if (!response.ok) {
143
117
  const errorData = await response.json();
144
- console.log("----originalFetch /2, errorData", JSON.stringify(errorData));
145
118
  console.log("Fetch error:", errorData.error?.message);
146
119
  if (response.status === 401) {
147
120
  storage.clear();
@@ -26,7 +26,6 @@ const Initializer = ({ setPlugin }) => {
26
26
  return null;
27
27
  };
28
28
  const isTokenExpired = (token) => {
29
- console.log("---isTokenExpired, token---", token);
30
29
  if (!token) return true;
31
30
  try {
32
31
  const payload = JSON.parse(atob(token.split(".")[1]));
@@ -38,7 +37,6 @@ const isTokenExpired = (token) => {
38
37
  };
39
38
  const renewToken = async (storage, originalFetch2) => {
40
39
  const refreshToken = storage.getItem("refreshToken");
41
- console.log("---renewToken, refreshToken---", refreshToken);
42
40
  if (!refreshToken) {
43
41
  throw new Error("No refresh token available");
44
42
  }
@@ -68,45 +66,26 @@ const renewToken = async (storage, originalFetch2) => {
68
66
  const originalFetch = window.fetch;
69
67
  const fetchInterceptor = (storage) => {
70
68
  window.fetch = async (input, init = {}) => {
71
- console.log("---input---", JSON.stringify(input));
72
- console.log("---init---", JSON.stringify(init));
73
69
  const url = input instanceof Request ? input.url : input;
74
- console.log("---url---", url);
75
70
  const byPass = init.headers ? await init.headers.get("x-by-pass") : false;
76
71
  if (url.includes("/admin/renew-token") || url.includes("/auth/login") || url.includes("repos/strapi/strapi/releases/latest") || url.includes("/admin/init") || init.body instanceof FormData || byPass == true) {
77
- console.log("---skip renewal---");
78
- try {
79
- const _token = storage.getItem("jwtToken").replace(/"/g, "");
80
- console.log("---skip renewal, _token---", _token);
81
- const _init = {
82
- ...init,
83
- headers: {
84
- ...init.headers,
85
- Authorization: `Bearer ${_token}`
86
- }
87
- };
88
- console.log("---skip renewal, init---", JSON.stringify(_init));
89
- const response = await originalFetch(input, _init);
90
- console.log("---response--", JSON.stringify(response));
91
- console.log("---response, json--", await response.json());
92
- return response;
93
- } catch (e) {
94
- console.log("----fetch---, e", e);
95
- console.log("----fetch---, e", JSON.stringify(e));
96
- }
72
+ const _token = storage.getItem("jwtToken").replace(/"/g, "");
73
+ const _init = {
74
+ ...init,
75
+ headers: {
76
+ ...init.headers,
77
+ Authorization: `Bearer ${_token}`
78
+ }
79
+ };
80
+ const response = await originalFetch(input, _init);
81
+ return response;
97
82
  }
98
- console.log("---renewal---");
99
83
  let token = storage.getItem("jwtToken").replace(/"/g, "");
100
- console.log("---token---", token);
101
84
  if (isTokenExpired(token)) {
102
- console.log("---Token IS EXPIRED---");
103
85
  try {
104
86
  token = await renewToken(storage, originalFetch);
105
- console.log("---Token IS EXPIRED---, token", token);
106
87
  console.log("Token renewed successfully");
107
88
  } catch (error) {
108
- console.log("---Token IS EXPIRED---, error", error);
109
- console.log("---Token IS EXPIRED---, error", JSON.stringify(error));
110
89
  console.error("Token renewal failed. Logging out...");
111
90
  storage.clear();
112
91
  if (!window.location.pathname.includes("/admin/auth/login")) {
@@ -133,14 +112,8 @@ const fetchInterceptor = (storage) => {
133
112
  };
134
113
  try {
135
114
  const response = await originalFetch(input, modifiedInit);
136
- console.log("----originalFetch /2, input", input);
137
- console.log("----originalFetch /2, input", JSON.stringify(input));
138
- console.log("----originalFetch /2, modifiedInit", modifiedInit);
139
- console.log("----originalFetch /2, modifiedInit", JSON.stringify(modifiedInit));
140
- console.log("----originalFetch /2, response", response);
141
115
  if (!response.ok) {
142
116
  const errorData = await response.json();
143
- console.log("----originalFetch /2, errorData", JSON.stringify(errorData));
144
117
  console.log("Fetch error:", errorData.error?.message);
145
118
  if (response.status === 401) {
146
119
  storage.clear();
@@ -3019,7 +3019,11 @@ async function cognitoSignInCallback(ctx) {
3019
3019
  let jwtToken;
3020
3020
  if (dbUser) {
3021
3021
  activateUser = dbUser;
3022
- jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: dbUser.id });
3022
+ jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3023
+ userId: `${dbUser.id}`,
3024
+ type: "access",
3025
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3026
+ });
3023
3027
  } else {
3024
3028
  const cognitoRoles = await roleService.cognitoRoles();
3025
3029
  const roles2 = cognitoRoles && cognitoRoles["roles"] ? cognitoRoles["roles"].map((role2) => ({
@@ -3033,7 +3037,11 @@ async function cognitoSignInCallback(ctx) {
3033
3037
  defaultLocale,
3034
3038
  roles2
3035
3039
  );
3036
- jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: activateUser.id });
3040
+ jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3041
+ userId: `${activateUser.id}`,
3042
+ type: "access",
3043
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3044
+ });
3037
3045
  await oauthService.triggerWebHook(activateUser);
3038
3046
  }
3039
3047
  oauthService.triggerSignInSuccess(activateUser);
@@ -3108,7 +3116,11 @@ async function customSignInCallback(ctx) {
3108
3116
  }
3109
3117
  if (dbUser) {
3110
3118
  activateUser = dbUser;
3111
- jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: dbUser.id });
3119
+ jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3120
+ userId: `${dbUser.id}`,
3121
+ type: "access",
3122
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3123
+ });
3112
3124
  }
3113
3125
  oauthService.triggerSignInSuccess(activateUser);
3114
3126
  const html = oauthService.renderSignUpSuccess(jwtToken, activateUser, nonce);
@@ -3199,7 +3211,11 @@ async function customConfirmMfa(ctx) {
3199
3211
  if (!otp2) {
3200
3212
  throw new Error("Invalid code");
3201
3213
  }
3202
- jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: otp2.user.id });
3214
+ jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3215
+ userId: `${otp2.user.id}`,
3216
+ type: "access",
3217
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3218
+ });
3203
3219
  await strapi.query("plugin::strapi-custom-auth.mfaotp").delete({
3204
3220
  where: {
3205
3221
  id
@@ -3357,14 +3373,22 @@ async function microsoftSignInCallback(ctx) {
3357
3373
  } else {
3358
3374
  activateUser = dbUser;
3359
3375
  }
3360
- jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: activateUser.id });
3376
+ jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3377
+ userId: `${activateUser.id}`,
3378
+ type: "access",
3379
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3380
+ });
3361
3381
  } else {
3362
3382
  console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user does not exist, creating it");
3363
3383
  const roles2 = await roleService.retrieveMicrosoftUserRoles(groupResponse, config2);
3364
3384
  const defaultLocale = oauthService.localeFindByHeader(ctx.request.headers);
3365
3385
  activateUser = await oauthService.createUser(mail, surname, givenName, defaultLocale, roles2);
3366
3386
  console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user created, generating token");
3367
- jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: activateUser.id });
3387
+ jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3388
+ userId: `${activateUser.id}`,
3389
+ type: "access",
3390
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3391
+ });
3368
3392
  }
3369
3393
  oauthService.triggerSignInSuccess(activateUser);
3370
3394
  const nonce = v4();
@@ -3416,7 +3440,11 @@ async function microsoftTokenRenewal(ctx) {
3416
3440
  });
3417
3441
  const { mail } = userResponse?.data;
3418
3442
  const dbUser = await userService.findOneByEmail(mail);
3419
- const jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: dbUser.id });
3443
+ const jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3444
+ userId: `${dbUser.id}`,
3445
+ type: "access",
3446
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3447
+ });
3420
3448
  return ctx.send({ accessToken: jwtToken, refreshToken: tokenResponse.data.refresh_token });
3421
3449
  } catch (e2) {
3422
3450
  console.error(e2.message);
@@ -3004,7 +3004,11 @@ async function cognitoSignInCallback(ctx) {
3004
3004
  let jwtToken;
3005
3005
  if (dbUser) {
3006
3006
  activateUser = dbUser;
3007
- jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: dbUser.id });
3007
+ jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3008
+ userId: `${dbUser.id}`,
3009
+ type: "access",
3010
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3011
+ });
3008
3012
  } else {
3009
3013
  const cognitoRoles = await roleService.cognitoRoles();
3010
3014
  const roles2 = cognitoRoles && cognitoRoles["roles"] ? cognitoRoles["roles"].map((role2) => ({
@@ -3018,7 +3022,11 @@ async function cognitoSignInCallback(ctx) {
3018
3022
  defaultLocale,
3019
3023
  roles2
3020
3024
  );
3021
- jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: activateUser.id });
3025
+ jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3026
+ userId: `${activateUser.id}`,
3027
+ type: "access",
3028
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3029
+ });
3022
3030
  await oauthService.triggerWebHook(activateUser);
3023
3031
  }
3024
3032
  oauthService.triggerSignInSuccess(activateUser);
@@ -3093,7 +3101,11 @@ async function customSignInCallback(ctx) {
3093
3101
  }
3094
3102
  if (dbUser) {
3095
3103
  activateUser = dbUser;
3096
- jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: dbUser.id });
3104
+ jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3105
+ userId: `${dbUser.id}`,
3106
+ type: "access",
3107
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3108
+ });
3097
3109
  }
3098
3110
  oauthService.triggerSignInSuccess(activateUser);
3099
3111
  const html = oauthService.renderSignUpSuccess(jwtToken, activateUser, nonce);
@@ -3184,7 +3196,11 @@ async function customConfirmMfa(ctx) {
3184
3196
  if (!otp2) {
3185
3197
  throw new Error("Invalid code");
3186
3198
  }
3187
- jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: otp2.user.id });
3199
+ jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3200
+ userId: `${otp2.user.id}`,
3201
+ type: "access",
3202
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3203
+ });
3188
3204
  await strapi.query("plugin::strapi-custom-auth.mfaotp").delete({
3189
3205
  where: {
3190
3206
  id
@@ -3342,14 +3358,22 @@ async function microsoftSignInCallback(ctx) {
3342
3358
  } else {
3343
3359
  activateUser = dbUser;
3344
3360
  }
3345
- jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: activateUser.id });
3361
+ jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3362
+ userId: `${activateUser.id}`,
3363
+ type: "access",
3364
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3365
+ });
3346
3366
  } else {
3347
3367
  console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user does not exist, creating it");
3348
3368
  const roles2 = await roleService.retrieveMicrosoftUserRoles(groupResponse, config2);
3349
3369
  const defaultLocale = oauthService.localeFindByHeader(ctx.request.headers);
3350
3370
  activateUser = await oauthService.createUser(mail, surname, givenName, defaultLocale, roles2);
3351
3371
  console.log("[STRAPI-CUSTOM-AUTH] Microsoft Sign Callback: user created, generating token");
3352
- jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: activateUser.id });
3372
+ jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3373
+ userId: `${activateUser.id}`,
3374
+ type: "access",
3375
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3376
+ });
3353
3377
  }
3354
3378
  oauthService.triggerSignInSuccess(activateUser);
3355
3379
  const nonce = v4();
@@ -3401,7 +3425,11 @@ async function microsoftTokenRenewal(ctx) {
3401
3425
  });
3402
3426
  const { mail } = userResponse?.data;
3403
3427
  const dbUser = await userService.findOneByEmail(mail);
3404
- const jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({ id: dbUser.id });
3428
+ const jwtToken = strapi.plugins["users-permissions"].services.jwt.issue({
3429
+ userId: `${dbUser.id}`,
3430
+ type: "access",
3431
+ sessionId: "306b9b90ed47a1f9297ec25f05b07e05"
3432
+ });
3405
3433
  return ctx.send({ accessToken: jwtToken, refreshToken: tokenResponse.data.refresh_token });
3406
3434
  } catch (e2) {
3407
3435
  console.error(e2.message);
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.37",
2
+ "version": "1.2.39",
3
3
  "keywords": [],
4
4
  "type": "commonjs",
5
5
  "exports": {