@semapps/auth 0.4.0-alpha.1 → 0.4.0-alpha.10

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/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@semapps/auth",
3
- "version": "0.4.0-alpha.1",
3
+ "version": "0.4.0-alpha.10",
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.1",
9
- "@semapps/triplestore": "0.4.0-alpha.1",
8
+ "@semapps/mime-types": "0.4.0-alpha.10",
9
+ "@semapps/triplestore": "0.4.0-alpha.10",
10
10
  "bcrypt": "^5.0.1",
11
11
  "express-session": "^1.17.0",
12
12
  "jsonwebtoken": "^8.5.1",
@@ -22,5 +22,5 @@
22
22
  "publishConfig": {
23
23
  "access": "public"
24
24
  },
25
- "gitHead": "9c193459477ead6da089de738945bbcd6a3daf34"
25
+ "gitHead": "b533264851c93b462be916ec97b1edc7dd022687"
26
26
  }
@@ -16,6 +16,8 @@ module.exports = {
16
16
  let { uuid, username, password, email, webId } = ctx.params;
17
17
  const hashedPassword = password ? await this.hashPassword(password) : undefined;
18
18
 
19
+ email = email.toLowerCase();
20
+
19
21
  const emailExists = await ctx.call('auth.account.emailExists', { email });
20
22
  if (emailExists) {
21
23
  throw new Error('email.already.exists');
@@ -54,11 +56,10 @@ module.exports = {
54
56
  async verify(ctx) {
55
57
  const { username, password } = ctx.params;
56
58
 
57
- const accounts = await this._find(ctx, {
58
- query: {
59
- username
60
- }
61
- });
59
+ // If the username includes a @, assume it is an email
60
+ const query = username.includes('@') ? { email: username } : { username };
61
+
62
+ const accounts = await this._find(ctx, { query });
62
63
 
63
64
  if (accounts.length > 0) {
64
65
  const passwordMatch = await this.comparePassword(password, accounts[0].hashedPassword);
@@ -92,7 +93,7 @@ module.exports = {
92
93
  const account = await ctx.call('auth.account.findByWebId', { webId });
93
94
 
94
95
  return await this._update(ctx, {
95
- '@id': account.id,
96
+ '@id': account['@id'],
96
97
  hashedPassword
97
98
  });
98
99
  }
@@ -100,7 +101,7 @@ module.exports = {
100
101
  methods: {
101
102
  async isValidUsername(ctx, username) {
102
103
  // Ensure the username has no space or special characters
103
- if (!/^[a-zA-Z0-9\-_.]+$/.exec(username)) {
104
+ if (!/^[a-z0-9\-_.]+$/.exec(username)) {
104
105
  throw new Error('username.invalid');
105
106
  }
106
107
 
package/services/jwt.js CHANGED
@@ -14,6 +14,9 @@ module.exports = {
14
14
 
15
15
  if (!fs.existsSync(privateKeyPath) && !fs.existsSync(publicKeyPath)) {
16
16
  console.log('JWT keypair not found, generating...');
17
+ if (!fs.existsSync(this.settings.jwtPath)) {
18
+ fs.mkdirSync(this.settings.jwtPath);
19
+ }
17
20
  await this.actions.generateKeyPair({ privateKeyPath, publicKeyPath });
18
21
  }
19
22