@semapps/auth 0.4.0-alpha.12 → 0.4.0-alpha.15

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 CHANGED
@@ -11,6 +11,7 @@ const AuthMixin = {
11
11
  registrationAllowed: true,
12
12
  reservedUsernames: [],
13
13
  webIdSelection: [],
14
+ accountSelection: [],
14
15
  accountsDataset: 'settings'
15
16
  },
16
17
  dependencies: ['api', 'webid'],
@@ -23,7 +24,7 @@ const AuthMixin = {
23
24
 
24
25
  await this.broker.createService(AuthAccountService, {
25
26
  settings: { reservedUsernames },
26
- adapter: new TripleStoreAdapter({ type: 'AuthAccount', dataset: accountsDataset }),
27
+ adapter: new TripleStoreAdapter({ type: 'AuthAccount', dataset: accountsDataset })
27
28
  });
28
29
  },
29
30
  async started() {
@@ -111,6 +112,15 @@ const AuthMixin = {
111
112
  } else {
112
113
  return data;
113
114
  }
115
+ },
116
+ pickAccountData(data) {
117
+ if (this.settings.accountSelection.length > 0) {
118
+ return Object.fromEntries(
119
+ this.settings.accountSelection.filter(key => key in data).map(key => [key, data[key]])
120
+ );
121
+ } else {
122
+ return data || {};
123
+ }
114
124
  }
115
125
  }
116
126
  };
@@ -32,9 +32,9 @@ const AuthSSOMixin = {
32
32
  newUser = false;
33
33
 
34
34
  // TODO update account with recent information
35
- // await this.broker.call('webid.edit', profileData, { meta: { webId } });
35
+ // await ctx.call('webid.edit', profileData, { meta: { webId } });
36
36
 
37
- await this.broker.emit('auth.connected', { webId, accountData });
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');
@@ -47,10 +47,14 @@ const AuthSSOMixin = {
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('auth.registered', { webId, profileData, accountData }, { meta: { webId: null, dataset: null } });
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: accountData.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.12",
3
+ "version": "0.4.0-alpha.15",
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.12",
9
- "@semapps/triplestore": "0.4.0-alpha.12",
8
+ "@semapps/mime-types": "0.4.0-alpha.15",
9
+ "@semapps/triplestore": "0.4.0-alpha.15",
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.11",
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": "69f22b8c24503034a70fcefe452cede38b09a2cd"
25
+ "gitHead": "75e6cd77cd24f51cf6f83046b8a0c73461a8112c"
26
26
  }
@@ -13,7 +13,7 @@ module.exports = {
13
13
  dependencies: ['triplestore'],
14
14
  actions: {
15
15
  async create(ctx) {
16
- let { uuid, username, password, email, webId } = ctx.params;
16
+ let { uuid, username, password, email, webId, ...rest } = ctx.params;
17
17
  const hashedPassword = password ? await this.hashPassword(password) : undefined;
18
18
 
19
19
  email = email.toLowerCase();
@@ -38,6 +38,7 @@ module.exports = {
38
38
  }
39
39
 
40
40
  return await this._create(ctx, {
41
+ ...rest,
41
42
  uuid,
42
43
  username,
43
44
  email,
@@ -11,18 +11,24 @@ const AuthLocalService = {
11
11
  jwtPath: null,
12
12
  registrationAllowed: true,
13
13
  reservedUsernames: [],
14
- webIdSelection: []
14
+ webIdSelection: [],
15
+ accountSelection: []
15
16
  },
16
17
  created() {
17
18
  this.passportId = 'local';
18
19
  },
19
20
  actions: {
20
21
  async signup(ctx) {
21
- const { username, email, password, ...otherData } = ctx.params;
22
+ const { username, email, password, ...rest } = ctx.params;
22
23
 
23
- let accountData = await ctx.call('auth.account.create', { username, email, password });
24
+ let accountData = await ctx.call('auth.account.create', {
25
+ username,
26
+ email,
27
+ password,
28
+ ...this.pickAccountData(rest)
29
+ });
24
30
 
25
- const profileData = { nick: username, email, ...otherData };
31
+ const profileData = { nick: username, email, ...rest };
26
32
  const webId = await ctx.call('webid.create', this.pickWebIdData(profileData));
27
33
 
28
34
  // Link the webId with the account
@@ -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) {