@celljs/oauth2-client 3.0.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/LICENSE +21 -0
- package/README.md +1 -0
- package/cell.yml +57 -0
- package/lib/node/authentication/authentication-protocol.d.ts +25 -0
- package/lib/node/authentication/authentication-protocol.d.ts.map +1 -0
- package/lib/node/authentication/authentication-protocol.js +11 -0
- package/lib/node/authentication/authentication-protocol.js.map +1 -0
- package/lib/node/authentication/index.d.ts +4 -0
- package/lib/node/authentication/index.d.ts.map +1 -0
- package/lib/node/authentication/index.js +20 -0
- package/lib/node/authentication/index.js.map +1 -0
- package/lib/node/authentication/oauth2-authentication-provider.d.ts +30 -0
- package/lib/node/authentication/oauth2-authentication-provider.d.ts.map +1 -0
- package/lib/node/authentication/oauth2-authentication-provider.js +170 -0
- package/lib/node/authentication/oauth2-authentication-provider.js.map +1 -0
- package/lib/node/authentication/oidc-authentication-provider.d.ts +18 -0
- package/lib/node/authentication/oidc-authentication-provider.d.ts.map +1 -0
- package/lib/node/authentication/oidc-authentication-provider.js +74 -0
- package/lib/node/authentication/oidc-authentication-provider.js.map +1 -0
- package/lib/node/authorization/authorization-code-authorized-client-provider.d.ts +5 -0
- package/lib/node/authorization/authorization-code-authorized-client-provider.d.ts.map +1 -0
- package/lib/node/authorization/authorization-code-authorized-client-provider.js +27 -0
- package/lib/node/authorization/authorization-code-authorized-client-provider.js.map +1 -0
- package/lib/node/authorization/authorization-code-grant-middleware.d.ts +26 -0
- package/lib/node/authorization/authorization-code-grant-middleware.d.ts.map +1 -0
- package/lib/node/authorization/authorization-code-grant-middleware.js +129 -0
- package/lib/node/authorization/authorization-code-grant-middleware.js.map +1 -0
- package/lib/node/authorization/authorization-failure-handler.d.ts +10 -0
- package/lib/node/authorization/authorization-failure-handler.d.ts.map +1 -0
- package/lib/node/authorization/authorization-failure-handler.js +35 -0
- package/lib/node/authorization/authorization-failure-handler.js.map +1 -0
- package/lib/node/authorization/authorization-protocol.d.ts +78 -0
- package/lib/node/authorization/authorization-protocol.d.ts.map +1 -0
- package/lib/node/authorization/authorization-protocol.js +34 -0
- package/lib/node/authorization/authorization-protocol.js.map +1 -0
- package/lib/node/authorization/authorization-request-manager.d.ts +13 -0
- package/lib/node/authorization/authorization-request-manager.d.ts.map +1 -0
- package/lib/node/authorization/authorization-request-manager.js +64 -0
- package/lib/node/authorization/authorization-request-manager.js.map +1 -0
- package/lib/node/authorization/authorization-request-redirect-middleware.d.ts +20 -0
- package/lib/node/authorization/authorization-request-redirect-middleware.d.ts.map +1 -0
- package/lib/node/authorization/authorization-request-redirect-middleware.js +113 -0
- package/lib/node/authorization/authorization-request-redirect-middleware.js.map +1 -0
- package/lib/node/authorization/authorization-request-resolver.d.ts +38 -0
- package/lib/node/authorization/authorization-request-resolver.d.ts.map +1 -0
- package/lib/node/authorization/authorization-request-resolver.js +155 -0
- package/lib/node/authorization/authorization-request-resolver.js.map +1 -0
- package/lib/node/authorization/authorization-success-handler.d.ts +7 -0
- package/lib/node/authorization/authorization-success-handler.d.ts.map +1 -0
- package/lib/node/authorization/authorization-success-handler.js +28 -0
- package/lib/node/authorization/authorization-success-handler.js.map +1 -0
- package/lib/node/authorization/authorized-client-manager.d.ts +11 -0
- package/lib/node/authorization/authorized-client-manager.d.ts.map +1 -0
- package/lib/node/authorization/authorized-client-manager.js +48 -0
- package/lib/node/authorization/authorized-client-manager.js.map +1 -0
- package/lib/node/authorization/authorized-client-service.d.ts +12 -0
- package/lib/node/authorization/authorized-client-service.d.ts.map +1 -0
- package/lib/node/authorization/authorized-client-service.js +87 -0
- package/lib/node/authorization/authorized-client-service.js.map +1 -0
- package/lib/node/authorization/client-credentials-authorized-client-provider.d.ts +12 -0
- package/lib/node/authorization/client-credentials-authorized-client-provider.d.ts.map +1 -0
- package/lib/node/authorization/client-credentials-authorized-client-provider.js +72 -0
- package/lib/node/authorization/client-credentials-authorized-client-provider.js.map +1 -0
- package/lib/node/authorization/context-attributes-mapper.d.ts +5 -0
- package/lib/node/authorization/context-attributes-mapper.d.ts.map +1 -0
- package/lib/node/authorization/context-attributes-mapper.js +28 -0
- package/lib/node/authorization/context-attributes-mapper.js.map +1 -0
- package/lib/node/authorization/index.d.ts +14 -0
- package/lib/node/authorization/index.d.ts.map +1 -0
- package/lib/node/authorization/index.js +30 -0
- package/lib/node/authorization/index.js.map +1 -0
- package/lib/node/authorization/password-authorized-client-provider.d.ts +12 -0
- package/lib/node/authorization/password-authorized-client-provider.d.ts.map +1 -0
- package/lib/node/authorization/password-authorized-client-provider.js +85 -0
- package/lib/node/authorization/password-authorized-client-provider.js.map +1 -0
- package/lib/node/authorization/refresh-token-authorized-client-provider.d.ts +12 -0
- package/lib/node/authorization/refresh-token-authorized-client-provider.d.ts.map +1 -0
- package/lib/node/authorization/refresh-token-authorized-client-provider.js +68 -0
- package/lib/node/authorization/refresh-token-authorized-client-provider.js.map +1 -0
- package/lib/node/constants.d.ts +5 -0
- package/lib/node/constants.d.ts.map +1 -0
- package/lib/node/constants.js +8 -0
- package/lib/node/constants.js.map +1 -0
- package/lib/node/endpoint/authorization-code-token-response-client.d.ts +12 -0
- package/lib/node/endpoint/authorization-code-token-response-client.d.ts.map +1 -0
- package/lib/node/endpoint/authorization-code-token-response-client.js +83 -0
- package/lib/node/endpoint/authorization-code-token-response-client.js.map +1 -0
- package/lib/node/endpoint/client-credentials-token-response-client.d.ts +12 -0
- package/lib/node/endpoint/client-credentials-token-response-client.d.ts.map +1 -0
- package/lib/node/endpoint/client-credentials-token-response-client.js +80 -0
- package/lib/node/endpoint/client-credentials-token-response-client.js.map +1 -0
- package/lib/node/endpoint/endpoint-protocol.d.ts +48 -0
- package/lib/node/endpoint/endpoint-protocol.d.ts.map +1 -0
- package/lib/node/endpoint/endpoint-protocol.js +9 -0
- package/lib/node/endpoint/endpoint-protocol.js.map +1 -0
- package/lib/node/endpoint/index.d.ts +7 -0
- package/lib/node/endpoint/index.d.ts.map +1 -0
- package/lib/node/endpoint/index.js +23 -0
- package/lib/node/endpoint/index.js.map +1 -0
- package/lib/node/endpoint/password-token-response-client.d.ts +12 -0
- package/lib/node/endpoint/password-token-response-client.d.ts.map +1 -0
- package/lib/node/endpoint/password-token-response-client.js +82 -0
- package/lib/node/endpoint/password-token-response-client.js.map +1 -0
- package/lib/node/endpoint/refresh-token-token-response-client.d.ts +12 -0
- package/lib/node/endpoint/refresh-token-token-response-client.d.ts.map +1 -0
- package/lib/node/endpoint/refresh-token-token-response-client.js +87 -0
- package/lib/node/endpoint/refresh-token-token-response-client.js.map +1 -0
- package/lib/node/endpoint/user-response-client.d.ts +9 -0
- package/lib/node/endpoint/user-response-client.d.ts.map +1 -0
- package/lib/node/endpoint/user-response-client.js +84 -0
- package/lib/node/endpoint/user-response-client.js.map +1 -0
- package/lib/node/error/error-hander.d.ts +11 -0
- package/lib/node/error/error-hander.d.ts.map +1 -0
- package/lib/node/error/error-hander.js +52 -0
- package/lib/node/error/error-hander.js.map +1 -0
- package/lib/node/error/error-protocol.d.ts +3 -0
- package/lib/node/error/error-protocol.d.ts.map +1 -0
- package/lib/node/error/error-protocol.js +7 -0
- package/lib/node/error/error-protocol.js.map +1 -0
- package/lib/node/error/error.d.ts +10 -0
- package/lib/node/error/error.d.ts.map +1 -0
- package/lib/node/error/error.js +23 -0
- package/lib/node/error/error.js.map +1 -0
- package/lib/node/error/index.d.ts +4 -0
- package/lib/node/error/index.d.ts.map +1 -0
- package/lib/node/error/index.js +20 -0
- package/lib/node/error/index.js.map +1 -0
- package/lib/node/index.d.ts +8 -0
- package/lib/node/index.d.ts.map +1 -0
- package/lib/node/index.js +24 -0
- package/lib/node/index.js.map +1 -0
- package/lib/node/module.d.ts +4 -0
- package/lib/node/module.d.ts.map +1 -0
- package/lib/node/module.js +6 -0
- package/lib/node/module.js.map +1 -0
- package/lib/node/provider/index.d.ts +3 -0
- package/lib/node/provider/index.d.ts.map +1 -0
- package/lib/node/provider/index.js +19 -0
- package/lib/node/provider/index.js.map +1 -0
- package/lib/node/provider/provider-details-manager.d.ts +12 -0
- package/lib/node/provider/provider-details-manager.d.ts.map +1 -0
- package/lib/node/provider/provider-details-manager.js +50 -0
- package/lib/node/provider/provider-details-manager.js.map +1 -0
- package/lib/node/provider/provider-protocol.d.ts +21 -0
- package/lib/node/provider/provider-protocol.d.ts.map +1 -0
- package/lib/node/provider/provider-protocol.js +5 -0
- package/lib/node/provider/provider-protocol.js.map +1 -0
- package/lib/node/registration/id-token-jwt-decoder-facatory.d.ts +15 -0
- package/lib/node/registration/id-token-jwt-decoder-facatory.d.ts.map +1 -0
- package/lib/node/registration/id-token-jwt-decoder-facatory.js +89 -0
- package/lib/node/registration/id-token-jwt-decoder-facatory.js.map +1 -0
- package/lib/node/registration/index.d.ts +5 -0
- package/lib/node/registration/index.d.ts.map +1 -0
- package/lib/node/registration/index.js +21 -0
- package/lib/node/registration/index.js.map +1 -0
- package/lib/node/registration/jws-algorithm-resolver.d.ts +5 -0
- package/lib/node/registration/jws-algorithm-resolver.d.ts.map +1 -0
- package/lib/node/registration/jws-algorithm-resolver.js +22 -0
- package/lib/node/registration/jws-algorithm-resolver.js.map +1 -0
- package/lib/node/registration/registration-manager.d.ts +15 -0
- package/lib/node/registration/registration-manager.d.ts.map +1 -0
- package/lib/node/registration/registration-manager.js +64 -0
- package/lib/node/registration/registration-manager.js.map +1 -0
- package/lib/node/registration/registration-protocol.d.ts +22 -0
- package/lib/node/registration/registration-protocol.d.ts.map +1 -0
- package/lib/node/registration/registration-protocol.js +7 -0
- package/lib/node/registration/registration-protocol.js.map +1 -0
- package/lib/node/user/index.d.ts +4 -0
- package/lib/node/user/index.d.ts.map +1 -0
- package/lib/node/user/index.js +20 -0
- package/lib/node/user/index.js.map +1 -0
- package/lib/node/user/oauth2-user-service.d.ts +10 -0
- package/lib/node/user/oauth2-user-service.d.ts.map +1 -0
- package/lib/node/user/oauth2-user-service.js +61 -0
- package/lib/node/user/oauth2-user-service.js.map +1 -0
- package/lib/node/user/oidc-user-service.d.ts +13 -0
- package/lib/node/user/oidc-user-service.d.ts.map +1 -0
- package/lib/node/user/oidc-user-service.js +98 -0
- package/lib/node/user/oidc-user-service.js.map +1 -0
- package/lib/node/user/user-protocol.d.ts +6 -0
- package/lib/node/user/user-protocol.d.ts.map +1 -0
- package/lib/node/user/user-protocol.js +3 -0
- package/lib/node/user/user-protocol.js.map +1 -0
- package/lib/node/utils/authorization-grant-request-entity-util.d.ts +10 -0
- package/lib/node/utils/authorization-grant-request-entity-util.d.ts.map +1 -0
- package/lib/node/utils/authorization-grant-request-entity-util.js +28 -0
- package/lib/node/utils/authorization-grant-request-entity-util.js.map +1 -0
- package/lib/node/utils/authorization-response-util.d.ts +8 -0
- package/lib/node/utils/authorization-response-util.d.ts.map +1 -0
- package/lib/node/utils/authorization-response-util.js +53 -0
- package/lib/node/utils/authorization-response-util.js.map +1 -0
- package/lib/node/utils/index.d.ts +3 -0
- package/lib/node/utils/index.d.ts.map +1 -0
- package/lib/node/utils/index.js +19 -0
- package/lib/node/utils/index.js.map +1 -0
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.d.ts.map +1 -0
- package/lib/package.spec.js +4 -0
- package/lib/package.spec.js.map +1 -0
- package/package.json +51 -0
- package/src/node/authentication/authentication-protocol.ts +26 -0
- package/src/node/authentication/index.ts +3 -0
- package/src/node/authentication/oauth2-authentication-provider.ts +163 -0
- package/src/node/authentication/oidc-authentication-provider.ts +60 -0
- package/src/node/authorization/authorization-code-authorized-client-provider.ts +16 -0
- package/src/node/authorization/authorization-code-grant-middleware.ts +110 -0
- package/src/node/authorization/authorization-failure-handler.ts +23 -0
- package/src/node/authorization/authorization-protocol.ts +104 -0
- package/src/node/authorization/authorization-request-manager.ts +54 -0
- package/src/node/authorization/authorization-request-redirect-middleware.ts +91 -0
- package/src/node/authorization/authorization-request-resolver.ts +149 -0
- package/src/node/authorization/authorization-success-handler.ts +15 -0
- package/src/node/authorization/authorized-client-manager.ts +35 -0
- package/src/node/authorization/authorized-client-service.ts +73 -0
- package/src/node/authorization/client-credentials-authorized-client-provider.ts +61 -0
- package/src/node/authorization/context-attributes-mapper.ts +18 -0
- package/src/node/authorization/index.ts +13 -0
- package/src/node/authorization/password-authorized-client-provider.ts +78 -0
- package/src/node/authorization/refresh-token-authorized-client-provider.ts +58 -0
- package/src/node/constants.ts +4 -0
- package/src/node/endpoint/authorization-code-token-response-client.ts +73 -0
- package/src/node/endpoint/client-credentials-token-response-client.ts +69 -0
- package/src/node/endpoint/endpoint-protocol.ts +55 -0
- package/src/node/endpoint/index.ts +6 -0
- package/src/node/endpoint/password-token-response-client.ts +71 -0
- package/src/node/endpoint/refresh-token-token-response-client.ts +77 -0
- package/src/node/endpoint/user-response-client.ts +72 -0
- package/src/node/error/error-hander.ts +39 -0
- package/src/node/error/error-protocol.ts +6 -0
- package/src/node/error/error.ts +19 -0
- package/src/node/error/index.ts +3 -0
- package/src/node/index.ts +7 -0
- package/src/node/module.ts +4 -0
- package/src/node/provider/index.ts +2 -0
- package/src/node/provider/provider-details-manager.ts +33 -0
- package/src/node/provider/provider-protocol.ts +24 -0
- package/src/node/registration/id-token-jwt-decoder-facatory.ts +71 -0
- package/src/node/registration/index.ts +4 -0
- package/src/node/registration/jws-algorithm-resolver.ts +12 -0
- package/src/node/registration/registration-manager.ts +47 -0
- package/src/node/registration/registration-protocol.ts +27 -0
- package/src/node/user/index.ts +3 -0
- package/src/node/user/oauth2-user-service.ts +50 -0
- package/src/node/user/oidc-user-service.ts +92 -0
- package/src/node/user/user-protocol.ts +6 -0
- package/src/node/utils/authorization-grant-request-entity-util.ts +26 -0
- package/src/node/utils/authorization-response-util.ts +50 -0
- package/src/node/utils/index.ts +2 -0
- package/src/package.spec.ts +4 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthorizationCodeGrantMiddleware = void 0;
|
|
13
|
+
const node_1 = require("@celljs/web/lib/node");
|
|
14
|
+
const core_1 = require("@celljs/core");
|
|
15
|
+
const authorization_protocol_1 = require("./authorization-protocol");
|
|
16
|
+
const oauth2_core_1 = require("@celljs/oauth2-core");
|
|
17
|
+
const utils_1 = require("../utils");
|
|
18
|
+
const registration_1 = require("../registration");
|
|
19
|
+
const web_1 = require("@celljs/web");
|
|
20
|
+
const node_2 = require("@celljs/security/lib/node");
|
|
21
|
+
const endpoint_1 = require("../endpoint");
|
|
22
|
+
const constants_1 = require("../constants");
|
|
23
|
+
let AuthorizationCodeGrantMiddleware = class AuthorizationCodeGrantMiddleware {
|
|
24
|
+
constructor() {
|
|
25
|
+
this.priority = authorization_protocol_1.AUTHORIZATION_CODE_GRANT_MIDDLEWARE_PRIORITY;
|
|
26
|
+
}
|
|
27
|
+
async handle(ctx, next) {
|
|
28
|
+
if (await this.matchesAuthorizationResponse()) {
|
|
29
|
+
await this.processAuthorizationResponse();
|
|
30
|
+
}
|
|
31
|
+
await next();
|
|
32
|
+
}
|
|
33
|
+
async processAuthorizationResponse() {
|
|
34
|
+
const authorizationRequest = await this.authorizationRequestManager.remove();
|
|
35
|
+
const registrationId = authorizationRequest.attributes[oauth2_core_1.OAuth2ParameterNames.REGISTRATION_ID];
|
|
36
|
+
const clientRegistration = await this.clientRegistrationManager.get(registrationId);
|
|
37
|
+
const redirectUri = await this.pathResolver.resolve(this.endpoint, node_1.Context.getRequest().path);
|
|
38
|
+
const authorizationResponse = utils_1.AuthorizationResponseUtil.convert(redirectUri);
|
|
39
|
+
if (authorizationResponse.error) {
|
|
40
|
+
throw new oauth2_core_1.OAuth2AuthorizationError(authorizationResponse.error);
|
|
41
|
+
}
|
|
42
|
+
if (authorizationResponse.state !== authorizationRequest.state) {
|
|
43
|
+
throw new oauth2_core_1.OAuth2AuthorizationError({
|
|
44
|
+
errorCode: authorization_protocol_1.INVALID_STATE_PARAMETER_ERROR_CODE
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const tokenResponse = await this.authorizationCodeTokenResponseClient.getTokenResponse({
|
|
48
|
+
authorizationGrantType: clientRegistration.authorizationGrantType,
|
|
49
|
+
clientRegistration,
|
|
50
|
+
authorizationExchange: {
|
|
51
|
+
authorizationRequest, authorizationResponse
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const authentication = node_2.SecurityContext.getAuthentication();
|
|
55
|
+
const principalName = authentication.name;
|
|
56
|
+
await this.authorizedClientManager.save({
|
|
57
|
+
clientRegistration,
|
|
58
|
+
principalName,
|
|
59
|
+
accessToken: tokenResponse.accessToken,
|
|
60
|
+
refreshToken: tokenResponse.refreshToken
|
|
61
|
+
}, principalName);
|
|
62
|
+
const savedRequest = await this.requestCache.get();
|
|
63
|
+
await this.redirectStrategy.send((savedRequest === null || savedRequest === void 0 ? void 0 : savedRequest.redirectUrl) || authorizationRequest.redirectUri);
|
|
64
|
+
}
|
|
65
|
+
async matchesAuthorizationResponse() {
|
|
66
|
+
const authorizationMatch = this.authorizationCodeGrantUri && await this.requestMatcher.match(await this.pathResolver.resolve(this.authorizationCodeGrantUri));
|
|
67
|
+
if (!utils_1.AuthorizationResponseUtil.isAuthorizationResponse() || !authorizationMatch) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const authorizationRequest = await this.authorizationRequestManager.get();
|
|
71
|
+
if (!authorizationRequest) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return !await this.requestMatcher.match(await this.pathResolver.resolve(this.redirectLoginPath));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
__decorate([
|
|
78
|
+
(0, core_1.Autowired)(authorization_protocol_1.AuthorizationRequestManager),
|
|
79
|
+
__metadata("design:type", Object)
|
|
80
|
+
], AuthorizationCodeGrantMiddleware.prototype, "authorizationRequestManager", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
(0, core_1.Autowired)(authorization_protocol_1.AuthorizationRequestResolver),
|
|
83
|
+
__metadata("design:type", Object)
|
|
84
|
+
], AuthorizationCodeGrantMiddleware.prototype, "authorizationRequestResolver", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
(0, core_1.Autowired)(registration_1.ClientRegistrationManager),
|
|
87
|
+
__metadata("design:type", Object)
|
|
88
|
+
], AuthorizationCodeGrantMiddleware.prototype, "clientRegistrationManager", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
(0, core_1.Autowired)(authorization_protocol_1.AuthorizedClientManager),
|
|
91
|
+
__metadata("design:type", Object)
|
|
92
|
+
], AuthorizationCodeGrantMiddleware.prototype, "authorizedClientManager", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, core_1.Autowired)(node_1.RedirectStrategy),
|
|
95
|
+
__metadata("design:type", Object)
|
|
96
|
+
], AuthorizationCodeGrantMiddleware.prototype, "redirectStrategy", void 0);
|
|
97
|
+
__decorate([
|
|
98
|
+
(0, core_1.Autowired)(node_1.RequestMatcher),
|
|
99
|
+
__metadata("design:type", Object)
|
|
100
|
+
], AuthorizationCodeGrantMiddleware.prototype, "requestMatcher", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
(0, core_1.Autowired)(web_1.PathResolver),
|
|
103
|
+
__metadata("design:type", Object)
|
|
104
|
+
], AuthorizationCodeGrantMiddleware.prototype, "pathResolver", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, core_1.Autowired)(node_2.RequestCache),
|
|
107
|
+
__metadata("design:type", Object)
|
|
108
|
+
], AuthorizationCodeGrantMiddleware.prototype, "requestCache", void 0);
|
|
109
|
+
__decorate([
|
|
110
|
+
(0, core_1.Autowired)(endpoint_1.AuthorizationCodeTokenResponseClient),
|
|
111
|
+
__metadata("design:type", endpoint_1.AuthorizationCodeTokenResponseClient)
|
|
112
|
+
], AuthorizationCodeGrantMiddleware.prototype, "authorizationCodeTokenResponseClient", void 0);
|
|
113
|
+
__decorate([
|
|
114
|
+
(0, core_1.Value)(web_1.ENDPOINT),
|
|
115
|
+
__metadata("design:type", String)
|
|
116
|
+
], AuthorizationCodeGrantMiddleware.prototype, "endpoint", void 0);
|
|
117
|
+
__decorate([
|
|
118
|
+
(0, core_1.Value)(constants_1.REDIRECT_LOGIN_PATH),
|
|
119
|
+
__metadata("design:type", String)
|
|
120
|
+
], AuthorizationCodeGrantMiddleware.prototype, "redirectLoginPath", void 0);
|
|
121
|
+
__decorate([
|
|
122
|
+
(0, core_1.Value)(constants_1.AUTHORIZATION_CODE_GRANT_URI),
|
|
123
|
+
__metadata("design:type", String)
|
|
124
|
+
], AuthorizationCodeGrantMiddleware.prototype, "authorizationCodeGrantUri", void 0);
|
|
125
|
+
AuthorizationCodeGrantMiddleware = __decorate([
|
|
126
|
+
(0, core_1.Component)(node_1.Middleware)
|
|
127
|
+
], AuthorizationCodeGrantMiddleware);
|
|
128
|
+
exports.AuthorizationCodeGrantMiddleware = AuthorizationCodeGrantMiddleware;
|
|
129
|
+
//# sourceMappingURL=authorization-code-grant-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-code-grant-middleware.js","sourceRoot":"","sources":["../../../src/node/authorization/authorization-code-grant-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA6F;AAC7F,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AC,CAAC;IACrG,CAAC;CAIJ,CAAA;AA9FG;IAAC,IAAA,gBAAS,EAAC,oDAA2B,CAAC;;qFAC2D;AAElG;IAAC,IAAA,gBAAS,EAAC,qDAA4B,CAAC;;sFACsC;AAE9E;IAAC,IAAA,gBAAS,EAAC,wCAAyB,CAAC;;mFACmC;AAExE;IAAC,IAAA,gBAAS,EAAC,gDAAuB,CAAC;;iFACmD;AAEtF;IAAC,IAAA,gBAAS,EAAC,uBAAgB,CAAC;;0EAC0B;AAEtD;IAAC,IAAA,gBAAS,EAAC,qBAAc,CAAC;;wEACwB;AAElD;IAAC,IAAA,gBAAS,EAAC,kBAAY,CAAC;;sEACsB;AAE9C;IAAC,IAAA,gBAAS,EAAC,mBAAY,CAAC;;sEACsB;AAE9C;IAAC,IAAA,gBAAS,EAAC,+CAAoC,CAAC;8BACS,+CAAoC;8FAAC;AAE9F;IAAC,IAAA,YAAK,EAAC,cAAQ,CAAC;;kEACoB;AAEpC;IAAC,IAAA,YAAK,EAAC,+BAAmB,CAAC;;2EACkB;AAE7C;IAAC,IAAA,YAAK,EAAC,wCAA4B,CAAC;;mFACiB;AApC5C,gCAAgC;IAD5C,IAAA,gBAAS,EAAC,iBAAU,CAAC;GACT,gCAAgC,CAgG5C;AAhGY,4EAAgC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthorizedClient, AuthorizedClientManager, AuthorizationFailureHandler } from './authorization-protocol';
|
|
2
|
+
import { Authentication } from '@celljs/security/lib/node';
|
|
3
|
+
import { OAuth2AuthorizationError } from '@celljs/oauth2-core';
|
|
4
|
+
import { ClientAuthorizationError } from '../error';
|
|
5
|
+
export declare class DefaultAuthorizationFailureHandler implements AuthorizationFailureHandler {
|
|
6
|
+
protected readonly authorizedClientManager: AuthorizedClientManager<AuthorizedClient>;
|
|
7
|
+
onAuthorizationFailure(oauth2AuthorizationError: OAuth2AuthorizationError, principal: Authentication): Promise<void>;
|
|
8
|
+
protected hasRemovalErrorCode(oauth2AuthorizationError: ClientAuthorizationError): number;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=authorization-failure-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-failure-handler.d.ts","sourceRoot":"","sources":["../../../src/node/authorization/authorization-failure-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,gBAAgB,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAC/I,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,wBAAwB,EAAoB,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAEpD,qBACa,kCAAmC,YAAW,2BAA2B;IAGlF,SAAS,CAAC,QAAQ,CAAC,uBAAuB,EAAE,uBAAuB,CAAC,gBAAgB,CAAC,CAAC;IAEhF,sBAAsB,CAAC,wBAAwB,EAAE,wBAAwB,EAAE,SAAS,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1H,SAAS,CAAC,mBAAmB,CAAC,wBAAwB,EAAE,wBAAwB;CAInF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DefaultAuthorizationFailureHandler = void 0;
|
|
13
|
+
const authorization_protocol_1 = require("./authorization-protocol");
|
|
14
|
+
const core_1 = require("@celljs/core");
|
|
15
|
+
const oauth2_core_1 = require("@celljs/oauth2-core");
|
|
16
|
+
const error_1 = require("../error");
|
|
17
|
+
let DefaultAuthorizationFailureHandler = class DefaultAuthorizationFailureHandler {
|
|
18
|
+
async onAuthorizationFailure(oauth2AuthorizationError, principal) {
|
|
19
|
+
if (oauth2AuthorizationError instanceof error_1.ClientAuthorizationError && this.hasRemovalErrorCode(oauth2AuthorizationError)) {
|
|
20
|
+
await this.authorizedClientManager.remove(oauth2AuthorizationError.clientRegistrationId, principal.name);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
hasRemovalErrorCode(oauth2AuthorizationError) {
|
|
24
|
+
return [oauth2_core_1.OAuth2ErrorCodes.INVALID_TOKEN, oauth2_core_1.OAuth2ErrorCodes.INVALID_GRANT].findIndex(code => code === oauth2AuthorizationError.oauth2Error.errorCode);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, core_1.Autowired)(authorization_protocol_1.AuthorizedClientManager),
|
|
29
|
+
__metadata("design:type", Object)
|
|
30
|
+
], DefaultAuthorizationFailureHandler.prototype, "authorizedClientManager", void 0);
|
|
31
|
+
DefaultAuthorizationFailureHandler = __decorate([
|
|
32
|
+
(0, core_1.Component)(authorization_protocol_1.AuthorizationSuccessHandler)
|
|
33
|
+
], DefaultAuthorizationFailureHandler);
|
|
34
|
+
exports.DefaultAuthorizationFailureHandler = DefaultAuthorizationFailureHandler;
|
|
35
|
+
//# sourceMappingURL=authorization-failure-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-failure-handler.js","sourceRoot":"","sources":["../../../src/node/authorization/authorization-failure-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qEAA+I;AAE/I,uCAAoD;AACpD,qDAAiF;AACjF,oCAAoD;AAG7C,IAAM,kCAAkC,GAAxC,MAAM,kCAAkC;IAK3C,KAAK,CAAC,sBAAsB,CAAC,wBAAkD,EAAE,SAAyB;QACtG,IAAI,wBAAwB,YAAY,gCAAwB,IAAI,IAAI,CAAC,mBAAmB,CAAC,wBAAwB,CAAC,EAAE;YACpH,MAAM,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,wBAAwB,CAAC,oBAAoB,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;SAC5G;IACL,CAAC;IAES,mBAAmB,CAAC,wBAAkD;QAC5E,OAAO,CAAE,8BAAgB,CAAC,aAAa,EAAE,8BAAgB,CAAC,aAAa,CAAE,CAAC,SAAS,CAAE,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,wBAAwB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAC1J,CAAC;CAEJ,CAAA;AAbG;IAAC,IAAA,gBAAS,EAAC,gDAAuB,CAAC;;mFACmD;AAH7E,kCAAkC;IAD9C,IAAA,gBAAS,EAAC,oDAA2B,CAAC;GAC1B,kCAAkC,CAe9C;AAfY,gFAAkC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { AuthorizationRequest, AccessToken, RefreshToken, OAuth2AuthorizationError } from '@celljs/oauth2-core';
|
|
2
|
+
import { ClientRegistration } from '../registration';
|
|
3
|
+
import { Authentication } from '@celljs/security/lib/node';
|
|
4
|
+
export declare const AuthorizationRequestResolver: unique symbol;
|
|
5
|
+
export declare const AuthorizedClientManager: unique symbol;
|
|
6
|
+
export declare const AuthorizationRequestManager: unique symbol;
|
|
7
|
+
export declare const AuthorizedClientService: unique symbol;
|
|
8
|
+
export declare const AuthorizedClientProvider: unique symbol;
|
|
9
|
+
export declare const ContextAttributesMapper: unique symbol;
|
|
10
|
+
export declare const AuthorizationSuccessHandler: unique symbol;
|
|
11
|
+
export declare const AuthorizationFailureHandler: unique symbol;
|
|
12
|
+
export declare const AUTHORIZATION_REQUEST_REDIRECT_MIDDLEWARE_PRIORITY: number;
|
|
13
|
+
export declare const AUTHORIZATION_CODE_GRANT_MIDDLEWARE_PRIORITY: number;
|
|
14
|
+
export declare const INVALID_STATE_PARAMETER_ERROR_CODE = "invalid_state_parameter";
|
|
15
|
+
export interface AuthorizationRequestResolver {
|
|
16
|
+
resolve(clientRegistrationId?: string): Promise<AuthorizationRequest | undefined>;
|
|
17
|
+
}
|
|
18
|
+
export interface AuthorizedClient {
|
|
19
|
+
clientRegistration: ClientRegistration;
|
|
20
|
+
principalName: string;
|
|
21
|
+
accessToken: AccessToken;
|
|
22
|
+
refreshToken?: RefreshToken;
|
|
23
|
+
}
|
|
24
|
+
export interface AuthorizedClientManager<T extends AuthorizedClient> {
|
|
25
|
+
get(clientRegistrationId: string, principalName: string): Promise<T | undefined>;
|
|
26
|
+
save(authorizedClient: T, principalName: string): Promise<void>;
|
|
27
|
+
remove(clientRegistrationId: string, principalName: string): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
export interface AuthorizationRequestManager<T extends AuthorizationRequest> {
|
|
30
|
+
get(): Promise<T | undefined>;
|
|
31
|
+
save(authorizationRequest: T): Promise<void>;
|
|
32
|
+
remove(): Promise<T | undefined>;
|
|
33
|
+
}
|
|
34
|
+
export interface AuthorizeRequest {
|
|
35
|
+
clientRegistrationId: string;
|
|
36
|
+
authorizedClient: AuthorizedClient;
|
|
37
|
+
principal: Authentication;
|
|
38
|
+
attributes?: Map<string, any>;
|
|
39
|
+
}
|
|
40
|
+
export interface AuthorizedClientService {
|
|
41
|
+
authorize(authorizeRequest: AuthorizeRequest): Promise<AuthorizedClient | undefined>;
|
|
42
|
+
}
|
|
43
|
+
export interface AuthorizationContext {
|
|
44
|
+
clientRegistration: ClientRegistration;
|
|
45
|
+
authorizedClient?: AuthorizedClient;
|
|
46
|
+
principal: Authentication;
|
|
47
|
+
attributes: Map<string, any>;
|
|
48
|
+
}
|
|
49
|
+
export declare namespace AuthorizationContext {
|
|
50
|
+
/**
|
|
51
|
+
* The name of the attributes in the context associated
|
|
52
|
+
* to the value for the "request scope(s)".
|
|
53
|
+
*/
|
|
54
|
+
const REQUEST_SCOPE_ATTRIBUTE_NAME = "AuthorizationContext.REQUEST_SCOPE";
|
|
55
|
+
/**
|
|
56
|
+
* The name of the attributes in the context associated
|
|
57
|
+
* to the value for the resource owner's username.
|
|
58
|
+
*/
|
|
59
|
+
const USERNAME_ATTRIBUTE_NAME = "AuthorizationContext.USERNAME";
|
|
60
|
+
/**
|
|
61
|
+
* The name of the attributes in the context associated
|
|
62
|
+
* to the value for the resource owner's password.
|
|
63
|
+
*/
|
|
64
|
+
const PASSWORD_ATTRIBUTE_NAME = "AuthorizationContext.PASSWORD";
|
|
65
|
+
}
|
|
66
|
+
export interface AuthorizedClientProvider {
|
|
67
|
+
provide(context: AuthorizationContext): Promise<AuthorizedClient | undefined>;
|
|
68
|
+
}
|
|
69
|
+
export interface ContextAttributesMapper {
|
|
70
|
+
apply(authorizeRequest: AuthorizeRequest): Promise<Map<string, any>>;
|
|
71
|
+
}
|
|
72
|
+
export interface AuthorizationSuccessHandler {
|
|
73
|
+
onAuthorizationSuccess(authorizedClient: AuthorizedClient, principal: Authentication): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
export interface AuthorizationFailureHandler {
|
|
76
|
+
onAuthorizationFailure(oauth2AuthorizationError: OAuth2AuthorizationError, principal: Authentication): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=authorization-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-protocol.d.ts","sourceRoot":"","sources":["../../../src/node/authorization/authorization-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAChH,O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AC,gBAAgB,EAAE,gBAAgB,EAAE,SAAS,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxG;AAED,MAAM,WAAW,2BAA2B;IACxC,sBAAsB,CAAC,wBAAwB,EAAE,wBAAwB,EAAE,SAAS,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxH"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthorizationContext = exports.INVALID_STATE_PARAMETER_ERROR_CODE = exports.AUTHORIZATION_CODE_GRANT_MIDDLEWARE_PRIORITY = exports.AUTHORIZATION_REQUEST_REDIRECT_MIDDLEWARE_PRIORITY = exports.AuthorizationFailureHandler = exports.AuthorizationSuccessHandler = exports.ContextAttributesMapper = exports.AuthorizedClientProvider = exports.AuthorizedClientService = exports.AuthorizationRequestManager = exports.AuthorizedClientManager = exports.AuthorizationRequestResolver = void 0;
|
|
4
|
+
const node_1 = require("@celljs/security/lib/node");
|
|
5
|
+
exports.AuthorizationRequestResolver = Symbol('AuthorizationRequestResolver');
|
|
6
|
+
exports.AuthorizedClientManager = Symbol('AuthorizedClientManager');
|
|
7
|
+
exports.AuthorizationRequestManager = Symbol('AuthorizationRequestManager');
|
|
8
|
+
exports.AuthorizedClientService = Symbol('AuthorizedClientService');
|
|
9
|
+
exports.AuthorizedClientProvider = Symbol('AuthorizedClientProvider');
|
|
10
|
+
exports.ContextAttributesMapper = Symbol('ContextAttributesMapper');
|
|
11
|
+
exports.AuthorizationSuccessHandler = Symbol('AuthorizationSuccessHandler');
|
|
12
|
+
exports.AuthorizationFailureHandler = Symbol('AuthorizationFailureHandler');
|
|
13
|
+
exports.AUTHORIZATION_REQUEST_REDIRECT_MIDDLEWARE_PRIORITY = node_1.AUTHENTICATION_MIDDLE_PRIORITY + 50;
|
|
14
|
+
exports.AUTHORIZATION_CODE_GRANT_MIDDLEWARE_PRIORITY = node_1.AUTHENTICATION_MIDDLE_PRIORITY - 100;
|
|
15
|
+
exports.INVALID_STATE_PARAMETER_ERROR_CODE = 'invalid_state_parameter';
|
|
16
|
+
var AuthorizationContext;
|
|
17
|
+
(function (AuthorizationContext) {
|
|
18
|
+
/**
|
|
19
|
+
* The name of the attributes in the context associated
|
|
20
|
+
* to the value for the "request scope(s)".
|
|
21
|
+
*/
|
|
22
|
+
AuthorizationContext.REQUEST_SCOPE_ATTRIBUTE_NAME = 'AuthorizationContext.REQUEST_SCOPE';
|
|
23
|
+
/**
|
|
24
|
+
* The name of the attributes in the context associated
|
|
25
|
+
* to the value for the resource owner's username.
|
|
26
|
+
*/
|
|
27
|
+
AuthorizationContext.USERNAME_ATTRIBUTE_NAME = 'AuthorizationContext.USERNAME';
|
|
28
|
+
/**
|
|
29
|
+
* The name of the attributes in the context associated
|
|
30
|
+
* to the value for the resource owner's password.
|
|
31
|
+
*/
|
|
32
|
+
AuthorizationContext.PASSWORD_ATTRIBUTE_NAME = 'AuthorizationContext.PASSWORD';
|
|
33
|
+
})(AuthorizationContext = exports.AuthorizationContext || (exports.AuthorizationContext = {}));
|
|
34
|
+
//# sourceMappingURL=authorization-protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-protocol.js","sourceRoot":"","sources":["../../../src/node/authorization/authorization-protocol.ts"],"names":[],"mappings":";;;AAEA,oDAA2F;AAE9E,QAAA,4BAA4B,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAC;AACtE,QAAA,uBAAuB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;AAC5D,QAAA,2BAA2B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;AACpE,QAAA,uBAAuB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;AAC5D,QAAA,wBAAwB,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC;AAC9D,QAAA,uBAAuB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC;AAC5D,QAAA,2BAA2B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;AACpE,QAAA,2BAA2B,GAAG,MAAM,CAAC,6BAA6B,CAAC,CAAC;AAEpE,QAAA,kDAAkD,GAAG,qCAA8B,GAAG,EAAE,CAAC;AACzF,QAAA,4CAA4C,GAAG,qCAA8B,GAAG,GAAG,CAAC;AACpF,QAAA,kCAAkC,GAAG,yBAAyB,CAAC;AAqD5E,IAAiB,oBAAoB,CAmBpC;AAnBD,WAAiB,oBAAoB;IAEjC;;;OAGG;IACU,iDAA4B,GAAG,oCAAoC,CAAC;IAEjF;;;OAGG;IACU,4CAAuB,GAAG,+BAA+B,CAAC;IAEvE;;;OAGG;IACU,4CAAuB,GAAG,+BAA+B,CAAC;AAC3E,CAAC,EAnBgB,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAmBpC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AuthorizationRequestManager } from './authorization-protocol';
|
|
2
|
+
import { AuthorizationRequest } from '@celljs/oauth2-core';
|
|
3
|
+
export declare class HttpSessionAuthorizationRequestManager implements AuthorizationRequestManager<AuthorizationRequest> {
|
|
4
|
+
protected readonly sessionAttributeName: string;
|
|
5
|
+
get(): Promise<AuthorizationRequest | undefined>;
|
|
6
|
+
save(authorizationRequest: AuthorizationRequest): Promise<void>;
|
|
7
|
+
remove(): Promise<AuthorizationRequest | undefined>;
|
|
8
|
+
protected getStateParameter(): string | undefined;
|
|
9
|
+
protected getAuthorizationRequests(): {
|
|
10
|
+
[state: string]: AuthorizationRequest;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=authorization-request-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-request-manager.d.ts","sourceRoot":"","sources":["../../../src/node/authorization/authorization-request-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAwB,MAAM,qBAAqB,CAAC;AAKjF,qBACa,sCAAuC,YAAW,2BAA2B,CAAC,oBAAoB,CAAC;IAE5G,SAAS,CAAC,QAAQ,CAAC,oBAAoB,SAA0E;IAE3G,GAAG,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAOhD,IAAI,CAAC,oBAAoB,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAY/D,MAAM,IAAI,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAczD,SAAS,CAAC,iBAAiB,IAAI,MAAM,GAAG,SAAS;IAIjD,SAAS,CAAC,wBAAwB,IAAI;QAAE,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,CAAA;KAAE;CAKlF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var HttpSessionAuthorizationRequestManager_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.HttpSessionAuthorizationRequestManager = void 0;
|
|
11
|
+
const authorization_protocol_1 = require("./authorization-protocol");
|
|
12
|
+
const oauth2_core_1 = require("@celljs/oauth2-core");
|
|
13
|
+
const node_1 = require("@celljs/web/lib/node");
|
|
14
|
+
const assert_1 = require("assert");
|
|
15
|
+
const core_1 = require("@celljs/core");
|
|
16
|
+
let HttpSessionAuthorizationRequestManager = HttpSessionAuthorizationRequestManager_1 = class HttpSessionAuthorizationRequestManager {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.sessionAttributeName = `${HttpSessionAuthorizationRequestManager_1.name}.AUTHORIZATION_REQUEST`;
|
|
19
|
+
}
|
|
20
|
+
async get() {
|
|
21
|
+
const stateParameter = this.getStateParameter();
|
|
22
|
+
if (stateParameter) {
|
|
23
|
+
return this.getAuthorizationRequests()[stateParameter];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async save(authorizationRequest) {
|
|
27
|
+
if (authorizationRequest) {
|
|
28
|
+
const state = authorizationRequest.state;
|
|
29
|
+
(0, assert_1.ok)(state, 'authorizationRequest.state cannot be empty');
|
|
30
|
+
const authorizationRequests = this.getAuthorizationRequests();
|
|
31
|
+
authorizationRequests[state] = authorizationRequest;
|
|
32
|
+
const session = node_1.Context.getSession();
|
|
33
|
+
session[this.sessionAttributeName] = authorizationRequests;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
await this.remove();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async remove() {
|
|
40
|
+
const stateParameter = this.getStateParameter();
|
|
41
|
+
if (stateParameter) {
|
|
42
|
+
const authorizationRequests = this.getAuthorizationRequests();
|
|
43
|
+
const originalRequest = authorizationRequests[stateParameter];
|
|
44
|
+
delete authorizationRequests[stateParameter];
|
|
45
|
+
if (!Object.keys(authorizationRequests).length) {
|
|
46
|
+
const session = node_1.Context.getSession();
|
|
47
|
+
delete session[this.sessionAttributeName];
|
|
48
|
+
}
|
|
49
|
+
return originalRequest;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
getStateParameter() {
|
|
53
|
+
return node_1.Context.getRequest().query[oauth2_core_1.OAuth2ParameterNames.STATE];
|
|
54
|
+
}
|
|
55
|
+
getAuthorizationRequests() {
|
|
56
|
+
const session = node_1.Context.getSession();
|
|
57
|
+
return session[this.sessionAttributeName] || {};
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
HttpSessionAuthorizationRequestManager = HttpSessionAuthorizationRequestManager_1 = __decorate([
|
|
61
|
+
(0, core_1.Component)(authorization_protocol_1.AuthorizationRequestManager)
|
|
62
|
+
], HttpSessionAuthorizationRequestManager);
|
|
63
|
+
exports.HttpSessionAuthorizationRequestManager = HttpSessionAuthorizationRequestManager;
|
|
64
|
+
//# sourceMappingURL=authorization-request-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-request-manager.js","sourceRoot":"","sources":["../../../src/node/authorization/authorization-request-manager.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,qEAAuE;AACvE,qDAAiF;AACjF,+CAA+C;AAC/C,mCAA4B;AAC5B,uCAAyC;AAGlC,IAAM,sCAAsC,8CAA5C,MAAM,sCAAsC;IAA5C;QAEgB,yBAAoB,GAAG,GAAG,wCAAsC,CAAC,IAAI,wBAAwB,CAAC;IA4CrH,CAAC;IA1CG,KAAK,CAAC,GAAG;QACL,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAChD,IAAI,cAAc,EAAE;YAChB,OAAO,IAAI,CAAC,wBAAwB,EAAE,CAAC,cAAc,CAAC,CAAC;SAC1D;IACL,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,oBAA0C;QACjD,IAAI,oBAAoB,EAAE;YACtB,MAAM,KAAK,GAAG,oBAAoB,CAAC,KAAK,CAAC;YACzC,IAAA,WAAE,EAAC,KAAK,EAAE,4CAA4C,CAAC,CAAC;YACxD,MAAM,qBAAqB,GAAG,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAC9D,qBAAqB,CAAC,KAAK,CAAC,GAAG,oBAAoB,CAAC;YACpD,MAAM,OAAO,GAAG,cAAO,CAAC,UAAU,EAAE,CAAC;YACrC,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,GAAG,qBAAqB,CAAC;SAC9D;aAAM;YACH,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;SACvB;IACL,CAAC;IACD,KAAK,CAAC,MAAM;QACR,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAChD,IAAI,cAAc,EAAE;YAChB,MAAM,qBAAqB,GAAG,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAC9D,MAAM,eAAe,GAAG,qBAAqB,CAAC,cAAc,CAAC,CAAC;YAC9D,OAAO,qBAAqB,CAAC,cAAc,CAAC,CAAC;YAC7C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,MAAM,EAAE;gBAC5C,MAAM,OAAO,GAAG,cAAO,CAAC,UAAU,EAAE,CAAC;gBACrC,OAAO,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;aAC7C;YACD,OAAO,eAAe,CAAC;SAC1B;IACL,CAAC;IAES,iBAAiB;QACvB,OAAe,cAAO,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,kCAAoB,CAAC,KAAK,CAAC,CAAC;IAC1E,CAAC;IAES,wBAAwB;QAC9B,MAAM,OAAO,GAAG,cAAO,CAAC,UAAU,EAAE,CAAC;QACrC,OAAO,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,CAAC;IACpD,CAAC;CAEJ,CAAA;AA9CY,sCAAsC;IADlD,IAAA,gBAAS,EAAC,oDAA2B,CAAC;GAC1B,sCAAsC,CA8ClD;AA9CY,wFAAsC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Middleware, Context, RequestMatcher, RedirectStrategy } from '@celljs/web/lib/node';
|
|
2
|
+
import { Logger } from '@celljs/core';
|
|
3
|
+
import { AuthorizationRequestResolver, AuthorizationRequestManager } from './authorization-protocol';
|
|
4
|
+
import { AuthorizationRequest } from '@celljs/oauth2-core';
|
|
5
|
+
import { RequestCache } from '@celljs/security/lib/node';
|
|
6
|
+
export declare class AuthorizationRequestRedirectMiddleware implements Middleware {
|
|
7
|
+
protected readonly authorizationRequestBaseUri: string;
|
|
8
|
+
protected readonly requestMatcher: RequestMatcher;
|
|
9
|
+
protected readonly authorizationRequestManager: AuthorizationRequestManager<AuthorizationRequest>;
|
|
10
|
+
protected readonly authorizationRequestResolver: AuthorizationRequestResolver;
|
|
11
|
+
protected readonly redirectStrategy: RedirectStrategy;
|
|
12
|
+
protected readonly requestCache: RequestCache;
|
|
13
|
+
protected readonly targetUrlParameter: string;
|
|
14
|
+
protected readonly logger: Logger;
|
|
15
|
+
handle(ctx: Context, next: () => Promise<void>): Promise<void>;
|
|
16
|
+
protected unsuccessfulRedirectForAuthorization(error: any): void;
|
|
17
|
+
protected sendRedirectForAuthorization(authorizationRequest: AuthorizationRequest): Promise<void>;
|
|
18
|
+
readonly priority: number;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=authorization-request-redirect-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-request-redirect-middleware.d.ts","sourceRoot":"","sources":["../../../src/node/authorization/authorization-request-redirect-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAa,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxG,OAAO,EAA+B,MAAM,EAAE,MAAM,cAAc,CAAC;AAEnE,OAAO,EAAE,4BAA4B,EAAE,2BAA2B,EAAsD,MAAM,0BAA0B,CAAC;AACzJ,OAAO,EAA0B,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAGnF,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,qBACa,sCAAuC,YAAW,UAAU;IAGrE,SAAS,CAAC,QAAQ,CAAC,2BAA2B,EAAE,MAAM,CAAC;IAGvD,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IAGlD,SAAS,CAAC,QAAQ,CAAC,2BAA2B,EAAE,2BAA2B,CAAC,oBAAoB,CAAC,CAAC;IAGlG,SAAS,CAAC,QAAQ,CAAC,4BAA4B,EAAE,4BAA4B,CAAC;IAG9E,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAGtD,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IAG9C,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IAG9C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAE5B,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BpE,SAAS,CAAC,oCAAoC,CAAC,KAAK,EAAE,GAAG;cAKzC,4BAA4B,CAAC,oBAAoB,EAAE,oBAAoB;IAiBvF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAsD;CAElF"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AuthorizationRequestRedirectMiddleware = void 0;
|
|
13
|
+
const node_1 = require("@celljs/web/lib/node");
|
|
14
|
+
const core_1 = require("@celljs/core");
|
|
15
|
+
const constants_1 = require("../constants");
|
|
16
|
+
const authorization_protocol_1 = require("./authorization-protocol");
|
|
17
|
+
const oauth2_core_1 = require("@celljs/oauth2-core");
|
|
18
|
+
const http_1 = require("@celljs/http");
|
|
19
|
+
const error_1 = require("../error");
|
|
20
|
+
const node_2 = require("@celljs/security/lib/node");
|
|
21
|
+
let AuthorizationRequestRedirectMiddleware = class AuthorizationRequestRedirectMiddleware {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.priority = authorization_protocol_1.AUTHORIZATION_REQUEST_REDIRECT_MIDDLEWARE_PRIORITY;
|
|
24
|
+
}
|
|
25
|
+
async handle(ctx, next) {
|
|
26
|
+
try {
|
|
27
|
+
const authorizationRequest = await this.authorizationRequestResolver.resolve();
|
|
28
|
+
if (authorizationRequest) {
|
|
29
|
+
await this.sendRedirectForAuthorization(authorizationRequest);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
this.unsuccessfulRedirectForAuthorization(error);
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
await next();
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
if (err instanceof error_1.ClientAuthorizationError) {
|
|
41
|
+
try {
|
|
42
|
+
const authorizationRequest = await this.authorizationRequestResolver.resolve(err.clientRegistrationId);
|
|
43
|
+
if (authorizationRequest) {
|
|
44
|
+
await this.sendRedirectForAuthorization(authorizationRequest);
|
|
45
|
+
await this.requestCache.save();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
this.unsuccessfulRedirectForAuthorization(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
throw err;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
unsuccessfulRedirectForAuthorization(error) {
|
|
57
|
+
this.logger.error(`Authorization Request failed: ${error}`);
|
|
58
|
+
throw new node_1.HttpError(http_1.HttpStatus.INTERNAL_SERVER_ERROR, http_1.HttpStatus.INTERNAL_SERVER_ERROR_REASON_PHRASE);
|
|
59
|
+
}
|
|
60
|
+
async sendRedirectForAuthorization(authorizationRequest) {
|
|
61
|
+
if (oauth2_core_1.AuthorizationGrantType.AuthorizationCode === authorizationRequest.authorizationGrantType) {
|
|
62
|
+
await this.authorizationRequestManager.save(authorizationRequest);
|
|
63
|
+
}
|
|
64
|
+
if (this.targetUrlParameter) {
|
|
65
|
+
const redirectUrl = node_1.Context.getRequest().query[this.targetUrlParameter];
|
|
66
|
+
if (redirectUrl) {
|
|
67
|
+
await this.requestCache.save({
|
|
68
|
+
redirectUrl,
|
|
69
|
+
method: http_1.HttpMethod.GET,
|
|
70
|
+
query: {}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
await this.redirectStrategy.send(authorizationRequest.authorizationRequestUri);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
__decorate([
|
|
78
|
+
(0, core_1.Value)(constants_1.AUTHORIZATION_REQUEST_BASE_URI),
|
|
79
|
+
__metadata("design:type", String)
|
|
80
|
+
], AuthorizationRequestRedirectMiddleware.prototype, "authorizationRequestBaseUri", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
(0, core_1.Autowired)(node_1.RequestMatcher),
|
|
83
|
+
__metadata("design:type", Object)
|
|
84
|
+
], AuthorizationRequestRedirectMiddleware.prototype, "requestMatcher", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
(0, core_1.Autowired)(authorization_protocol_1.AuthorizationRequestManager),
|
|
87
|
+
__metadata("design:type", Object)
|
|
88
|
+
], AuthorizationRequestRedirectMiddleware.prototype, "authorizationRequestManager", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
(0, core_1.Autowired)(authorization_protocol_1.AuthorizationRequestResolver),
|
|
91
|
+
__metadata("design:type", Object)
|
|
92
|
+
], AuthorizationRequestRedirectMiddleware.prototype, "authorizationRequestResolver", void 0);
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, core_1.Autowired)(node_1.RedirectStrategy),
|
|
95
|
+
__metadata("design:type", Object)
|
|
96
|
+
], AuthorizationRequestRedirectMiddleware.prototype, "redirectStrategy", void 0);
|
|
97
|
+
__decorate([
|
|
98
|
+
(0, core_1.Autowired)(node_2.RequestCache),
|
|
99
|
+
__metadata("design:type", Object)
|
|
100
|
+
], AuthorizationRequestRedirectMiddleware.prototype, "requestCache", void 0);
|
|
101
|
+
__decorate([
|
|
102
|
+
(0, core_1.Value)('cell.security.targetUrlParameter'),
|
|
103
|
+
__metadata("design:type", String)
|
|
104
|
+
], AuthorizationRequestRedirectMiddleware.prototype, "targetUrlParameter", void 0);
|
|
105
|
+
__decorate([
|
|
106
|
+
(0, core_1.Autowired)(core_1.Logger),
|
|
107
|
+
__metadata("design:type", Object)
|
|
108
|
+
], AuthorizationRequestRedirectMiddleware.prototype, "logger", void 0);
|
|
109
|
+
AuthorizationRequestRedirectMiddleware = __decorate([
|
|
110
|
+
(0, core_1.Component)(node_1.Middleware)
|
|
111
|
+
], AuthorizationRequestRedirectMiddleware);
|
|
112
|
+
exports.AuthorizationRequestRedirectMiddleware = AuthorizationRequestRedirectMiddleware;
|
|
113
|
+
//# sourceMappingURL=authorization-request-redirect-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-request-redirect-middleware.js","sourceRoot":"","sources":["../../../src/node/authorization/authorization-request-redirect-middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAAwG;AACxG,uCAAmE;AACnE,4CAA8D;AAC9D,qEAAyJ;AACzJ,qDAAmF;AACnF,uCAAsD;AACtD,oCAAoD;AACpD,oDAAyD;AAGlD,IAAM,sCAAsC,GAA5C,MAAM,sCAAsC;IAA5C;QA8EM,aAAQ,GAAW,2EAAkD,CAAC;IAEnF,CAAC;IAtDG,KAAK,CAAC,MAAM,CAAC,GAAY,EAAE,IAAyB;QACh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AE;YACzB,MAAM,WAAW,GAAW,cAAO,CAAC,UAAU,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YAChF,IAAI,WAAW,EAAE;gBACb,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;oBACzB,WAAW;oBACX,MAAM,EAAE,iBAAU,CAAC,GAAG;oBACtB,KAAK,EAAE,EAAE;iBACZ,CAAC,CAAC;aACN;SACJ;QACD,MAAM,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,oBAAoB,CAAC,uBAAuB,CAAC,CAAC;IACnF,CAAC;CAIJ,CAAA;AA9EG;IAAC,IAAA,YAAK,EAAC,0CAA8B,CAAC;;2FACiB;AAEvD;IAAC,IAAA,gBAAS,EAAC,qBAAc,CAAC;;8EACwB;AAElD;IAAC,IAAA,gBAAS,EAAC,oDAA2B,CAAC;;2FAC2D;AAElG;IAAC,IAAA,gBAAS,EAAC,qDAA4B,CAAC;;4FACsC;AAE9E;IAAC,IAAA,gBAAS,EAAC,uBAAgB,CAAC;;gFAC0B;AAEtD;IAAC,IAAA,gBAAS,EAAC,mBAAY,CAAC;;4EACsB;AAE9C;IAAC,IAAA,YAAK,EAAC,kCAAkC,CAAC;;kFACI;AAE9C;IAAC,IAAA,gBAAS,EAAC,aAAM,CAAC;;sEACgB;AAxBzB,sCAAsC;IADlD,IAAA,gBAAS,EAAC,iBAAU,CAAC;GACT,sCAAsC,CAgFlD;AAhFY,wFAAsC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { AuthorizationRequestResolver } from './authorization-protocol';
|
|
2
|
+
import { AuthorizationRequest } from '@celljs/oauth2-core';
|
|
3
|
+
import { ClientRegistrationManager, ClientRegistration } from '../registration';
|
|
4
|
+
import { RequestMatcher } from '@celljs/web/lib/node';
|
|
5
|
+
import { Base64StringKeyGenerator } from '@celljs/security/lib/node';
|
|
6
|
+
import { ProviderDetailsManager } from '../provider';
|
|
7
|
+
import { PathResolver } from '@celljs/web';
|
|
8
|
+
export declare const REGISTRATION_ID_URI_VARIABLE_NAME = "registrationId";
|
|
9
|
+
export declare class DefaultAuthorizationRequestResolver implements AuthorizationRequestResolver {
|
|
10
|
+
protected readonly clientRegistrationManager: ClientRegistrationManager;
|
|
11
|
+
protected readonly providerDetailsManager: ProviderDetailsManager;
|
|
12
|
+
protected readonly requestMatcher: RequestMatcher;
|
|
13
|
+
protected readonly base64StringKeyGenerator: Base64StringKeyGenerator;
|
|
14
|
+
protected readonly pathResolver: PathResolver;
|
|
15
|
+
protected readonly authorizationRequestBaseUri: string;
|
|
16
|
+
protected readonly defaultRedirectUri: string;
|
|
17
|
+
protected readonly endpoint: string;
|
|
18
|
+
resolve(clientRegistrationId?: string): Promise<AuthorizationRequest | undefined>;
|
|
19
|
+
protected doResolve(registrationId: string, redirectUriAction: string): Promise<AuthorizationRequest>;
|
|
20
|
+
protected getParameters(authorizationRequest: AuthorizationRequest): {
|
|
21
|
+
[key: string]: string;
|
|
22
|
+
};
|
|
23
|
+
protected expandRedirectUri(clientRegistration: ClientRegistration, action: string): Promise<string>;
|
|
24
|
+
protected addNonceParameters(attributes: {
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
}, additionalParameters: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}): Promise<void>;
|
|
29
|
+
protected addPkceParameters(attributes: {
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
}, additionalParameters: {
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
protected createHash(nonce: string): string;
|
|
35
|
+
protected resolveRegistrationId(): Promise<string | undefined>;
|
|
36
|
+
protected getAction(defaultAction?: string): string;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=authorization-request-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-request-resolver.d.ts","sourceRoot":"","sources":["../../../src/node/authorization/authorization-request-resolver.ts"],"names":[],"mappings":"AAAA,OA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