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 +1 -1
- package/server/policies/is-auth.js +16 -19
package/package.json
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
module.exports = async (policyContext, config, { strapi }) => {
|
|
4
|
-
const
|
|
4
|
+
const auth = policyContext.request.header?.authorization;
|
|
5
|
+
if (!auth?.startsWith("Bearer ")) return false;
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
const token = auth.slice(7).trim();
|
|
8
|
+
if (!token) return false;
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
const tokenService =
|
|
11
|
+
strapi.service?.("admin::api-token-content-api") ||
|
|
12
|
+
strapi.service?.("admin::api-token");
|
|
11
13
|
|
|
12
|
-
|
|
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
|
-
|
|
18
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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
|
|
25
|
+
return true;
|
|
29
26
|
};
|