@strapi/plugin-users-permissions 4.0.7 → 4.0.8

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-users-permissions",
3
- "version": "4.0.7",
3
+ "version": "4.0.8",
4
4
  "description": "Protect your API with a full-authentication process based on JWT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,8 +28,8 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@purest/providers": "^1.0.2",
31
- "@strapi/helper-plugin": "4.0.7",
32
- "@strapi/utils": "4.0.7",
31
+ "@strapi/helper-plugin": "4.0.8",
32
+ "@strapi/utils": "4.0.8",
33
33
  "bcryptjs": "2.4.3",
34
34
  "grant-koa": "5.4.8",
35
35
  "jsonwebtoken": "^8.1.0",
@@ -61,5 +61,5 @@
61
61
  "required": true,
62
62
  "kind": "plugin"
63
63
  },
64
- "gitHead": "af0cba8c5b2ba7b371523e8f55413ef0fce98e1e"
64
+ "gitHead": "669bb2f0440d3b21a23c8d665fdba98bd3d8cc71"
65
65
  }
@@ -8,6 +8,7 @@
8
8
  * run jobs, or perform some special logic.
9
9
  */
10
10
  const _ = require('lodash');
11
+ const urljoin = require('url-join');
11
12
  const uuid = require('uuid/v4');
12
13
  const { getService } = require('../utils');
13
14
 
@@ -41,7 +42,7 @@ module.exports = async ({ strapi }) => {
41
42
 
42
43
  const initGrant = async pluginStore => {
43
44
  const apiPrefix = strapi.config.get('api.rest.prefix');
44
- const baseURL = `${strapi.config.server.url}/${apiPrefix}/auth`;
45
+ const baseURL = urljoin(strapi.config.server.url, apiPrefix, 'auth');
45
46
 
46
47
  const grantConfig = {
47
48
  email: {
@@ -67,40 +67,25 @@ const authenticate = async ctx => {
67
67
  const verify = async (auth, config) => {
68
68
  const { credentials: user } = auth;
69
69
 
70
- // public accesss
71
- if (!user) {
72
- // test against public role
73
- const publicPermissions = await strapi.query('plugin::users-permissions.permission').findMany({
74
- where: {
75
- role: { type: 'public' },
76
- },
77
- });
78
-
79
- const allowedActions = map('action', publicPermissions);
80
-
81
- // A non authenticated user cannot access routes that do not have a scope
82
- if (!config.scope) {
70
+ if (!config.scope) {
71
+ if (!user) {
72
+ // A non authenticated user cannot access routes that do not have a scope
83
73
  throw new UnauthorizedError();
74
+ } else {
75
+ // An authenticated user can access non scoped routes
76
+ return;
84
77
  }
85
-
86
- const isAllowed = castArray(config.scope).every(scope => allowedActions.includes(scope));
87
-
88
- if (!isAllowed) {
89
- throw new ForbiddenError();
90
- }
91
-
92
- return;
93
78
  }
94
79
 
95
- const permissions = await strapi.query('plugin::users-permissions.permission').findMany({
96
- where: { role: user.role.id },
97
- });
80
+ let allowedActions = auth.allowedActions;
98
81
 
99
- const allowedActions = map('action', permissions);
82
+ if (!allowedActions) {
83
+ const permissions = await strapi.query('plugin::users-permissions.permission').findMany({
84
+ where: { role: user ? user.role.id : { type: 'public' } },
85
+ });
100
86
 
101
- // An authenticated user can access non scoped routes
102
- if (!config.scope) {
103
- return;
87
+ allowedActions = map('action', permissions);
88
+ auth.allowedActions = allowedActions;
104
89
  }
105
90
 
106
91
  const isAllowed = castArray(config.scope).every(scope => allowedActions.includes(scope));
@@ -108,12 +93,6 @@ const verify = async (auth, config) => {
108
93
  if (!isAllowed) {
109
94
  throw new ForbiddenError();
110
95
  }
111
-
112
- // TODO: if we need to keep policies for u&p execution
113
- // Execute the policies.
114
- // if (permission.policy) {
115
- // return await strapi.plugin('users-permissions').policy(permission.policy)(ctx, next);
116
- // }
117
96
  };
118
97
 
119
98
  module.exports = {