@semapps/auth 0.7.0 → 0.8.0
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/mixins/auth.js +1 -1
- package/mixins/auth.sso.js +2 -3
- package/package.json +6 -6
- package/services/account.js +34 -0
- package/services/auth.local.js +5 -1
package/mixins/auth.js
CHANGED
package/mixins/auth.sso.js
CHANGED
@@ -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.
|
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.
|
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.
|
9
|
-
"@semapps/middlewares": "0.
|
10
|
-
"@semapps/mime-types": "0.
|
11
|
-
"@semapps/triplestore": "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": "
|
32
|
+
"gitHead": "9ab99a4751d5240ec9d6df985bf00dc21c348ef4"
|
33
33
|
}
|
package/services/account.js
CHANGED
@@ -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: {
|
package/services/auth.local.js
CHANGED
@@ -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.
|
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 });
|