@semapps/auth 0.4.0 → 0.4.2-rc.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.sso.js +2 -0
- package/package.json +4 -4
- package/services/auth.local.js +42 -2
package/mixins/auth.sso.js
CHANGED
@@ -69,6 +69,7 @@ const AuthSSOMixin = {
|
|
69
69
|
return [
|
70
70
|
{
|
71
71
|
path: '/auth',
|
72
|
+
name: 'auth',
|
72
73
|
use: [sessionMiddleware, this.passport.initialize(), this.passport.session()],
|
73
74
|
aliases: {
|
74
75
|
'GET /': [saveRedirectUrl, this.passport.authenticate(this.passportId, { session: false }), redirectToFront]
|
@@ -76,6 +77,7 @@ const AuthSSOMixin = {
|
|
76
77
|
},
|
77
78
|
{
|
78
79
|
path: '/auth/logout',
|
80
|
+
name: 'auth-logout',
|
79
81
|
use: [sessionMiddleware, this.passport.initialize(), this.passport.session()],
|
80
82
|
aliases: {
|
81
83
|
'GET /': [saveRedirectUrl, localLogout, redirectToFront]
|
package/package.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "@semapps/auth",
|
3
|
-
"version": "0.4.0",
|
3
|
+
"version": "0.4.2-rc.0",
|
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",
|
9
|
-
"@semapps/triplestore": "0.4.0",
|
8
|
+
"@semapps/mime-types": "0.4.2-rc.0",
|
9
|
+
"@semapps/triplestore": "0.4.2-rc.0",
|
10
10
|
"bcrypt": "^5.0.1",
|
11
11
|
"express-session": "^1.17.0",
|
12
12
|
"jsonwebtoken": "^8.5.1",
|
@@ -25,5 +25,5 @@
|
|
25
25
|
"publishConfig": {
|
26
26
|
"access": "public"
|
27
27
|
},
|
28
|
-
"gitHead": "
|
28
|
+
"gitHead": "9b11bb0e2dc7a9df7222810174f54d944c346764"
|
29
29
|
}
|
package/services/auth.local.js
CHANGED
@@ -14,6 +14,7 @@ const AuthLocalService = {
|
|
14
14
|
reservedUsernames: [],
|
15
15
|
webIdSelection: [],
|
16
16
|
accountSelection: [],
|
17
|
+
formUrl: null,
|
17
18
|
mail: {
|
18
19
|
from: null,
|
19
20
|
transport: {
|
@@ -69,7 +70,25 @@ const AuthLocalService = {
|
|
69
70
|
|
70
71
|
const token = await ctx.call('auth.jwt.generateToken', { payload: { webId: accountData.webId } });
|
71
72
|
|
72
|
-
return { token, webId: accountData.webId, newUser:
|
73
|
+
return { token, webId: accountData.webId, newUser: false };
|
74
|
+
},
|
75
|
+
async logout(ctx) {
|
76
|
+
ctx.meta.$statusCode = 302;
|
77
|
+
ctx.meta.$location = ctx.params.redirectUrl || this.settings.formUrl;
|
78
|
+
},
|
79
|
+
async redirectToForm(ctx) {
|
80
|
+
if (this.settings.formUrl) {
|
81
|
+
const formUrl = new URL(this.settings.formUrl);
|
82
|
+
if (ctx.params) {
|
83
|
+
for (let [key, value] of Object.entries(ctx.params)) {
|
84
|
+
formUrl.searchParams.set(key, value);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
ctx.meta.$statusCode = 302;
|
88
|
+
ctx.meta.$location = formUrl.toString();
|
89
|
+
} else {
|
90
|
+
throw new Error('No formUrl defined in auth.local settings')
|
91
|
+
}
|
73
92
|
},
|
74
93
|
async resetPassword(ctx) {
|
75
94
|
const { email } = ctx.params;
|
@@ -123,27 +142,47 @@ const AuthLocalService = {
|
|
123
142
|
getApiRoutes() {
|
124
143
|
const loginRoute = {
|
125
144
|
path: '/auth/login',
|
145
|
+
name: 'auth-login',
|
126
146
|
use: [this.passport.initialize()],
|
127
147
|
aliases: {
|
128
148
|
'POST /': [this.passport.authenticate(this.passportId, { session: false }), sendToken]
|
129
149
|
}
|
130
150
|
};
|
131
151
|
|
152
|
+
const logoutRoute = {
|
153
|
+
path: '/auth/logout',
|
154
|
+
name: 'auth-logout',
|
155
|
+
aliases: {
|
156
|
+
'GET /': 'auth.logout'
|
157
|
+
}
|
158
|
+
};
|
159
|
+
|
132
160
|
const signupRoute = {
|
133
161
|
path: '/auth/signup',
|
162
|
+
name: 'auth-signup',
|
134
163
|
aliases: {
|
135
164
|
'POST /': 'auth.signup'
|
136
165
|
}
|
137
166
|
};
|
138
167
|
|
168
|
+
const formRoute = {
|
169
|
+
path: '/auth',
|
170
|
+
name: 'auth',
|
171
|
+
aliases: {
|
172
|
+
'GET /': 'auth.redirectToForm'
|
173
|
+
}
|
174
|
+
};
|
175
|
+
|
139
176
|
const resetPasswordRoute = {
|
140
177
|
path: '/auth/reset_password',
|
178
|
+
name: 'auth-reset-password',
|
141
179
|
aliases: {
|
142
180
|
'POST /': 'auth.resetPassword'
|
143
181
|
}
|
144
182
|
};
|
145
183
|
const setNewPasswordRoute = {
|
146
184
|
path: '/auth/new_password',
|
185
|
+
name: 'auth-new-password',
|
147
186
|
aliases: {
|
148
187
|
'POST /': 'auth.setNewPassword'
|
149
188
|
}
|
@@ -151,6 +190,7 @@ const AuthLocalService = {
|
|
151
190
|
|
152
191
|
const accountSettingsRoute = {
|
153
192
|
path: '/auth/account',
|
193
|
+
name: 'auth-account',
|
154
194
|
aliases: {
|
155
195
|
'GET /': 'auth.account.findSettingsByWebId',
|
156
196
|
'POST /': 'auth.account.updateAccountSettings'
|
@@ -158,7 +198,7 @@ const AuthLocalService = {
|
|
158
198
|
authorization: true
|
159
199
|
};
|
160
200
|
|
161
|
-
const routes = [loginRoute, resetPasswordRoute, setNewPasswordRoute, accountSettingsRoute];
|
201
|
+
const routes = [loginRoute, logoutRoute, formRoute, resetPasswordRoute, setNewPasswordRoute, accountSettingsRoute];
|
162
202
|
|
163
203
|
if (this.settings.registrationAllowed) {
|
164
204
|
return [...routes, signupRoute];
|