@webda/core 4.0.0-beta.3 → 4.0.0-beta.4
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/lib/application/application.d.ts +31 -0
- package/lib/application/application.d.ts.map +1 -1
- package/lib/application/application.js +55 -2
- package/lib/application/application.js.map +1 -1
- package/lib/application/deployment.d.ts +93 -0
- package/lib/application/deployment.d.ts.map +1 -0
- package/lib/application/deployment.js +99 -0
- package/lib/application/deployment.js.map +1 -0
- package/lib/application/unpackedapplication.d.ts.map +1 -1
- package/lib/application/unpackedapplication.js +9 -1
- package/lib/application/unpackedapplication.js.map +1 -1
- package/lib/bin/cli.d.ts +36 -1
- package/lib/bin/cli.d.ts.map +1 -1
- package/lib/bin/cli.js +108 -2
- package/lib/bin/cli.js.map +1 -1
- package/lib/contexts/execution.js +1 -1
- package/lib/contexts/execution.js.map +1 -1
- package/lib/contexts/operationcontext.d.ts +3 -0
- package/lib/contexts/operationcontext.d.ts.map +1 -1
- package/lib/contexts/operationcontext.js +6 -3
- package/lib/contexts/operationcontext.js.map +1 -1
- package/lib/core/core.js +1 -1
- package/lib/core/core.js.map +1 -1
- package/lib/core/hooks.d.ts +22 -0
- package/lib/core/hooks.d.ts.map +1 -1
- package/lib/core/hooks.js +24 -0
- package/lib/core/hooks.js.map +1 -1
- package/lib/deployers/deployer.d.ts +157 -0
- package/lib/deployers/deployer.d.ts.map +1 -0
- package/lib/deployers/deployer.js +81 -0
- package/lib/deployers/deployer.js.map +1 -0
- package/lib/deployers/git.d.ts +27 -0
- package/lib/deployers/git.d.ts.map +1 -0
- package/lib/deployers/git.js +66 -0
- package/lib/deployers/git.js.map +1 -0
- package/lib/deployers/packager.d.ts +85 -0
- package/lib/deployers/packager.d.ts.map +1 -0
- package/lib/deployers/packager.js +259 -0
- package/lib/deployers/packager.js.map +1 -0
- package/lib/index.d.ts +8 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -3
- package/lib/index.js.map +1 -1
- package/lib/models/coremodel.model.d.ts.map +1 -1
- package/lib/models/coremodel.model.js.map +1 -1
- package/lib/models/decorator.d.ts +4 -0
- package/lib/models/decorator.d.ts.map +1 -1
- package/lib/models/decorator.js +4 -0
- package/lib/models/decorator.js.map +1 -1
- package/lib/models/deployment.d.ts +2 -21
- package/lib/models/deployment.d.ts.map +1 -1
- package/lib/models/encrypted.model.d.ts +46 -0
- package/lib/models/encrypted.model.d.ts.map +1 -0
- package/lib/models/encrypted.model.js +87 -0
- package/lib/models/encrypted.model.js.map +1 -0
- package/lib/models/ident.model.d.ts +103 -64
- package/lib/models/ident.model.d.ts.map +1 -1
- package/lib/models/ident.model.js +168 -76
- package/lib/models/ident.model.js.map +1 -1
- package/lib/models/ownermodel.model.d.ts.map +1 -1
- package/lib/models/ownermodel.model.js +2 -1
- package/lib/models/ownermodel.model.js.map +1 -1
- package/lib/models/password.model.d.ts +78 -0
- package/lib/models/password.model.d.ts.map +1 -0
- package/lib/models/password.model.js +171 -0
- package/lib/models/password.model.js.map +1 -0
- package/lib/models/refreshtoken.model.d.ts +30 -0
- package/lib/models/refreshtoken.model.d.ts.map +1 -0
- package/lib/models/refreshtoken.model.js +29 -0
- package/lib/models/refreshtoken.model.js.map +1 -0
- package/lib/models/registry.model.d.ts.map +1 -1
- package/lib/models/registry.model.js.map +1 -1
- package/lib/models/simpleuser.model.d.ts.map +1 -1
- package/lib/models/simpleuser.model.js +2 -1
- package/lib/models/simpleuser.model.js.map +1 -1
- package/lib/models/user.model.d.ts +23 -23
- package/lib/models/user.model.d.ts.map +1 -1
- package/lib/models/user.model.js +68 -29
- package/lib/models/user.model.js.map +1 -1
- package/lib/services/audit.model.d.ts.map +1 -1
- package/lib/services/audit.model.js +2 -1
- package/lib/services/audit.model.js.map +1 -1
- package/lib/services/domainservice.service.d.ts +39 -0
- package/lib/services/domainservice.service.d.ts.map +1 -1
- package/lib/services/domainservice.service.js +78 -2
- package/lib/services/domainservice.service.js.map +1 -1
- package/lib/services/iauthentication.d.ts +196 -3
- package/lib/services/iauthentication.d.ts.map +1 -1
- package/lib/services/servicecommands.d.ts.map +1 -1
- package/lib/services/servicecommands.js +17 -11
- package/lib/services/servicecommands.js.map +1 -1
- package/lib/services/token.service.d.ts +95 -0
- package/lib/services/token.service.d.ts.map +1 -0
- package/lib/services/token.service.js +182 -0
- package/lib/services/token.service.js.map +1 -0
- package/lib/session/manager.model.d.ts +16 -0
- package/lib/session/manager.model.d.ts.map +1 -1
- package/lib/session/manager.model.js +58 -1
- package/lib/session/manager.model.js.map +1 -1
- package/lib/session/session.d.ts +44 -1
- package/lib/session/session.d.ts.map +1 -1
- package/lib/session/session.js +51 -2
- package/lib/session/session.js.map +1 -1
- package/lib/stores/memory.service.d.ts.map +1 -1
- package/lib/stores/memory.service.js +4 -3
- package/lib/stores/memory.service.js.map +1 -1
- package/lib/templates/templates.d.ts +8 -0
- package/lib/templates/templates.d.ts.map +1 -1
- package/lib/templates/templates.js +10 -1
- package/lib/templates/templates.js.map +1 -1
- package/lib/test/behavior-fixture.model.d.ts +30 -0
- package/lib/test/behavior-fixture.model.d.ts.map +1 -0
- package/lib/test/behavior-fixture.model.js +63 -0
- package/lib/test/behavior-fixture.model.js.map +1 -0
- package/lib/test/legacyident.fixture.model.d.ts +98 -0
- package/lib/test/legacyident.fixture.model.d.ts.map +1 -0
- package/lib/test/legacyident.fixture.model.js +125 -0
- package/lib/test/legacyident.fixture.model.js.map +1 -0
- package/lib/test/objects.d.ts +2 -2
- package/lib/test/objects.d.ts.map +1 -1
- package/lib/test/objects.js +2 -2
- package/lib/test/objects.js.map +1 -1
- package/package.json +25 -8
- package/test/config-cached.json +2 -1
- package/test/config.json +3 -1
- package/test/my-cnf.json +1 -1
- package/webda.module.json +653 -375
- package/lib/services/authentication.service.d.ts +0 -442
- package/lib/services/authentication.service.d.ts.map +0 -1
- package/lib/services/authentication.service.js +0 -932
- package/lib/services/authentication.service.js.map +0 -1
- package/lib/services/oauth.d.ts +0 -250
- package/lib/services/oauth.d.ts.map +0 -1
- package/lib/services/oauth.js +0 -405
- package/lib/services/oauth.js.map +0 -1
package/lib/services/oauth.js
DELETED
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
-
var useValue = arguments.length > 2;
|
|
3
|
-
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
-
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
-
}
|
|
6
|
-
return useValue ? value : void 0;
|
|
7
|
-
};
|
|
8
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
-
var _, done = false;
|
|
14
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
-
var context = {};
|
|
16
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
-
if (kind === "accessor") {
|
|
21
|
-
if (result === void 0) continue;
|
|
22
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
-
}
|
|
27
|
-
else if (_ = accept(result)) {
|
|
28
|
-
if (kind === "field") initializers.unshift(_);
|
|
29
|
-
else descriptor[key] = _;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
-
done = true;
|
|
34
|
-
};
|
|
35
|
-
import * as WebdaError from "../errors/errors.js";
|
|
36
|
-
import { Service } from "./service.js";
|
|
37
|
-
import { getUuid } from "@webda/utils";
|
|
38
|
-
import { Route } from "../rest/irest.js";
|
|
39
|
-
import { Counter } from "../metrics/metrics.js";
|
|
40
|
-
import { RegExpStringValidator } from "@webda/utils";
|
|
41
|
-
import { ServiceParameters } from "../services/serviceparameters.js";
|
|
42
|
-
import { useService } from "../core/hooks.js";
|
|
43
|
-
/** Parameters for OAuth services including client credentials, scopes, and redirect URIs */
|
|
44
|
-
export class OAuthServiceParameters extends ServiceParameters {
|
|
45
|
-
/**
|
|
46
|
-
* Scope to request on OAuth flow
|
|
47
|
-
*
|
|
48
|
-
* @defaut ["email"]
|
|
49
|
-
*/
|
|
50
|
-
scope;
|
|
51
|
-
/**
|
|
52
|
-
* If set to true it will add a ${url}/scope
|
|
53
|
-
* So client can anticipate the requested scope
|
|
54
|
-
*
|
|
55
|
-
* This is useful when using the client api to generate
|
|
56
|
-
* token. This way the service can request the wanted scope
|
|
57
|
-
*
|
|
58
|
-
* @default false
|
|
59
|
-
*/
|
|
60
|
-
exposeScope;
|
|
61
|
-
/**
|
|
62
|
-
* List of URIs authorized for redirect post authorization
|
|
63
|
-
*
|
|
64
|
-
* @default []
|
|
65
|
-
*/
|
|
66
|
-
authorized_uris;
|
|
67
|
-
/**
|
|
68
|
-
* Default redirect_uri
|
|
69
|
-
*
|
|
70
|
-
* @default ${url}/callback
|
|
71
|
-
*/
|
|
72
|
-
redirect_uri;
|
|
73
|
-
/**
|
|
74
|
-
* Allow direct connection without a referer
|
|
75
|
-
*
|
|
76
|
-
* @default false
|
|
77
|
-
*/
|
|
78
|
-
no_referer;
|
|
79
|
-
/**
|
|
80
|
-
* Name of the authentication service to use if exist
|
|
81
|
-
* @default Authentication
|
|
82
|
-
*/
|
|
83
|
-
authenticationService;
|
|
84
|
-
/**
|
|
85
|
-
* Load parameters with defaults for scopes, auth service, and URI settings
|
|
86
|
-
* @param params - the service parameters
|
|
87
|
-
* @returns the result
|
|
88
|
-
*/
|
|
89
|
-
load(params) {
|
|
90
|
-
super.load(params);
|
|
91
|
-
this.scope ??= ["email"];
|
|
92
|
-
this.exposeScope ??= false;
|
|
93
|
-
this.authenticationService ??= "Authentication";
|
|
94
|
-
this.authorized_uris ??= [];
|
|
95
|
-
this.no_referer ??= false;
|
|
96
|
-
return this;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* OAuth service implementing the default OAuth workflow
|
|
101
|
-
* It is abstract as it does not manage any provider as is
|
|
102
|
-
*/
|
|
103
|
-
let OAuthService = (() => {
|
|
104
|
-
let _classSuper = Service;
|
|
105
|
-
let _instanceExtraInitializers = [];
|
|
106
|
-
let __redirect_decorators;
|
|
107
|
-
return class OAuthService extends _classSuper {
|
|
108
|
-
static {
|
|
109
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
110
|
-
__redirect_decorators = [Route(".{?redirect?}", ["GET"], {
|
|
111
|
-
get: {
|
|
112
|
-
description: "Log with a ${name} account",
|
|
113
|
-
summary: "Redirect to ${name}",
|
|
114
|
-
operationId: "logInWith${name}",
|
|
115
|
-
responses: {
|
|
116
|
-
"302": { description: "" },
|
|
117
|
-
"400": { description: "Missing token" }
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
})];
|
|
121
|
-
__esDecorate(this, null, __redirect_decorators, { kind: "method", name: "_redirect", static: false, private: false, access: { has: obj => "_redirect" in obj, get: obj => obj._redirect }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
122
|
-
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
123
|
-
}
|
|
124
|
-
_authenticationService = __runInitializers(this, _instanceExtraInitializers);
|
|
125
|
-
authorized_uris;
|
|
126
|
-
/**
|
|
127
|
-
* Ensure default parameter url
|
|
128
|
-
* @param name - the service name
|
|
129
|
-
* @param params - the service parameters
|
|
130
|
-
*/
|
|
131
|
-
constructor(name, params) {
|
|
132
|
-
super(name, params);
|
|
133
|
-
this.parameters.url ??= this.getDefaultUrl();
|
|
134
|
-
}
|
|
135
|
-
/** Initialize OAuth-specific metrics for tracking logins */
|
|
136
|
-
initMetrics() {
|
|
137
|
-
super.initMetrics();
|
|
138
|
-
this.metrics.login = this.getMetric(Counter, {
|
|
139
|
-
name: "oauth_login",
|
|
140
|
-
help: "count the number of login",
|
|
141
|
-
labelNames: ["method"]
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Allow callback referer to access this url no matter what
|
|
146
|
-
* @param context - the execution context
|
|
147
|
-
* @returns true if the condition is met
|
|
148
|
-
*/
|
|
149
|
-
async checkRequest(context) {
|
|
150
|
-
// Only authorize url from this service
|
|
151
|
-
if (!context.getHttpContext().getRelativeUri().startsWith(this.parameters.url)) {
|
|
152
|
-
return false;
|
|
153
|
-
}
|
|
154
|
-
const regexps = this.getCallbackReferer();
|
|
155
|
-
let valid = false;
|
|
156
|
-
const referer = context.getHttpContext().getUniqueHeader("referer", "");
|
|
157
|
-
if (this.parameters.no_referer && referer === "") {
|
|
158
|
-
return true;
|
|
159
|
-
}
|
|
160
|
-
for (const i in regexps) {
|
|
161
|
-
valid = referer.match(regexps[i]) !== null;
|
|
162
|
-
if (valid) {
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return valid;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Resolve dynamic dependancy
|
|
170
|
-
* @returns this for chaining
|
|
171
|
-
*/
|
|
172
|
-
resolve() {
|
|
173
|
-
super.resolve();
|
|
174
|
-
this.parameters.with(params => {
|
|
175
|
-
if (params.url === undefined) {
|
|
176
|
-
params.url = this.getDefaultUrl();
|
|
177
|
-
}
|
|
178
|
-
if (params.authorized_uris === undefined) {
|
|
179
|
-
this.log("WARN", "Not defining authorized_uris is a security risk");
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
this.authorized_uris = new RegExpStringValidator(params.authorized_uris);
|
|
183
|
-
}
|
|
184
|
-
this._authenticationService = useService(this.parameters.authenticationService);
|
|
185
|
-
});
|
|
186
|
-
return this;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Get OAuth callback query parameters
|
|
190
|
-
* @returns the result
|
|
191
|
-
*/
|
|
192
|
-
getCallbackQueryParams() {
|
|
193
|
-
return [
|
|
194
|
-
{
|
|
195
|
-
name: "code",
|
|
196
|
-
required: true
|
|
197
|
-
},
|
|
198
|
-
{
|
|
199
|
-
name: "scope",
|
|
200
|
-
required: true
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
name: "state",
|
|
204
|
-
required: true
|
|
205
|
-
}
|
|
206
|
-
];
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Register callback + optional token/scope routes.
|
|
210
|
-
*
|
|
211
|
-
* `_redirect` is declared via `@Route` below. The callback query string
|
|
212
|
-
* depends on {@link getCallbackQueryParams} (subclass-overridable), and
|
|
213
|
-
* the token/scope routes are conditional on {@link hasToken} and
|
|
214
|
-
* `parameters.exposeScope`, so those three stay programmatic.
|
|
215
|
-
*
|
|
216
|
-
* @returns this for chaining
|
|
217
|
-
*/
|
|
218
|
-
async init() {
|
|
219
|
-
await super.init();
|
|
220
|
-
const name = this.getName();
|
|
221
|
-
this.addRoute(this.parameters.url +
|
|
222
|
-
"/callback{?" +
|
|
223
|
-
this.getCallbackQueryParams()
|
|
224
|
-
.map(param => param.name + (param.required ? "" : "?"))
|
|
225
|
-
.join(",") +
|
|
226
|
-
"}", ["GET"], this._callback, {
|
|
227
|
-
get: {
|
|
228
|
-
description: `Get result from ${name} Authentication`,
|
|
229
|
-
summary: `Use the token provide to validate with ${name} the user`,
|
|
230
|
-
operationId: `callbackFrom${name}`,
|
|
231
|
-
responses: {
|
|
232
|
-
"204": {
|
|
233
|
-
description: ""
|
|
234
|
-
},
|
|
235
|
-
"400": {
|
|
236
|
-
description: "Missing token"
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
if (this.hasToken()) {
|
|
242
|
-
this.addRoute(this.parameters.url + "/token", ["POST"], this._token, {
|
|
243
|
-
post: {
|
|
244
|
-
description: `Log with a ${name} token`,
|
|
245
|
-
summary: `Use the token provide to validate with ${name} the user`,
|
|
246
|
-
operationId: `verify${name}Token`,
|
|
247
|
-
responses: {
|
|
248
|
-
"204": {
|
|
249
|
-
description: ""
|
|
250
|
-
},
|
|
251
|
-
"400": {
|
|
252
|
-
description: "Missing token"
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
if (this.parameters.exposeScope) {
|
|
259
|
-
this.addRoute(this.parameters.url + "/scope", ["GET"], this._scope, {
|
|
260
|
-
get: {
|
|
261
|
-
description: `List ${name} auth scope for this apps`,
|
|
262
|
-
summary: "Retrieve the scope intended to be used with this auth",
|
|
263
|
-
operationId: `get${name}Scope`,
|
|
264
|
-
responses: {
|
|
265
|
-
"204": {
|
|
266
|
-
description: ""
|
|
267
|
-
},
|
|
268
|
-
"400": {
|
|
269
|
-
description: "Missing token"
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
return this;
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Expose the scope used by the authentication
|
|
279
|
-
* @param ctx - the operation context
|
|
280
|
-
*/
|
|
281
|
-
_scope(ctx) {
|
|
282
|
-
ctx.write(this.parameters.scope);
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Define if this provider allow authentication by tokens
|
|
286
|
-
* @returns true if the condition is met
|
|
287
|
-
*/
|
|
288
|
-
hasToken() {
|
|
289
|
-
return false;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Check if the url is authorized
|
|
293
|
-
* @param redirect - the redirect URL
|
|
294
|
-
* @param context - the execution context
|
|
295
|
-
* @returns true if the condition is met
|
|
296
|
-
*/
|
|
297
|
-
isAuthorizedUri(redirect, context) {
|
|
298
|
-
return (!this.parameters.authorized_uris || // If no authorized_uris defined, allow all
|
|
299
|
-
this.authorized_uris?.validate(redirect) || // If redirect is included in authorized_uris
|
|
300
|
-
(this.parameters.no_referer && !context.getHttpContext().getUniqueHeader("referer"))); // If no_referer is allowed
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Inject the provider name into openapi template replacements so the
|
|
304
|
-
* `${name}` placeholders in `@Route` metadata resolve per-instance.
|
|
305
|
-
*
|
|
306
|
-
* @returns replacements map merged with defaults
|
|
307
|
-
*/
|
|
308
|
-
getOpenApiReplacements() {
|
|
309
|
-
return { ...super.getOpenApiReplacements(), name: this.getName() };
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Redirect to the OAuth provider
|
|
313
|
-
*
|
|
314
|
-
* The calling url must be and authorized_uris if defined
|
|
315
|
-
* @param ctx - the operation context
|
|
316
|
-
*/
|
|
317
|
-
_redirect(ctx) {
|
|
318
|
-
// implement default behavior
|
|
319
|
-
const redirect_uri = this.parameters.redirect_uri || `${ctx.getHttpContext().getAbsoluteUrl()}/callback`;
|
|
320
|
-
const redirect = ctx.getParameters().redirect || ctx.getHttpContext().getHeaders().referer;
|
|
321
|
-
if (!this.isAuthorizedUri(redirect, ctx)) {
|
|
322
|
-
throw new WebdaError.Unauthorized("Unauthorized redirect parameter");
|
|
323
|
-
}
|
|
324
|
-
const session = ctx.getSession();
|
|
325
|
-
session.oauth ??= {};
|
|
326
|
-
// Generate 2 random uuid: nonce and state
|
|
327
|
-
session.oauth.state = getUuid("base64");
|
|
328
|
-
// Redirect to the calling uri
|
|
329
|
-
session.oauth.redirect = redirect;
|
|
330
|
-
ctx.redirect(this.generateAuthUrl(redirect_uri, session.oauth.state, ctx));
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Handle a token return
|
|
334
|
-
*
|
|
335
|
-
* This is private to avoid any override
|
|
336
|
-
* @param context - the execution context
|
|
337
|
-
*/
|
|
338
|
-
async _token(context) {
|
|
339
|
-
const res = await this.handleToken(context);
|
|
340
|
-
await this.handleReturn(context, res.identId, res.profile);
|
|
341
|
-
await this.emit("OAuth.Callback", {
|
|
342
|
-
...res,
|
|
343
|
-
type: "token",
|
|
344
|
-
provider: this.getName(),
|
|
345
|
-
context
|
|
346
|
-
});
|
|
347
|
-
this.metrics.login.inc({ method: "token" });
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Handle a standard url callback
|
|
351
|
-
*
|
|
352
|
-
* This is private to avoid any override
|
|
353
|
-
* @param ctx - the operation context
|
|
354
|
-
*/
|
|
355
|
-
async _callback(ctx) {
|
|
356
|
-
const res = await this.handleCallback(ctx);
|
|
357
|
-
await this.handleReturn(ctx, res.identId, res.profile);
|
|
358
|
-
await this.emit("OAuth.Callback", {
|
|
359
|
-
...res,
|
|
360
|
-
type: "callback",
|
|
361
|
-
provider: this.getName(),
|
|
362
|
-
context: ctx
|
|
363
|
-
});
|
|
364
|
-
this.metrics.login.inc({ method: "callback" });
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Once approved by the OAuth provider this will do the common task
|
|
368
|
-
* @param ctx - the operation context
|
|
369
|
-
* @param identId - the identity identifier
|
|
370
|
-
* @param profile - the user profile
|
|
371
|
-
* @param _tokens - the authentication tokens
|
|
372
|
-
*/
|
|
373
|
-
async handleReturn(ctx, identId, profile, _tokens = undefined) {
|
|
374
|
-
// If no identId has been provided error
|
|
375
|
-
if (!identId) {
|
|
376
|
-
throw new WebdaError.Forbidden("No identId provided by the OAuth provider");
|
|
377
|
-
}
|
|
378
|
-
const session = ctx.getSession();
|
|
379
|
-
session.oauth ??= {};
|
|
380
|
-
// If authentication service then create a User/Ident couple
|
|
381
|
-
if (this._authenticationService) {
|
|
382
|
-
// Should call the onIdentLogin()
|
|
383
|
-
await this._authenticationService.onIdentLogin(ctx, this.getName().toLowerCase(), identId, profile);
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
// Login in session
|
|
387
|
-
ctx.getSession().login(identId, identId);
|
|
388
|
-
// Store the profile retrieved
|
|
389
|
-
session.oauth.profile = profile;
|
|
390
|
-
}
|
|
391
|
-
// Redirect to our targets
|
|
392
|
-
if (session.oauth.redirect) {
|
|
393
|
-
ctx.redirect(session.oauth.redirect);
|
|
394
|
-
}
|
|
395
|
-
else {
|
|
396
|
-
ctx.write("Your authentication is successful");
|
|
397
|
-
}
|
|
398
|
-
// Clean variables from session
|
|
399
|
-
session.oauth.state = undefined;
|
|
400
|
-
session.oauth.redirect = undefined;
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
})();
|
|
404
|
-
export { OAuthService };
|
|
405
|
-
//# sourceMappingURL=oauth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"oauth.js","sourceRoot":"","sources":["../../src/services/oauth.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAK,UAAU,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAiB,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAA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