@semapps/auth 0.4.0-alpha.11 → 0.4.0-alpha.14

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
@@ -1,7 +1,8 @@
1
+ const passport = require('passport');
2
+ const { Errors: E } = require('moleculer-web');
3
+ const { TripleStoreAdapter } = require('@semapps/triplestore');
1
4
  const AuthAccountService = require('../services/account');
2
5
  const AuthJWTService = require('../services/jwt');
3
- const { Errors: E } = require('moleculer-web');
4
- const passport = require('passport');
5
6
 
6
7
  const AuthMixin = {
7
8
  settings: {
@@ -9,18 +10,21 @@ const AuthMixin = {
9
10
  jwtPath: null,
10
11
  registrationAllowed: true,
11
12
  reservedUsernames: [],
12
- webIdSelection: []
13
+ webIdSelection: [],
14
+ accountSelection: [],
15
+ accountsDataset: 'settings'
13
16
  },
14
17
  dependencies: ['api', 'webid'],
15
18
  async created() {
16
- const { jwtPath, reservedUsernames } = this.settings;
19
+ const { jwtPath, reservedUsernames, accountsDataset } = this.settings;
17
20
 
18
21
  await this.broker.createService(AuthJWTService, {
19
22
  settings: { jwtPath }
20
23
  });
21
24
 
22
25
  await this.broker.createService(AuthAccountService, {
23
- settings: { reservedUsernames }
26
+ settings: { reservedUsernames },
27
+ adapter: new TripleStoreAdapter({ type: 'AuthAccount', dataset: accountsDataset })
24
28
  });
25
29
  },
26
30
  async started() {
@@ -108,6 +112,15 @@ const AuthMixin = {
108
112
  } else {
109
113
  return data;
110
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
+ }
111
124
  }
112
125
  }
113
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,10 @@ 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('auth.registered', { webId, profileData, accountData, ssoData }, { meta: { webId: null, dataset: null } });
51
51
  }
52
52
 
53
- const token = await ctx.call('auth.jwt.generateToken', { payload: { webId: accountData.webId } });
53
+ const token = await ctx.call('auth.jwt.generateToken', { payload: { webId } });
54
54
 
55
55
  return { token, newUser };
56
56
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@semapps/auth",
3
- "version": "0.4.0-alpha.11",
3
+ "version": "0.4.0-alpha.14",
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.11",
9
- "@semapps/triplestore": "0.4.0-alpha.11",
8
+ "@semapps/mime-types": "0.4.0-alpha.14",
9
+ "@semapps/triplestore": "0.4.0-alpha.14",
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": "fe2f720f4685e29be79bcf18d139611de5037919"
25
+ "gitHead": "d84cc686bf0a0404a94cefe9d8b5828a058659da"
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