@semapps/auth 0.4.0-alpha.13 → 0.4.0-alpha.16
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 +4 -2
- package/mixins/auth.sso.js +9 -5
- package/package.json +5 -5
- package/services/account.js +2 -2
- package/services/auth.local.js +7 -2
- package/services/migration.js +2 -1
package/mixins/auth.js
CHANGED
@@ -24,7 +24,7 @@ const AuthMixin = {
|
|
24
24
|
|
25
25
|
await this.broker.createService(AuthAccountService, {
|
26
26
|
settings: { reservedUsernames },
|
27
|
-
adapter: new TripleStoreAdapter({ type: 'AuthAccount', dataset: accountsDataset })
|
27
|
+
adapter: new TripleStoreAdapter({ type: 'AuthAccount', dataset: accountsDataset })
|
28
28
|
});
|
29
29
|
},
|
30
30
|
async started() {
|
@@ -115,7 +115,9 @@ const AuthMixin = {
|
|
115
115
|
},
|
116
116
|
pickAccountData(data) {
|
117
117
|
if (this.settings.accountSelection.length > 0) {
|
118
|
-
return Object.fromEntries(
|
118
|
+
return Object.fromEntries(
|
119
|
+
this.settings.accountSelection.filter(key => key in data).map(key => [key, data[key]])
|
120
|
+
);
|
119
121
|
} else {
|
120
122
|
return data || {};
|
121
123
|
}
|
package/mixins/auth.sso.js
CHANGED
@@ -32,25 +32,29 @@ const AuthSSOMixin = {
|
|
32
32
|
newUser = false;
|
33
33
|
|
34
34
|
// TODO update account with recent information
|
35
|
-
// await
|
35
|
+
// await ctx.call('webid.edit', profileData, { meta: { webId } });
|
36
36
|
|
37
|
-
|
37
|
+
ctx.emit('auth.connected', { webId, accountData, ssoData }, { meta: { webId: null, dataset: null } });
|
38
38
|
} else {
|
39
39
|
if (!this.settings.registrationAllowed) {
|
40
40
|
throw new Error('registration.not-allowed');
|
41
41
|
}
|
42
42
|
|
43
43
|
accountData = await ctx.call('auth.account.create', { uuid: profileData.uuid, email: profileData.email });
|
44
|
-
webId = await ctx.call('webid.create', { nick: accountData.username, ...profileData });
|
44
|
+
webId = await ctx.call('webid.create', this.pickWebIdData({ nick: accountData.username, ...profileData }));
|
45
45
|
newUser = true;
|
46
46
|
|
47
47
|
// Link the webId with the account
|
48
48
|
await ctx.call('auth.account.attachWebId', { accountUri: accountData['@id'], webId });
|
49
49
|
|
50
|
-
ctx.emit(
|
50
|
+
ctx.emit(
|
51
|
+
'auth.registered',
|
52
|
+
{ webId, profileData, accountData, ssoData },
|
53
|
+
{ meta: { webId: null, dataset: null } }
|
54
|
+
);
|
51
55
|
}
|
52
56
|
|
53
|
-
const token = await ctx.call('auth.jwt.generateToken', { payload: { webId
|
57
|
+
const token = await ctx.call('auth.jwt.generateToken', { payload: { webId } });
|
54
58
|
|
55
59
|
return { token, newUser };
|
56
60
|
}
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@semapps/auth",
|
3
|
-
"version": "0.4.0-alpha.
|
3
|
+
"version": "0.4.0-alpha.16",
|
4
4
|
"description": "Authentification module for SemApps",
|
5
5
|
"license": "Apache-2.0",
|
6
6
|
"author": "Virtual Assembly",
|
7
7
|
"dependencies": {
|
8
|
-
"@semapps/mime-types": "0.4.0-alpha.
|
9
|
-
"@semapps/triplestore": "0.4.0-alpha.
|
8
|
+
"@semapps/mime-types": "0.4.0-alpha.16",
|
9
|
+
"@semapps/triplestore": "0.4.0-alpha.16",
|
10
10
|
"bcrypt": "^5.0.1",
|
11
11
|
"express-session": "^1.17.0",
|
12
12
|
"jsonwebtoken": "^8.5.1",
|
@@ -15,12 +15,12 @@
|
|
15
15
|
"moleculer-web": "^0.10.0-beta1",
|
16
16
|
"openid-client": "^4.7.4",
|
17
17
|
"passport": "^0.4.1",
|
18
|
-
"passport-cas2": "0.0.
|
18
|
+
"passport-cas2": "0.0.12",
|
19
19
|
"passport-local": "^1.0.0",
|
20
20
|
"url-join": "^4.0.1"
|
21
21
|
},
|
22
22
|
"publishConfig": {
|
23
23
|
"access": "public"
|
24
24
|
},
|
25
|
-
"gitHead": "
|
25
|
+
"gitHead": "035fb21fc25fe669392a95e222b76eb54c96a0ed"
|
26
26
|
}
|
package/services/account.js
CHANGED
@@ -16,7 +16,7 @@ module.exports = {
|
|
16
16
|
let { uuid, username, password, email, webId, ...rest } = ctx.params;
|
17
17
|
const hashedPassword = password ? await this.hashPassword(password) : undefined;
|
18
18
|
|
19
|
-
email = email.toLowerCase();
|
19
|
+
email = email && email.toLowerCase();
|
20
20
|
|
21
21
|
const emailExists = await ctx.call('auth.account.emailExists', { email });
|
22
22
|
if (emailExists) {
|
@@ -102,7 +102,7 @@ module.exports = {
|
|
102
102
|
methods: {
|
103
103
|
async isValidUsername(ctx, username) {
|
104
104
|
// Ensure the username has no space or special characters
|
105
|
-
if (!/^[a-z0-9
|
105
|
+
if (!/^[a-z0-9\-+_.]+$/.exec(username)) {
|
106
106
|
throw new Error('username.invalid');
|
107
107
|
}
|
108
108
|
|
package/services/auth.local.js
CHANGED
@@ -12,7 +12,7 @@ const AuthLocalService = {
|
|
12
12
|
registrationAllowed: true,
|
13
13
|
reservedUsernames: [],
|
14
14
|
webIdSelection: [],
|
15
|
-
accountSelection: []
|
15
|
+
accountSelection: []
|
16
16
|
},
|
17
17
|
created() {
|
18
18
|
this.passportId = 'local';
|
@@ -21,7 +21,12 @@ const AuthLocalService = {
|
|
21
21
|
async signup(ctx) {
|
22
22
|
const { username, email, password, ...rest } = ctx.params;
|
23
23
|
|
24
|
-
let accountData = await ctx.call('auth.account.create', {
|
24
|
+
let accountData = await ctx.call('auth.account.create', {
|
25
|
+
username,
|
26
|
+
email,
|
27
|
+
password,
|
28
|
+
...this.pickAccountData(rest)
|
29
|
+
});
|
25
30
|
|
26
31
|
const profileData = { nick: username, email, ...rest };
|
27
32
|
const webId = await ctx.call('webid.create', this.pickWebIdData(profileData));
|
package/services/migration.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
const { MIME_TYPES } = require('@semapps/mime-types');
|
2
|
+
const { getSlugFromUri } = require('@semapps/ldp');
|
2
3
|
|
3
4
|
module.exports = {
|
4
5
|
name: 'auth.migration',
|
@@ -13,7 +14,7 @@ module.exports = {
|
|
13
14
|
try {
|
14
15
|
await ctx.call('auth.account.create', {
|
15
16
|
email: user[emailPredicate],
|
16
|
-
username: user[usernamePredicate],
|
17
|
+
username: usernamePredicate ? user[usernamePredicate] : getSlugFromUri(user.id),
|
17
18
|
webId: user.id
|
18
19
|
});
|
19
20
|
} catch (e) {
|