@semapps/auth 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
package/mixins/auth.js CHANGED
@@ -19,7 +19,7 @@ const AuthMixin = {
19
19
  accountsDataset: 'settings',
20
20
  podProvider: false
21
21
  },
22
- dependencies: ['api', 'webid'],
22
+ dependencies: ['api'],
23
23
  async created() {
24
24
  const { jwtPath, reservedUsernames, accountsDataset, podProvider } = this.settings;
25
25
 
@@ -33,8 +33,7 @@ const AuthSSOMixin = {
33
33
  webId = accountData.webId;
34
34
  newUser = false;
35
35
 
36
- // TODO update account with recent information
37
- // await ctx.call('webid.edit', profileData, { meta: { webId } });
36
+ // TODO update account with recent profileData information
38
37
 
39
38
  ctx.emit('auth.connected', { webId, accountData, ssoData }, { meta: { webId: null, dataset: null } });
40
39
  } else {
@@ -47,7 +46,7 @@ const AuthSSOMixin = {
47
46
  email: profileData.email,
48
47
  username: profileData.username
49
48
  });
50
- webId = await ctx.call('webid.create', this.pickWebIdData({ nick: accountData.username, ...profileData }));
49
+ webId = await ctx.call('webid.createWebId', this.pickWebIdData({ nick: accountData.username, ...profileData }));
51
50
  newUser = true;
52
51
 
53
52
  // Link the webId with the account
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@semapps/auth",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Authentification module for SemApps",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Virtual Assembly",
7
7
  "dependencies": {
8
- "@semapps/ldp": "0.7.0",
9
- "@semapps/middlewares": "0.7.0",
10
- "@semapps/mime-types": "0.7.0",
11
- "@semapps/triplestore": "0.7.0",
8
+ "@semapps/ldp": "0.8.0",
9
+ "@semapps/middlewares": "0.8.0",
10
+ "@semapps/mime-types": "0.8.0",
11
+ "@semapps/triplestore": "0.8.0",
12
12
  "bcrypt": "^5.0.1",
13
13
  "express-session": "^1.17.0",
14
14
  "jsonwebtoken": "^8.5.1",
@@ -29,5 +29,5 @@
29
29
  "engines": {
30
30
  "node": ">=14"
31
31
  },
32
- "gitHead": "793f935c61e5f4e87ac17ee1dd41a968f12678b4"
32
+ "gitHead": "9ab99a4751d5240ec9d6df985bf00dc21c348ef4"
33
33
  }
@@ -88,6 +88,12 @@ module.exports = {
88
88
  const accounts = await this._find(ctx, { query: { email } });
89
89
  return accounts.length > 0;
90
90
  },
91
+ /** Overwrite find method, to filter accounts with tombstone. */
92
+ async find(ctx) {
93
+ /** @type {object[]} */
94
+ const accounts = await this._find(ctx, ctx.params);
95
+ return accounts.filter(account => !account.deletedAt);
96
+ },
91
97
  async findByUsername(ctx) {
92
98
  const { username } = ctx.params;
93
99
  const accounts = await this._find(ctx, { query: { username } });
@@ -184,6 +190,34 @@ module.exports = {
184
190
  '@id': account['@id'],
185
191
  ...params
186
192
  });
193
+ },
194
+ async deleteByWebId(ctx) {
195
+ const { webId } = ctx.params;
196
+ const account = await ctx.call('auth.account.findByWebId', { webId });
197
+
198
+ if (account) {
199
+ await this._remove(ctx, { id: account['@id'] });
200
+ return true;
201
+ }
202
+
203
+ return false;
204
+ },
205
+ // Remove email and password from an account, set deletedAt timestamp.
206
+ async setTombstone(ctx) {
207
+ const { webId } = ctx.params;
208
+ const account = await ctx.call('auth.account.findByWebId', { webId });
209
+
210
+ return await this._update(ctx, {
211
+ // Set all values to undefined...
212
+ ...Object.fromEntries(Object.keys(account).map(key => [key, null])),
213
+ '@id': account['@id'],
214
+ // ...except for
215
+ webId: account.webId,
216
+ username: account.username,
217
+ podUri: account.podUri,
218
+ // And add a deletedAt date.
219
+ deletedAt: new Date().toISOString()
220
+ });
187
221
  }
188
222
  },
189
223
  methods: {
@@ -4,6 +4,7 @@ const sendToken = require('../middlewares/sendToken');
4
4
  const { MoleculerError } = require('moleculer').Errors;
5
5
  const AuthMailService = require('./mail');
6
6
 
7
+ /** @type {import('moleculer').ServiceSchema} */
7
8
  const AuthLocalService = {
8
9
  name: 'auth',
9
10
  mixins: [AuthMixin],
@@ -27,6 +28,7 @@ const AuthLocalService = {
27
28
  }
28
29
  }
29
30
  },
31
+ dependencies: ['webid'],
30
32
  async created() {
31
33
  const { mail } = this.settings;
32
34
 
@@ -43,6 +45,8 @@ const AuthLocalService = {
43
45
  actions: {
44
46
  async signup(ctx) {
45
47
  const { username, email, password, interactionId, ...rest } = ctx.params;
48
+ // This is going to get in our way otherwise when waiting for completions.
49
+ ctx.meta.skipObjectsWatcher = true;
46
50
 
47
51
  if (username && username.length < 2) {
48
52
  throw new Error('The username must be at least 2 characters long');
@@ -56,7 +60,7 @@ const AuthLocalService = {
56
60
  });
57
61
 
58
62
  const profileData = { nick: username, email, ...rest };
59
- const webId = await ctx.call('webid.create', this.pickWebIdData(profileData));
63
+ const webId = await ctx.call('webid.createWebId', this.pickWebIdData(profileData));
60
64
 
61
65
  // Link the webId with the account
62
66
  accountData = await ctx.call('auth.account.attachWebId', { accountUri: accountData['@id'], webId });