-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-security.ts
102 lines (91 loc) · 4.92 KB
/
create-security.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import TapjawAuthenticationWrapper from '../contracts/tapjaw-authentication-wrapper';
import { default as TapjawApplyAuthorizationHttpHeaderWrapper } from '../authenticators/wrappers/apply-authorization-http-header-wrapper';
import { default as TapjawApplyOauthAuthorizationHttpHeaderWrapper } from '../authenticators/wrappers/apply-oauth-authorization-http-header-wrapper';
import { default as ApplyCustomHttpHeaderWrapper } from '../authenticators/wrappers/apply-custom-http-header-wrapper';
import { default as TapjawBasicAuthenticator } from '../authenticators/basic-auth-authenticator';
import { default as TapjawBearerAuthenticator } from '../authenticators/bearer-auth-authenticator';
import { default as TapjawNonBearerAuthenticator } from '../authenticators/non-bearer-authorization-authenticator';
import {
CustomHeaders,
default as TapjawCustomHeaderAuthenticator,
} from '../authenticators/custom-header-authenticator';
import { default as TapjawOauthAuthenticator } from '../authenticators/oauth-authenticator';
import ApplyJwtHttpHeaderWrapper from '../authenticators/wrappers/apply-jwt-http-header-wrapper';
import JWTBuilder from '../authenticators/jwt/jwt-builder';
import { default as TapjawApplyOAuthRefreshHttpHeaderWrapper } from '../authenticators/wrappers/apply-oauth-refresh-http-header-wrapper';
import { default as TapjawOauthRefreshAuthenticator } from '../authenticators/oauth-refresh-authenticator';
import { default as TapjawPrefetchTokenAuthorizationHeaderAuthenticator } from '../authenticators/prefetch-token-authorization-header-authenticator';
import { ApplyTokenHttpUriWrapper } from '../authenticators/wrappers';
import { PreauthUriTokenAuthenticator } from '../authenticators';
import QueryStringAuthenticator, { QueryParameters } from '../authenticators/query-string-authenticator';
import ApplyQueryStringWrapper from '../authenticators/wrappers/apply-query-string-wrapper';
export const createBasicSecurity = (username: string, password: string): TapjawAuthenticationWrapper =>
new TapjawApplyAuthorizationHttpHeaderWrapper(new TapjawBasicAuthenticator(username, password));
export const createBearerSecurity = (token: string): TapjawAuthenticationWrapper =>
new TapjawApplyAuthorizationHttpHeaderWrapper(new TapjawBearerAuthenticator(token));
export const createSimpleAuthorizationHeaderSecurity = (token: string): TapjawAuthenticationWrapper =>
new TapjawApplyAuthorizationHttpHeaderWrapper(new TapjawNonBearerAuthenticator(token));
export const createCustomHeaderSecurity = (name: string, value: string): TapjawAuthenticationWrapper =>
new ApplyCustomHttpHeaderWrapper(new TapjawCustomHeaderAuthenticator([[name, value]]));
export const createCustomHeadersSecurity = (headers: CustomHeaders[]): TapjawAuthenticationWrapper =>
new ApplyCustomHttpHeaderWrapper(new TapjawCustomHeaderAuthenticator(headers));
export const createQueryParamterPrefetchTokenSecurity = (
queryParameterName: string,
hostname: string,
uri: string,
method: string,
jsonPathToToken: string,
queryParameters: Record<string, string> = {},
headers: Record<string, string> = {}
): TapjawAuthenticationWrapper =>
new ApplyTokenHttpUriWrapper(
queryParameterName,
new PreauthUriTokenAuthenticator(hostname, uri, method, jsonPathToToken, queryParameters, headers)
);
export const createPrefetchTokenAuthorizationHeadersSecurity = (
apiKey: string,
hostname: string,
path: string,
method: string
): TapjawAuthenticationWrapper =>
new TapjawApplyAuthorizationHttpHeaderWrapper(
new TapjawPrefetchTokenAuthorizationHeaderAuthenticator(apiKey, hostname, path, method)
);
export const createOAuthSecurity = (
clientId: string,
clientSecret: string,
hostname: string,
path: string,
postParams: Record<string, string>,
method = 'POST',
responseEncoding: BufferEncoding = 'utf8'
): TapjawAuthenticationWrapper =>
new TapjawApplyOauthAuthorizationHttpHeaderWrapper(
new TapjawOauthAuthenticator(clientId, clientSecret, hostname, path, postParams, method, responseEncoding)
);
export const createOAuthRefreshSecurity = (
clientId: string,
clientSecret: string,
hostname: string,
path: string,
postParams: Record<string, string>,
method = 'POST',
responseEncoding: BufferEncoding = 'utf8'
): TapjawAuthenticationWrapper =>
new TapjawApplyOAuthRefreshHttpHeaderWrapper(
new TapjawOauthRefreshAuthenticator(
clientId,
clientSecret,
hostname,
path,
postParams,
method,
responseEncoding
)
);
export const createJWTSecurity = (jwtBuilder: JWTBuilder): TapjawAuthenticationWrapper => {
return new ApplyJwtHttpHeaderWrapper(jwtBuilder);
};
export const createQueryStringSecurity = (queryParameters: QueryParameters): TapjawAuthenticationWrapper => {
return new ApplyQueryStringWrapper(new QueryStringAuthenticator(queryParameters));
};