strapi-plugin-payone-provider 5.8.28 → 5.8.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-plugin-payone-provider",
3
- "version": "5.8.28",
3
+ "version": "5.8.29",
4
4
  "description": "Strapi plugin for Payone payment gateway integration",
5
5
  "license": "MIT",
6
6
  "maintainers": [
@@ -1,29 +1,26 @@
1
1
  "use strict";
2
2
 
3
3
  module.exports = async (policyContext, config, { strapi }) => {
4
- const { authorization } = policyContext.request.header || {};
4
+ const auth = policyContext.request.header?.authorization;
5
+ if (!auth?.startsWith("Bearer ")) return false;
5
6
 
6
- if (authorization && authorization.startsWith("Bearer ")) {
7
- const token = authorization.split(" ")[1];
7
+ const token = auth.slice(7).trim();
8
+ if (!token) return false;
8
9
 
9
- try {
10
- const apiTokenService = strapi.service("admin::api-token");
10
+ const tokenService =
11
+ strapi.service?.("admin::api-token-content-api") ||
12
+ strapi.service?.("admin::api-token");
11
13
 
12
- if (!apiTokenService) {
13
- strapi.log.warn("strapi-plugin-payone-provider: api-token service not found");
14
- return false;
15
- }
14
+ if (!tokenService?.hash) return false;
16
15
 
17
- const accessKey = await apiTokenService.hash(token);
18
- const storedToken = await apiTokenService.getBy({ accessKey });
16
+ const accessKey = tokenService.hash(token);
17
+ const stored = await (tokenService.getByAccessKey
18
+ ? tokenService.getByAccessKey(accessKey)
19
+ : tokenService.getBy?.({ accessKey })
20
+ ).catch(() => null);
19
21
 
20
- if (storedToken) {
21
- return true;
22
- }
23
- } catch (e) {
24
- strapi.log.warn("strapi-plugin-payone-provider isAuth policy error:", e.message);
25
- }
26
- }
22
+ if (!stored) return false;
23
+ if (stored.expiresAt && new Date(stored.expiresAt) < new Date()) return false;
27
24
 
28
- return false;
25
+ return true;
29
26
  };