@commercetools/connect-payments-sdk 0.2.2 → 0.3.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/CHANGELOG.md +6 -0
- package/dist/api/hooks/jwt-auth.hook.d.ts +1 -0
- package/dist/api/hooks/jwt-auth.hook.js +1 -0
- package/dist/api/hooks/oauth2-auth.hook.d.ts +1 -0
- package/dist/api/hooks/oauth2-auth.hook.js +1 -0
- package/dist/api/hooks/{session-auth.hook.d.ts → session-header-auth.hook.d.ts} +4 -3
- package/dist/api/hooks/{session-auth.hook.js → session-header-auth.hook.js} +4 -3
- package/dist/api/hooks/session-query-param-auth.hook.d.ts +17 -0
- package/dist/api/hooks/session-query-param-auth.hook.js +23 -0
- package/dist/api/hooks/types/hook.type.d.ts +1 -0
- package/dist/api/index.d.ts +2 -1
- package/dist/api/index.js +2 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +12 -4
- package/dist/security/authn/authns.d.ts +11 -1
- package/dist/security/authn/authns.js +28 -1
- package/dist/security/authn/{session-authn-manager.d.ts → session-header-authn-manager.d.ts} +1 -1
- package/dist/security/authn/{session-authn-manager.js → session-header-authn-manager.js} +3 -3
- package/dist/security/authn/session-query-param-authn-manager.d.ts +10 -0
- package/dist/security/authn/session-query-param-authn-manager.js +28 -0
- package/dist/security/authn/types/authn.type.d.ts +3 -0
- package/dist/security/index.d.ts +2 -1
- package/dist/security/index.js +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,7 @@ class JWTAuthenticationHook {
|
|
|
10
10
|
this.contextProvider = opts.contextProvider;
|
|
11
11
|
}
|
|
12
12
|
authenticate() {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
14
|
return async (request) => {
|
|
14
15
|
const authorizationHeader = new security_1.HeaderBasedAuthentication(request.headers['authorization']);
|
|
15
16
|
const authn = await this.authenticationManager.authenticate(authorizationHeader);
|
|
@@ -10,6 +10,7 @@ class Oauth2AuthenticationHook {
|
|
|
10
10
|
this.contextProvider = opts.contextProvider;
|
|
11
11
|
}
|
|
12
12
|
authenticate() {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
14
|
return async (request) => {
|
|
14
15
|
const authorizationHeader = new security_1.HeaderBasedAuthentication(request.headers['authorization']);
|
|
15
16
|
const authn = await this.authenticationManager.authenticate(authorizationHeader);
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { IncomingHttpHeaders } from 'node:http';
|
|
3
3
|
import { ContextProvider, RequestContextData } from '../context/types/request-context.type';
|
|
4
|
-
import {
|
|
4
|
+
import { SessionHeaderAuthenticationManager } from '../../security';
|
|
5
5
|
import { AuthenticationHook } from './types/hook.type';
|
|
6
|
-
export declare class
|
|
6
|
+
export declare class SessionHeaderAuthenticationHook implements AuthenticationHook {
|
|
7
7
|
private authenticationManager;
|
|
8
8
|
private contextProvider;
|
|
9
9
|
constructor(opts: {
|
|
10
|
-
authenticationManager:
|
|
10
|
+
authenticationManager: SessionHeaderAuthenticationManager;
|
|
11
11
|
contextProvider: ContextProvider<RequestContextData>;
|
|
12
12
|
});
|
|
13
13
|
authenticate(): (request: {
|
|
14
14
|
headers: IncomingHttpHeaders;
|
|
15
|
+
query?: any;
|
|
15
16
|
}) => Promise<void>;
|
|
16
17
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SessionHeaderAuthenticationHook = void 0;
|
|
4
4
|
const security_1 = require("../../security");
|
|
5
|
-
class
|
|
5
|
+
class SessionHeaderAuthenticationHook {
|
|
6
6
|
authenticationManager;
|
|
7
7
|
contextProvider;
|
|
8
8
|
constructor(opts) {
|
|
@@ -10,6 +10,7 @@ class SessionAuthenticationHook {
|
|
|
10
10
|
this.contextProvider = opts.contextProvider;
|
|
11
11
|
}
|
|
12
12
|
authenticate() {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
14
|
return async (request) => {
|
|
14
15
|
const sessionIdAuthn = new security_1.HeaderBasedAuthentication(request.headers['x-session-id']);
|
|
15
16
|
const authn = await this.authenticationManager.authenticate(sessionIdAuthn);
|
|
@@ -19,4 +20,4 @@ class SessionAuthenticationHook {
|
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
|
-
exports.
|
|
23
|
+
exports.SessionHeaderAuthenticationHook = SessionHeaderAuthenticationHook;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingHttpHeaders } from 'node:http';
|
|
3
|
+
import { ContextProvider, RequestContextData } from '../context/types/request-context.type';
|
|
4
|
+
import { SessionQueryParamAuthenticationManager } from '../../security';
|
|
5
|
+
import { AuthenticationHook } from './types/hook.type';
|
|
6
|
+
export declare class SessionQueryParamAuthenticationHook implements AuthenticationHook {
|
|
7
|
+
private authenticationManager;
|
|
8
|
+
private contextProvider;
|
|
9
|
+
constructor(opts: {
|
|
10
|
+
authenticationManager: SessionQueryParamAuthenticationManager;
|
|
11
|
+
contextProvider: ContextProvider<RequestContextData>;
|
|
12
|
+
});
|
|
13
|
+
authenticate(): (request: {
|
|
14
|
+
headers: IncomingHttpHeaders;
|
|
15
|
+
query?: any;
|
|
16
|
+
}) => Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SessionQueryParamAuthenticationHook = void 0;
|
|
4
|
+
const security_1 = require("../../security");
|
|
5
|
+
class SessionQueryParamAuthenticationHook {
|
|
6
|
+
authenticationManager;
|
|
7
|
+
contextProvider;
|
|
8
|
+
constructor(opts) {
|
|
9
|
+
this.authenticationManager = opts.authenticationManager;
|
|
10
|
+
this.contextProvider = opts.contextProvider;
|
|
11
|
+
}
|
|
12
|
+
authenticate() {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
return async (request) => {
|
|
15
|
+
const sessionIdAuthn = new security_1.QueryParamBasedAuthentication(request.query['ctsid']);
|
|
16
|
+
const authn = await this.authenticationManager.authenticate(sessionIdAuthn);
|
|
17
|
+
this.contextProvider.updateContextData({
|
|
18
|
+
authentication: authn,
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.SessionQueryParamAuthenticationHook = SessionQueryParamAuthenticationHook;
|
package/dist/api/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './handlers/config.handler';
|
|
|
4
4
|
export * from './handlers/status.handler';
|
|
5
5
|
export * from './hooks/jwt-auth.hook';
|
|
6
6
|
export * from './hooks/oauth2-auth.hook';
|
|
7
|
-
export * from './hooks/session-auth.hook';
|
|
7
|
+
export * from './hooks/session-header-auth.hook';
|
|
8
|
+
export * from './hooks/session-query-param-auth.hook';
|
|
8
9
|
export * from './hooks/types/hook.type';
|
|
9
10
|
export * from './hooks/authorize.hook';
|
package/dist/api/index.js
CHANGED
|
@@ -20,6 +20,7 @@ __exportStar(require("./handlers/config.handler"), exports);
|
|
|
20
20
|
__exportStar(require("./handlers/status.handler"), exports);
|
|
21
21
|
__exportStar(require("./hooks/jwt-auth.hook"), exports);
|
|
22
22
|
__exportStar(require("./hooks/oauth2-auth.hook"), exports);
|
|
23
|
-
__exportStar(require("./hooks/session-auth.hook"), exports);
|
|
23
|
+
__exportStar(require("./hooks/session-header-auth.hook"), exports);
|
|
24
|
+
__exportStar(require("./hooks/session-query-param-auth.hook"), exports);
|
|
24
25
|
__exportStar(require("./hooks/types/hook.type"), exports);
|
|
25
26
|
__exportStar(require("./hooks/authorize.hook"), exports);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JWTAuthenticationHook, Oauth2AuthenticationHook, RequestContextData, RequestContextProvider,
|
|
1
|
+
import { JWTAuthenticationHook, Oauth2AuthenticationHook, RequestContextData, RequestContextProvider, AuthorityAuthorizationHook, SessionHeaderAuthenticationHook, SessionQueryParamAuthenticationHook } from './api';
|
|
2
2
|
import { DefaultCommercetoolsAPI } from './commercetools/api/root-api';
|
|
3
3
|
import { DefaultAuthorizationService } from './commercetools/services/ct-authorization.service';
|
|
4
4
|
import { DefaultCartService } from './commercetools/services/ct-cart.service';
|
|
@@ -27,7 +27,8 @@ export declare const setupPaymentSDK: (opts: {
|
|
|
27
27
|
ctPaymentService: DefaultPaymentService;
|
|
28
28
|
ctAuthorizationService: DefaultAuthorizationService;
|
|
29
29
|
contextProvider: RequestContextProvider;
|
|
30
|
-
|
|
30
|
+
sessionHeaderAuthHookFn: SessionHeaderAuthenticationHook;
|
|
31
|
+
sessionQueryParamAuthHookFn: SessionQueryParamAuthenticationHook;
|
|
31
32
|
jwtAuthHookFn: JWTAuthenticationHook;
|
|
32
33
|
oauth2AuthHookFn: Oauth2AuthenticationHook;
|
|
33
34
|
authorityAuthorizationHookFn: AuthorityAuthorizationHook;
|
package/dist/index.js
CHANGED
|
@@ -61,7 +61,10 @@ const setupPaymentSDK = (opts) => {
|
|
|
61
61
|
const jwtService = new security_1.DefaultJWTService({
|
|
62
62
|
jwksUrl: opts.jwksUrl,
|
|
63
63
|
});
|
|
64
|
-
const
|
|
64
|
+
const sessionHeaderAuthenticationManager = new security_1.SessionHeaderAuthenticationManager({
|
|
65
|
+
sessionService,
|
|
66
|
+
});
|
|
67
|
+
const sessionQueryParamAuthenticationManager = new security_1.SessionQueryParamAuthenticationManager({
|
|
65
68
|
sessionService,
|
|
66
69
|
});
|
|
67
70
|
const oauth2AuthenticationManager = new security_1.Oauth2AuthenticationManager({
|
|
@@ -76,8 +79,12 @@ const setupPaymentSDK = (opts) => {
|
|
|
76
79
|
iss: opts.jwtIssuer,
|
|
77
80
|
projectKey: opts.projectKey,
|
|
78
81
|
});
|
|
79
|
-
const
|
|
80
|
-
authenticationManager:
|
|
82
|
+
const sessionHeaderAuthHookFn = new api_1.SessionHeaderAuthenticationHook({
|
|
83
|
+
authenticationManager: sessionHeaderAuthenticationManager,
|
|
84
|
+
contextProvider,
|
|
85
|
+
});
|
|
86
|
+
const sessionQueryParamAuthHookFn = new api_1.SessionQueryParamAuthenticationHook({
|
|
87
|
+
authenticationManager: sessionQueryParamAuthenticationManager,
|
|
81
88
|
contextProvider,
|
|
82
89
|
});
|
|
83
90
|
const jwtAuthHookFn = new api_1.JWTAuthenticationHook({
|
|
@@ -98,7 +105,8 @@ const setupPaymentSDK = (opts) => {
|
|
|
98
105
|
ctPaymentService,
|
|
99
106
|
ctAuthorizationService,
|
|
100
107
|
contextProvider,
|
|
101
|
-
|
|
108
|
+
sessionHeaderAuthHookFn,
|
|
109
|
+
sessionQueryParamAuthHookFn,
|
|
102
110
|
jwtAuthHookFn,
|
|
103
111
|
oauth2AuthHookFn,
|
|
104
112
|
authorityAuthorizationHookFn,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Authentication, HeaderPrincipal, JWTPrincipal, Oauth2Principal, SessionPrincipal } from './types/authn.type';
|
|
1
|
+
import { Authentication, HeaderPrincipal, JWTPrincipal, Oauth2Principal, QueryParamPrincipal, SessionPrincipal } from './types/authn.type';
|
|
2
2
|
export declare class SessionAuthentication implements Authentication<SessionPrincipal, string> {
|
|
3
3
|
private principal;
|
|
4
4
|
private authorities;
|
|
@@ -22,6 +22,16 @@ export declare class HeaderBasedAuthentication implements Authentication<HeaderP
|
|
|
22
22
|
getPrincipal(): HeaderPrincipal;
|
|
23
23
|
isAuthenticated(): boolean;
|
|
24
24
|
}
|
|
25
|
+
export declare class QueryParamBasedAuthentication implements Authentication<QueryParamPrincipal, string> {
|
|
26
|
+
private authQueryParam;
|
|
27
|
+
constructor(authQueryParam: string);
|
|
28
|
+
hasPrincipal(): boolean;
|
|
29
|
+
getAuthorities(): string[];
|
|
30
|
+
hasCredentials(): boolean;
|
|
31
|
+
getCredentials(): string;
|
|
32
|
+
getPrincipal(): QueryParamPrincipal;
|
|
33
|
+
isAuthenticated(): boolean;
|
|
34
|
+
}
|
|
25
35
|
export declare class Oauth2Authentication implements Authentication<Oauth2Principal, string> {
|
|
26
36
|
private principal;
|
|
27
37
|
private authorities;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JWTAuthentication = exports.Oauth2Authentication = exports.HeaderBasedAuthentication = exports.SessionAuthentication = void 0;
|
|
3
|
+
exports.JWTAuthentication = exports.Oauth2Authentication = exports.QueryParamBasedAuthentication = exports.HeaderBasedAuthentication = exports.SessionAuthentication = void 0;
|
|
4
4
|
class SessionAuthentication {
|
|
5
5
|
principal;
|
|
6
6
|
authorities;
|
|
@@ -58,6 +58,33 @@ class HeaderBasedAuthentication {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
exports.HeaderBasedAuthentication = HeaderBasedAuthentication;
|
|
61
|
+
class QueryParamBasedAuthentication {
|
|
62
|
+
authQueryParam;
|
|
63
|
+
constructor(authQueryParam) {
|
|
64
|
+
this.authQueryParam = authQueryParam;
|
|
65
|
+
}
|
|
66
|
+
hasPrincipal() {
|
|
67
|
+
return this.getPrincipal() != undefined;
|
|
68
|
+
}
|
|
69
|
+
getAuthorities() {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
hasCredentials() {
|
|
73
|
+
return this.getCredentials() != undefined;
|
|
74
|
+
}
|
|
75
|
+
getCredentials() {
|
|
76
|
+
return this.authQueryParam;
|
|
77
|
+
}
|
|
78
|
+
getPrincipal() {
|
|
79
|
+
return {
|
|
80
|
+
authQueryParam: this.authQueryParam,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
isAuthenticated() {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.QueryParamBasedAuthentication = QueryParamBasedAuthentication;
|
|
61
88
|
class Oauth2Authentication {
|
|
62
89
|
principal;
|
|
63
90
|
authorities;
|
package/dist/security/authn/{session-authn-manager.d.ts → session-header-authn-manager.d.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AuthenticationManager } from './types/authn.type';
|
|
2
2
|
import { HeaderBasedAuthentication, SessionAuthentication } from './authns';
|
|
3
3
|
import { CommercetoolsSessionService } from '../../commercetools';
|
|
4
|
-
export declare class
|
|
4
|
+
export declare class SessionHeaderAuthenticationManager implements AuthenticationManager {
|
|
5
5
|
private sessionService;
|
|
6
6
|
constructor(opts: {
|
|
7
7
|
sessionService: CommercetoolsSessionService;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SessionHeaderAuthenticationManager = void 0;
|
|
4
4
|
const authns_1 = require("./authns");
|
|
5
5
|
const errorx_1 = require("../../errorx");
|
|
6
|
-
class
|
|
6
|
+
class SessionHeaderAuthenticationManager {
|
|
7
7
|
sessionService;
|
|
8
8
|
constructor(opts) {
|
|
9
9
|
this.sessionService = opts.sessionService;
|
|
@@ -25,4 +25,4 @@ class SessionAuthenticationManager {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
exports.
|
|
28
|
+
exports.SessionHeaderAuthenticationManager = SessionHeaderAuthenticationManager;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthenticationManager } from './types/authn.type';
|
|
2
|
+
import { QueryParamBasedAuthentication, SessionAuthentication } from './authns';
|
|
3
|
+
import { CommercetoolsSessionService } from '../../commercetools';
|
|
4
|
+
export declare class SessionQueryParamAuthenticationManager implements AuthenticationManager {
|
|
5
|
+
private sessionService;
|
|
6
|
+
constructor(opts: {
|
|
7
|
+
sessionService: CommercetoolsSessionService;
|
|
8
|
+
});
|
|
9
|
+
authenticate(authentication: QueryParamBasedAuthentication): Promise<SessionAuthentication>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SessionQueryParamAuthenticationManager = void 0;
|
|
4
|
+
const authns_1 = require("./authns");
|
|
5
|
+
const errorx_1 = require("../../errorx");
|
|
6
|
+
class SessionQueryParamAuthenticationManager {
|
|
7
|
+
sessionService;
|
|
8
|
+
constructor(opts) {
|
|
9
|
+
this.sessionService = opts.sessionService;
|
|
10
|
+
}
|
|
11
|
+
async authenticate(authentication) {
|
|
12
|
+
const principal = authentication.getPrincipal();
|
|
13
|
+
try {
|
|
14
|
+
const session = await this.sessionService.verifySession(principal.authQueryParam);
|
|
15
|
+
return new authns_1.SessionAuthentication(principal.authQueryParam, {
|
|
16
|
+
cartId: this.sessionService.getCartFromSession(session),
|
|
17
|
+
allowedPaymentMethods: this.sessionService.getAllowedPaymentMethodsFromSession(session),
|
|
18
|
+
processorUrl: this.sessionService.getProcessorUrlFromSession(session),
|
|
19
|
+
paymentInterface: this.sessionService.getPaymentInterfaceFromSession(session),
|
|
20
|
+
merchantReturnUrl: this.sessionService.getMerchantReturnUrlFromSession(session),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
throw new errorx_1.ErrorAuthErrorResponse('Session is not active');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.SessionQueryParamAuthenticationManager = SessionQueryParamAuthenticationManager;
|
|
@@ -12,6 +12,9 @@ export interface Authentication<Principal = unknown, Credentials = unknown> {
|
|
|
12
12
|
export type HeaderPrincipal = {
|
|
13
13
|
authHeader: string;
|
|
14
14
|
};
|
|
15
|
+
export type QueryParamPrincipal = {
|
|
16
|
+
authQueryParam: string;
|
|
17
|
+
};
|
|
15
18
|
export type SessionPrincipal = {
|
|
16
19
|
cartId: string;
|
|
17
20
|
allowedPaymentMethods: string[];
|
package/dist/security/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from './authn/authns';
|
|
2
2
|
export * from './authn/jwt-authn-manager';
|
|
3
3
|
export * from './authn/oauth2-authn-manager';
|
|
4
|
-
export * from './authn/session-authn-manager';
|
|
4
|
+
export * from './authn/session-header-authn-manager';
|
|
5
|
+
export * from './authn/session-query-param-authn-manager';
|
|
5
6
|
export * from './authn/types/authn.type';
|
|
6
7
|
export * from './services/jwt.service';
|
|
7
8
|
export * from './services/oauth2.service';
|
package/dist/security/index.js
CHANGED
|
@@ -17,7 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./authn/authns"), exports);
|
|
18
18
|
__exportStar(require("./authn/jwt-authn-manager"), exports);
|
|
19
19
|
__exportStar(require("./authn/oauth2-authn-manager"), exports);
|
|
20
|
-
__exportStar(require("./authn/session-authn-manager"), exports);
|
|
20
|
+
__exportStar(require("./authn/session-header-authn-manager"), exports);
|
|
21
|
+
__exportStar(require("./authn/session-query-param-authn-manager"), exports);
|
|
21
22
|
__exportStar(require("./authn/types/authn.type"), exports);
|
|
22
23
|
__exportStar(require("./services/jwt.service"), exports);
|
|
23
24
|
__exportStar(require("./services/oauth2.service"), exports);
|