@whook/oauth2 8.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/LICENSE +20 -0
- package/README.md +384 -0
- package/dist/handlers/getOAuth2Authorize.d.ts +26 -0
- package/dist/handlers/getOAuth2Authorize.js +192 -0
- package/dist/handlers/getOAuth2Authorize.js.map +1 -0
- package/dist/handlers/getOAuth2Authorize.mjs +169 -0
- package/dist/handlers/getOAuth2Authorize.mjs.map +1 -0
- package/dist/handlers/getOAuth2Authorize.test.d.ts +1 -0
- package/dist/handlers/getOAuth2Authorize.test.js +122 -0
- package/dist/handlers/getOAuth2Authorize.test.js.map +1 -0
- package/dist/handlers/getOAuth2Authorize.test.mjs +114 -0
- package/dist/handlers/getOAuth2Authorize.test.mjs.map +1 -0
- package/dist/handlers/postAuthLogin.d.ts +45 -0
- package/dist/handlers/postAuthLogin.js +125 -0
- package/dist/handlers/postAuthLogin.js.map +1 -0
- package/dist/handlers/postAuthLogin.mjs +108 -0
- package/dist/handlers/postAuthLogin.mjs.map +1 -0
- package/dist/handlers/postAuthLogin.test.d.ts +1 -0
- package/dist/handlers/postAuthLogin.test.js +90 -0
- package/dist/handlers/postAuthLogin.test.js.map +1 -0
- package/dist/handlers/postAuthLogin.test.mjs +85 -0
- package/dist/handlers/postAuthLogin.test.mjs.map +1 -0
- package/dist/handlers/postAuthLogout.d.ts +12 -0
- package/dist/handlers/postAuthLogout.js +46 -0
- package/dist/handlers/postAuthLogout.js.map +1 -0
- package/dist/handlers/postAuthLogout.mjs +33 -0
- package/dist/handlers/postAuthLogout.mjs.map +1 -0
- package/dist/handlers/postAuthLogout.test.d.ts +1 -0
- package/dist/handlers/postAuthLogout.test.js +35 -0
- package/dist/handlers/postAuthLogout.test.js.map +1 -0
- package/dist/handlers/postAuthLogout.test.mjs +30 -0
- package/dist/handlers/postAuthLogout.test.mjs.map +1 -0
- package/dist/handlers/postAuthRefresh.d.ts +45 -0
- package/dist/handlers/postAuthRefresh.js +140 -0
- package/dist/handlers/postAuthRefresh.js.map +1 -0
- package/dist/handlers/postAuthRefresh.mjs +122 -0
- package/dist/handlers/postAuthRefresh.mjs.map +1 -0
- package/dist/handlers/postAuthRefresh.test.d.ts +1 -0
- package/dist/handlers/postAuthRefresh.test.js +99 -0
- package/dist/handlers/postAuthRefresh.test.js.map +1 -0
- package/dist/handlers/postAuthRefresh.test.mjs +94 -0
- package/dist/handlers/postAuthRefresh.test.mjs.map +1 -0
- package/dist/handlers/postOAuth2Acknowledge.d.ts +28 -0
- package/dist/handlers/postOAuth2Acknowledge.js +165 -0
- package/dist/handlers/postOAuth2Acknowledge.js.map +1 -0
- package/dist/handlers/postOAuth2Acknowledge.mjs +150 -0
- package/dist/handlers/postOAuth2Acknowledge.mjs.map +1 -0
- package/dist/handlers/postOAuth2Acknowledge.test.d.ts +1 -0
- package/dist/handlers/postOAuth2Acknowledge.test.js +148 -0
- package/dist/handlers/postOAuth2Acknowledge.test.js.map +1 -0
- package/dist/handlers/postOAuth2Acknowledge.test.mjs +140 -0
- package/dist/handlers/postOAuth2Acknowledge.test.mjs.map +1 -0
- package/dist/handlers/postOAuth2Token.d.ts +36 -0
- package/dist/handlers/postOAuth2Token.js +263 -0
- package/dist/handlers/postOAuth2Token.js.map +1 -0
- package/dist/handlers/postOAuth2Token.mjs +242 -0
- package/dist/handlers/postOAuth2Token.mjs.map +1 -0
- package/dist/handlers/postOAuth2Token.test.d.ts +1 -0
- package/dist/handlers/postOAuth2Token.test.js +166 -0
- package/dist/handlers/postOAuth2Token.test.js.map +1 -0
- package/dist/handlers/postOAuth2Token.test.mjs +160 -0
- package/dist/handlers/postOAuth2Token.test.mjs.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +230 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +15 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +759 -0
- package/dist/index.test.js.map +1 -0
- package/dist/index.test.mjs +748 -0
- package/dist/index.test.mjs.map +1 -0
- package/dist/services/authCookies.d.ts +26 -0
- package/dist/services/authCookies.js +74 -0
- package/dist/services/authCookies.js.map +1 -0
- package/dist/services/authCookies.mjs +58 -0
- package/dist/services/authCookies.mjs.map +1 -0
- package/dist/services/authCookies.test.d.ts +1 -0
- package/dist/services/authCookies.test.js +82 -0
- package/dist/services/authCookies.test.js.map +1 -0
- package/dist/services/authCookies.test.mjs +77 -0
- package/dist/services/authCookies.test.mjs.map +1 -0
- package/dist/services/oAuth2ClientCredentialsGranter.d.ts +17 -0
- package/dist/services/oAuth2ClientCredentialsGranter.js +56 -0
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -0
- package/dist/services/oAuth2ClientCredentialsGranter.mjs +41 -0
- package/dist/services/oAuth2ClientCredentialsGranter.mjs.map +1 -0
- package/dist/services/oAuth2CodeGranter.d.ts +17 -0
- package/dist/services/oAuth2CodeGranter.js +115 -0
- package/dist/services/oAuth2CodeGranter.js.map +1 -0
- package/dist/services/oAuth2CodeGranter.mjs +98 -0
- package/dist/services/oAuth2CodeGranter.mjs.map +1 -0
- package/dist/services/oAuth2CodeGranter.test.d.ts +1 -0
- package/dist/services/oAuth2CodeGranter.test.js +86 -0
- package/dist/services/oAuth2CodeGranter.test.js.map +1 -0
- package/dist/services/oAuth2CodeGranter.test.mjs +81 -0
- package/dist/services/oAuth2CodeGranter.test.mjs.map +1 -0
- package/dist/services/oAuth2Granters.d.ts +79 -0
- package/dist/services/oAuth2Granters.js +140 -0
- package/dist/services/oAuth2Granters.js.map +1 -0
- package/dist/services/oAuth2Granters.mjs +127 -0
- package/dist/services/oAuth2Granters.mjs.map +1 -0
- package/dist/services/oAuth2PasswordGranter.d.ts +16 -0
- package/dist/services/oAuth2PasswordGranter.js +55 -0
- package/dist/services/oAuth2PasswordGranter.js.map +1 -0
- package/dist/services/oAuth2PasswordGranter.mjs +40 -0
- package/dist/services/oAuth2PasswordGranter.mjs.map +1 -0
- package/dist/services/oAuth2RefreshTokenGranter.d.ts +15 -0
- package/dist/services/oAuth2RefreshTokenGranter.js +62 -0
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -0
- package/dist/services/oAuth2RefreshTokenGranter.mjs +47 -0
- package/dist/services/oAuth2RefreshTokenGranter.mjs.map +1 -0
- package/dist/services/oAuth2TokenGranter.d.ts +15 -0
- package/dist/services/oAuth2TokenGranter.js +92 -0
- package/dist/services/oAuth2TokenGranter.js.map +1 -0
- package/dist/services/oAuth2TokenGranter.mjs +78 -0
- package/dist/services/oAuth2TokenGranter.mjs.map +1 -0
- package/package.json +205 -0
- package/src/__snapshots__/index.test.ts.snap +396 -0
- package/src/handlers/__snapshots__/getOAuth2Authorize.test.ts.snap +38 -0
- package/src/handlers/__snapshots__/postOAuth2Acknowledge.test.ts.snap +61 -0
- package/src/handlers/__snapshots__/postOAuth2Token.test.ts.snap +52 -0
- package/src/handlers/getOAuth2Authorize.test.ts +142 -0
- package/src/handlers/getOAuth2Authorize.ts +222 -0
- package/src/handlers/postAuthLogin.test.ts +88 -0
- package/src/handlers/postAuthLogin.ts +123 -0
- package/src/handlers/postAuthLogout.test.ts +33 -0
- package/src/handlers/postAuthLogout.ts +38 -0
- package/src/handlers/postAuthRefresh.test.ts +97 -0
- package/src/handlers/postAuthRefresh.ts +146 -0
- package/src/handlers/postOAuth2Acknowledge.test.ts +175 -0
- package/src/handlers/postOAuth2Acknowledge.ts +209 -0
- package/src/handlers/postOAuth2Token.test.ts +153 -0
- package/src/handlers/postOAuth2Token.ts +302 -0
- package/src/index.test.ts +936 -0
- package/src/index.ts +105 -0
- package/src/services/__snapshots__/oAuth2CodeGranter.test.ts.snap +49 -0
- package/src/services/authCookies.test.ts +93 -0
- package/src/services/authCookies.ts +82 -0
- package/src/services/oAuth2ClientCredentialsGranter.ts +76 -0
- package/src/services/oAuth2CodeGranter.test.ts +94 -0
- package/src/services/oAuth2CodeGranter.ts +133 -0
- package/src/services/oAuth2Granters.ts +274 -0
- package/src/services/oAuth2PasswordGranter.ts +75 -0
- package/src/services/oAuth2RefreshTokenGranter.ts +77 -0
- package/src/services/oAuth2TokenGranter.ts +105 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.OAUTH2_ERRORS_DESCRIPTORS = void 0;
|
|
7
|
+
|
|
8
|
+
var _knifecycle = require("knifecycle");
|
|
9
|
+
|
|
10
|
+
var _whook = require("@whook/whook");
|
|
11
|
+
|
|
12
|
+
const OAUTH2_ERRORS_DESCRIPTORS = {
|
|
13
|
+
E_UNKNOWN_AUTHORIZER_TYPE: {
|
|
14
|
+
code: 'unsupported_response_type',
|
|
15
|
+
status: 400,
|
|
16
|
+
description: `The type "$0" is not supported.`,
|
|
17
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
18
|
+
help: _whook.DEFAULT_HELP_URI
|
|
19
|
+
},
|
|
20
|
+
E_UNKNOWN_APPLICATION_ID: {
|
|
21
|
+
code: 'unauthorized_client',
|
|
22
|
+
status: 400,
|
|
23
|
+
description: `The client id "$0" is unknown.`,
|
|
24
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
25
|
+
help: _whook.DEFAULT_HELP_URI
|
|
26
|
+
},
|
|
27
|
+
E_UNAUTHORIZED_APPLICATION_ID: {
|
|
28
|
+
code: 'unauthorized_client',
|
|
29
|
+
status: 401,
|
|
30
|
+
description: `The client id "$0" is not allowed.`,
|
|
31
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
32
|
+
help: _whook.DEFAULT_HELP_URI
|
|
33
|
+
},
|
|
34
|
+
E_APPLICATION_DISABLED: {
|
|
35
|
+
code: 'unauthorized_client',
|
|
36
|
+
status: 401,
|
|
37
|
+
description: `The client id "$0" is disabled.`,
|
|
38
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
39
|
+
help: _whook.DEFAULT_HELP_URI
|
|
40
|
+
},
|
|
41
|
+
E_BAD_REDIRECT_URI: {
|
|
42
|
+
code: 'invalid_request',
|
|
43
|
+
status: 400,
|
|
44
|
+
description: `The redirect uri "$0" is not allowed.`,
|
|
45
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
46
|
+
help: _whook.DEFAULT_HELP_URI
|
|
47
|
+
},
|
|
48
|
+
E_UNAUTHORIZED_SCOPE: {
|
|
49
|
+
code: 'invalid_scope',
|
|
50
|
+
status: 403,
|
|
51
|
+
description: `The scope "$0" is not allowed.`,
|
|
52
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
53
|
+
help: _whook.DEFAULT_HELP_URI
|
|
54
|
+
},
|
|
55
|
+
E_UNAUTHORIZED_GRANT_TYPE: {
|
|
56
|
+
code: 'invalid_request',
|
|
57
|
+
status: 403,
|
|
58
|
+
description: `The response type "$0" is not allowed for this application.`,
|
|
59
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
60
|
+
help: _whook.DEFAULT_HELP_URI
|
|
61
|
+
},
|
|
62
|
+
E_UNAUTHORIZED_CLIENT: {
|
|
63
|
+
code: 'invalid_client',
|
|
64
|
+
status: 401,
|
|
65
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
66
|
+
help: _whook.DEFAULT_HELP_URI
|
|
67
|
+
},
|
|
68
|
+
E_BAD_USERNAME: {
|
|
69
|
+
code: 'invalid_request',
|
|
70
|
+
status: 400,
|
|
71
|
+
description: 'User does not exists.',
|
|
72
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
73
|
+
help: _whook.DEFAULT_HELP_URI
|
|
74
|
+
},
|
|
75
|
+
E_BAD_PASSWORD: {
|
|
76
|
+
code: 'invalid_request',
|
|
77
|
+
status: 400,
|
|
78
|
+
description: 'Bad password sent for that user.',
|
|
79
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
80
|
+
help: _whook.DEFAULT_HELP_URI
|
|
81
|
+
},
|
|
82
|
+
E_BAD_REFRESH_TOKEN: {
|
|
83
|
+
code: 'invalid_request',
|
|
84
|
+
status: 400,
|
|
85
|
+
description: 'The refresh token is expired/invalid.',
|
|
86
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
87
|
+
help: _whook.DEFAULT_HELP_URI
|
|
88
|
+
},
|
|
89
|
+
E_BAD_AUTHORIZATION_CODE: {
|
|
90
|
+
code: 'invalid_request',
|
|
91
|
+
status: 400,
|
|
92
|
+
description: 'The authorization code is invalid or expired.',
|
|
93
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
94
|
+
help: _whook.DEFAULT_HELP_URI
|
|
95
|
+
},
|
|
96
|
+
E_UNKNOWN_ACKNOWLEDGOR_TYPE: {
|
|
97
|
+
code: 'unsupported_response_type',
|
|
98
|
+
status: 400,
|
|
99
|
+
description: `Type "$0" not supported.`,
|
|
100
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
101
|
+
help: _whook.DEFAULT_HELP_URI
|
|
102
|
+
},
|
|
103
|
+
E_ACCESS_DENIED: {
|
|
104
|
+
code: 'access_denied',
|
|
105
|
+
status: 403,
|
|
106
|
+
description: 'The user denied access to your application.',
|
|
107
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
108
|
+
help: _whook.DEFAULT_HELP_URI
|
|
109
|
+
},
|
|
110
|
+
E_UNKNOWN_AUTHENTICATION_TYPE: {
|
|
111
|
+
code: 'unsupported_grant_type',
|
|
112
|
+
status: 400,
|
|
113
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
114
|
+
help: _whook.DEFAULT_HELP_URI
|
|
115
|
+
},
|
|
116
|
+
E_OAUTH2: {
|
|
117
|
+
code: 'server_error',
|
|
118
|
+
status: 500,
|
|
119
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
120
|
+
help: _whook.DEFAULT_HELP_URI
|
|
121
|
+
},
|
|
122
|
+
E_REFRESH_COOKIE: {
|
|
123
|
+
code: 'invalid_request',
|
|
124
|
+
status: 400,
|
|
125
|
+
description: `Could not find any refresh_token value in the cookie header ($0).`,
|
|
126
|
+
uri: _whook.DEFAULT_ERROR_URI,
|
|
127
|
+
help: _whook.DEFAULT_HELP_URI
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
exports.OAUTH2_ERRORS_DESCRIPTORS = OAUTH2_ERRORS_DESCRIPTORS;
|
|
131
|
+
|
|
132
|
+
var _default = (0, _knifecycle.initializer)({
|
|
133
|
+
name: 'oAuth2Granters',
|
|
134
|
+
type: 'service',
|
|
135
|
+
inject: ['oAuth2ClientCredentialsGranter', 'oAuth2CodeGranter', 'oAuth2PasswordGranter', 'oAuth2RefreshTokenGranter', 'oAuth2TokenGranter'],
|
|
136
|
+
singleton: true
|
|
137
|
+
}, async services => Object.keys(services).map(key => services[key]));
|
|
138
|
+
|
|
139
|
+
exports.default = _default;
|
|
140
|
+
//# sourceMappingURL=oAuth2Granters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/oAuth2Granters.ts"],"names":["OAUTH2_ERRORS_DESCRIPTORS","E_UNKNOWN_AUTHORIZER_TYPE","code","status","description","uri","DEFAULT_ERROR_URI","help","DEFAULT_HELP_URI","E_UNKNOWN_APPLICATION_ID","E_UNAUTHORIZED_APPLICATION_ID","E_APPLICATION_DISABLED","E_BAD_REDIRECT_URI","E_UNAUTHORIZED_SCOPE","E_UNAUTHORIZED_GRANT_TYPE","E_UNAUTHORIZED_CLIENT","E_BAD_USERNAME","E_BAD_PASSWORD","E_BAD_REFRESH_TOKEN","E_BAD_AUTHORIZATION_CODE","E_UNKNOWN_ACKNOWLEDGOR_TYPE","E_ACCESS_DENIED","E_UNKNOWN_AUTHENTICATION_TYPE","E_OAUTH2","E_REFRESH_COOKIE","name","type","inject","singleton","services","Object","keys","map","key"],"mappings":";;;;;;;AAAA;;AACA;;AAIO,MAAMA,yBAAiD,GAAG;AAC/DC,EAAAA,yBAAyB,EAAE;AACzBC,IAAAA,IAAI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IAAP,CAAYF,QAAZ,EAAsBG,GAAtB,CAA2BC,GAAD,IAASJ,QAAQ,CAACI,GAAD,CAA3C,CAbP,C","sourcesContent":["import { initializer } from 'knifecycle';\nimport { DEFAULT_ERROR_URI, DEFAULT_HELP_URI } from '@whook/whook';\nimport type { WhookErrorsDescriptors } from '@whook/whook';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\nexport const OAUTH2_ERRORS_DESCRIPTORS: WhookErrorsDescriptors = {\n E_UNKNOWN_AUTHORIZER_TYPE: {\n code: 'unsupported_response_type',\n status: 400,\n description: `The type \"$0\" is not supported.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNKNOWN_APPLICATION_ID: {\n code: 'unauthorized_client',\n status: 400,\n description: `The client id \"$0\" is unknown.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNAUTHORIZED_APPLICATION_ID: {\n code: 'unauthorized_client',\n status: 401,\n description: `The client id \"$0\" is not allowed.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_APPLICATION_DISABLED: {\n code: 'unauthorized_client',\n status: 401,\n description: `The client id \"$0\" is disabled.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_BAD_REDIRECT_URI: {\n code: 'invalid_request',\n status: 400,\n description: `The redirect uri \"$0\" is not allowed.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNAUTHORIZED_SCOPE: {\n code: 'invalid_scope',\n status: 403,\n description: `The scope \"$0\" is not allowed.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNAUTHORIZED_GRANT_TYPE: {\n code: 'invalid_request',\n status: 403,\n description: `The response type \"$0\" is not allowed for this application.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNAUTHORIZED_CLIENT: {\n code: 'invalid_client',\n status: 401,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_BAD_USERNAME: {\n code: 'invalid_request',\n status: 400,\n description: 'User does not exists.',\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_BAD_PASSWORD: {\n code: 'invalid_request',\n status: 400,\n description: 'Bad password sent for that user.',\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_BAD_REFRESH_TOKEN: {\n code: 'invalid_request',\n status: 400,\n description: 'The refresh token is expired/invalid.',\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_BAD_AUTHORIZATION_CODE: {\n code: 'invalid_request',\n status: 400,\n description: 'The authorization code is invalid or expired.',\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNKNOWN_ACKNOWLEDGOR_TYPE: {\n code: 'unsupported_response_type',\n status: 400,\n description: `Type \"$0\" not supported.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_ACCESS_DENIED: {\n code: 'access_denied',\n status: 403,\n description: 'The user denied access to your application.',\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNKNOWN_AUTHENTICATION_TYPE: {\n code: 'unsupported_grant_type',\n status: 400,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_OAUTH2: {\n code: 'server_error',\n status: 500,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_REFRESH_COOKIE: {\n code: 'invalid_request',\n status: 400,\n description: `Could not find any refresh_token value in the cookie header ($0).`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n};\n\nexport type OAuth2CodeService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n CODE = string,\n> = {\n create: (\n authenticationData: AUTHENTICATION_DATA,\n redirectURI: string,\n additionalParameters: { [name: string]: unknown },\n ) => Promise<CODE>;\n check: (\n authenticationData: AUTHENTICATION_DATA,\n code: CODE,\n redirectURI: string,\n ) => Promise<\n AUTHENTICATION_DATA & {\n redirectURI: string;\n } & { [name: string]: unknown }\n >;\n};\n\nexport type OAuth2PasswordService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n USERNAME = string,\n PASSWORD = string,\n> = {\n check: (\n authenticationData: AUTHENTICATION_DATA,\n username: USERNAME,\n password: PASSWORD,\n demandedScope: AUTHENTICATION_DATA['scope'],\n ) => Promise<AUTHENTICATION_DATA>;\n};\n\nexport type OAuth2AccessTokenService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n TOKEN = string,\n> = {\n create: (\n authenticationData: AUTHENTICATION_DATA,\n tokenAuthenticationData: AUTHENTICATION_DATA,\n additionalParameters?: { [name: string]: unknown },\n ) => Promise<{\n token: TOKEN;\n expiresAt: number;\n }>;\n check: (\n authenticationData: AUTHENTICATION_DATA,\n token: TOKEN,\n scope?: AUTHENTICATION_DATA['scope'],\n ) => Promise<AUTHENTICATION_DATA>;\n};\n\nexport type OAuth2RefreshTokenService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n TOKEN = string,\n> = OAuth2AccessTokenService<AUTHENTICATION_DATA, TOKEN>;\n\nexport type CheckApplicationService = {\n (context: {\n applicationId: string;\n type: string;\n scope: string;\n redirectURI?: string;\n }): Promise<{\n applicationId: string;\n type: string;\n scope: string;\n redirectURI: string;\n }>;\n};\n\nexport type OAuth2GranterService<\n AUTHORIZE_PARAMETERS extends Record<string, unknown> = Record<\n string,\n unknown\n >,\n ACKNOWLEDGE_PARAMETERS extends Record<string, unknown> = Record<\n string,\n unknown\n >,\n GRANT_PARAMETERS extends Record<string, unknown> = Record<string, unknown>,\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = {\n type: string;\n authorizer?: {\n responseType: string;\n authorize: (\n context: {\n clientId: AUTHENTICATION_DATA['applicationId'];\n redirectURI: string;\n scope: AUTHENTICATION_DATA['scope'];\n },\n authorizeParameters?: AUTHORIZE_PARAMETERS,\n ) => Promise<{\n applicationId: AUTHENTICATION_DATA['applicationId'];\n redirectURI: string;\n scope: AUTHENTICATION_DATA['scope'];\n }>;\n };\n acknowledger?: {\n acknowledgmentType: string;\n acknowledge: (\n authenticationData: AUTHENTICATION_DATA,\n acknowledgeParameters: {\n clientId: AUTHENTICATION_DATA['applicationId'];\n redirectURI: string;\n scope: AUTHENTICATION_DATA['applicationId'];\n },\n additionalParameters: ACKNOWLEDGE_PARAMETERS,\n ) => Promise<\n AUTHENTICATION_DATA & {\n redirectURI: string;\n [name: string]: unknown;\n }\n >;\n };\n authenticator?: {\n grantType: string;\n authenticate: (\n grantParameters: GRANT_PARAMETERS,\n authenticationData: AUTHENTICATION_DATA,\n ) => Promise<AUTHENTICATION_DATA>;\n };\n};\n\nexport type OAuth2Options = {\n authenticateURL: string;\n defaultToClientScope?: boolean;\n};\n\nexport type OAuth2Config = {\n OAUTH2: OAuth2Options;\n ERRORS_DESCRIPTORS: WhookErrorsDescriptors;\n};\n\nexport default initializer(\n {\n name: 'oAuth2Granters',\n type: 'service',\n inject: [\n 'oAuth2ClientCredentialsGranter',\n 'oAuth2CodeGranter',\n 'oAuth2PasswordGranter',\n 'oAuth2RefreshTokenGranter',\n 'oAuth2TokenGranter',\n ],\n singleton: true,\n },\n async (services) => Object.keys(services).map((key) => services[key]),\n);\n"],"file":"oAuth2Granters.js"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { initializer } from 'knifecycle';
|
|
2
|
+
import { DEFAULT_ERROR_URI, DEFAULT_HELP_URI } from '@whook/whook';
|
|
3
|
+
export const OAUTH2_ERRORS_DESCRIPTORS = {
|
|
4
|
+
E_UNKNOWN_AUTHORIZER_TYPE: {
|
|
5
|
+
code: 'unsupported_response_type',
|
|
6
|
+
status: 400,
|
|
7
|
+
description: `The type "$0" is not supported.`,
|
|
8
|
+
uri: DEFAULT_ERROR_URI,
|
|
9
|
+
help: DEFAULT_HELP_URI
|
|
10
|
+
},
|
|
11
|
+
E_UNKNOWN_APPLICATION_ID: {
|
|
12
|
+
code: 'unauthorized_client',
|
|
13
|
+
status: 400,
|
|
14
|
+
description: `The client id "$0" is unknown.`,
|
|
15
|
+
uri: DEFAULT_ERROR_URI,
|
|
16
|
+
help: DEFAULT_HELP_URI
|
|
17
|
+
},
|
|
18
|
+
E_UNAUTHORIZED_APPLICATION_ID: {
|
|
19
|
+
code: 'unauthorized_client',
|
|
20
|
+
status: 401,
|
|
21
|
+
description: `The client id "$0" is not allowed.`,
|
|
22
|
+
uri: DEFAULT_ERROR_URI,
|
|
23
|
+
help: DEFAULT_HELP_URI
|
|
24
|
+
},
|
|
25
|
+
E_APPLICATION_DISABLED: {
|
|
26
|
+
code: 'unauthorized_client',
|
|
27
|
+
status: 401,
|
|
28
|
+
description: `The client id "$0" is disabled.`,
|
|
29
|
+
uri: DEFAULT_ERROR_URI,
|
|
30
|
+
help: DEFAULT_HELP_URI
|
|
31
|
+
},
|
|
32
|
+
E_BAD_REDIRECT_URI: {
|
|
33
|
+
code: 'invalid_request',
|
|
34
|
+
status: 400,
|
|
35
|
+
description: `The redirect uri "$0" is not allowed.`,
|
|
36
|
+
uri: DEFAULT_ERROR_URI,
|
|
37
|
+
help: DEFAULT_HELP_URI
|
|
38
|
+
},
|
|
39
|
+
E_UNAUTHORIZED_SCOPE: {
|
|
40
|
+
code: 'invalid_scope',
|
|
41
|
+
status: 403,
|
|
42
|
+
description: `The scope "$0" is not allowed.`,
|
|
43
|
+
uri: DEFAULT_ERROR_URI,
|
|
44
|
+
help: DEFAULT_HELP_URI
|
|
45
|
+
},
|
|
46
|
+
E_UNAUTHORIZED_GRANT_TYPE: {
|
|
47
|
+
code: 'invalid_request',
|
|
48
|
+
status: 403,
|
|
49
|
+
description: `The response type "$0" is not allowed for this application.`,
|
|
50
|
+
uri: DEFAULT_ERROR_URI,
|
|
51
|
+
help: DEFAULT_HELP_URI
|
|
52
|
+
},
|
|
53
|
+
E_UNAUTHORIZED_CLIENT: {
|
|
54
|
+
code: 'invalid_client',
|
|
55
|
+
status: 401,
|
|
56
|
+
uri: DEFAULT_ERROR_URI,
|
|
57
|
+
help: DEFAULT_HELP_URI
|
|
58
|
+
},
|
|
59
|
+
E_BAD_USERNAME: {
|
|
60
|
+
code: 'invalid_request',
|
|
61
|
+
status: 400,
|
|
62
|
+
description: 'User does not exists.',
|
|
63
|
+
uri: DEFAULT_ERROR_URI,
|
|
64
|
+
help: DEFAULT_HELP_URI
|
|
65
|
+
},
|
|
66
|
+
E_BAD_PASSWORD: {
|
|
67
|
+
code: 'invalid_request',
|
|
68
|
+
status: 400,
|
|
69
|
+
description: 'Bad password sent for that user.',
|
|
70
|
+
uri: DEFAULT_ERROR_URI,
|
|
71
|
+
help: DEFAULT_HELP_URI
|
|
72
|
+
},
|
|
73
|
+
E_BAD_REFRESH_TOKEN: {
|
|
74
|
+
code: 'invalid_request',
|
|
75
|
+
status: 400,
|
|
76
|
+
description: 'The refresh token is expired/invalid.',
|
|
77
|
+
uri: DEFAULT_ERROR_URI,
|
|
78
|
+
help: DEFAULT_HELP_URI
|
|
79
|
+
},
|
|
80
|
+
E_BAD_AUTHORIZATION_CODE: {
|
|
81
|
+
code: 'invalid_request',
|
|
82
|
+
status: 400,
|
|
83
|
+
description: 'The authorization code is invalid or expired.',
|
|
84
|
+
uri: DEFAULT_ERROR_URI,
|
|
85
|
+
help: DEFAULT_HELP_URI
|
|
86
|
+
},
|
|
87
|
+
E_UNKNOWN_ACKNOWLEDGOR_TYPE: {
|
|
88
|
+
code: 'unsupported_response_type',
|
|
89
|
+
status: 400,
|
|
90
|
+
description: `Type "$0" not supported.`,
|
|
91
|
+
uri: DEFAULT_ERROR_URI,
|
|
92
|
+
help: DEFAULT_HELP_URI
|
|
93
|
+
},
|
|
94
|
+
E_ACCESS_DENIED: {
|
|
95
|
+
code: 'access_denied',
|
|
96
|
+
status: 403,
|
|
97
|
+
description: 'The user denied access to your application.',
|
|
98
|
+
uri: DEFAULT_ERROR_URI,
|
|
99
|
+
help: DEFAULT_HELP_URI
|
|
100
|
+
},
|
|
101
|
+
E_UNKNOWN_AUTHENTICATION_TYPE: {
|
|
102
|
+
code: 'unsupported_grant_type',
|
|
103
|
+
status: 400,
|
|
104
|
+
uri: DEFAULT_ERROR_URI,
|
|
105
|
+
help: DEFAULT_HELP_URI
|
|
106
|
+
},
|
|
107
|
+
E_OAUTH2: {
|
|
108
|
+
code: 'server_error',
|
|
109
|
+
status: 500,
|
|
110
|
+
uri: DEFAULT_ERROR_URI,
|
|
111
|
+
help: DEFAULT_HELP_URI
|
|
112
|
+
},
|
|
113
|
+
E_REFRESH_COOKIE: {
|
|
114
|
+
code: 'invalid_request',
|
|
115
|
+
status: 400,
|
|
116
|
+
description: `Could not find any refresh_token value in the cookie header ($0).`,
|
|
117
|
+
uri: DEFAULT_ERROR_URI,
|
|
118
|
+
help: DEFAULT_HELP_URI
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
export default initializer({
|
|
122
|
+
name: 'oAuth2Granters',
|
|
123
|
+
type: 'service',
|
|
124
|
+
inject: ['oAuth2ClientCredentialsGranter', 'oAuth2CodeGranter', 'oAuth2PasswordGranter', 'oAuth2RefreshTokenGranter', 'oAuth2TokenGranter'],
|
|
125
|
+
singleton: true
|
|
126
|
+
}, async services => Object.keys(services).map(key => services[key]));
|
|
127
|
+
//# sourceMappingURL=oAuth2Granters.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/oAuth2Granters.ts"],"names":["initializer","DEFAULT_ERROR_URI","DEFAULT_HELP_URI","OAUTH2_ERRORS_DESCRIPTORS","E_UNKNOWN_AUTHORIZER_TYPE","code","status","description","uri","help","E_UNKNOWN_APPLICATION_ID","E_UNAUTHORIZED_APPLICATION_ID","E_APPLICATION_DISABLED","E_BAD_REDIRECT_URI","E_UNAUTHORIZED_SCOPE","E_UNAUTHORIZED_GRANT_TYPE","E_UNAUTHORIZED_CLIENT","E_BAD_USERNAME","E_BAD_PASSWORD","E_BAD_REFRESH_TOKEN","E_BAD_AUTHORIZATION_CODE","E_UNKNOWN_ACKNOWLEDGOR_TYPE","E_ACCESS_DENIED","E_UNKNOWN_AUTHENTICATION_TYPE","E_OAUTH2","E_REFRESH_COOKIE","name","type","inject","singleton","services","Object","keys","map","key"],"mappings":"AAAA,SAASA,WAAT,QAA4B,YAA5B;AACA,SAASC,iBAAT,EAA4BC,gBAA5B,QAAoD,cAApD;AAIA,OAAO,MAAMC,yBAAiD,GAAG;AAC/DC,EAAAA,yBAAyB,EAAE;AACzBC,IAAAA,IAAI,EAAE,2BADmB;AAEzBC,IAAAA,MAAM,EAAE,GAFiB;AAGzBC,IAAAA,WAAW,EAAG,iCAHW;AAIzBC,IAAAA,GAAG,EAAEP,iBAJoB;AAKzBQ,IAAAA,IAAI,EAAEP;AALmB,GADoC;AAQ/DQ,EAAAA,wBAAwB,EAAE;AACxBL,IAAAA,IAAI,EAAE,qBADkB;AAExBC,IAAAA,MAAM,EAAE,GAFgB;AAGxBC,IAAAA,WAAW,EAAG,gCAHU;AAIxBC,IAAAA,GAAG,EAAEP,iBAJmB;AAKxBQ,IAAAA,IAAI,EAAEP;AALkB,GARqC;AAe/DS,EAAAA,6BAA6B,EAAE;AAC7BN,IAAAA,IAAI,EAAE,qBADuB;AAE7BC,IAAAA,MAAM,EAAE,GAFqB;AAG7BC,IAAAA,WAAW,EAAG,oCAHe;AAI7BC,IAAAA,GAAG,EAAEP,iBAJwB;AAK7BQ,IAAAA,IAAI,EAAEP;AALuB,GAfgC;AAsB/DU,EAAAA,sBAAsB,EAAE;AACtBP,IAAAA,IAAI,EAAE,qBADgB;AAEtBC,IAAAA,MAAM,EAAE,GAFc;AAGtBC,IAAAA,WAAW,EAAG,iCAHQ;AAItBC,IAAAA,GAAG,EAAEP,iBAJiB;AAKt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AAJE,GAxGqD;AA8G/DuB,EAAAA,gBAAgB,EAAE;AAChBpB,IAAAA,IAAI,EAAE,iBADU;AAEhBC,IAAAA,MAAM,EAAE,GAFQ;AAGhBC,IAAAA,WAAW,EAAG,mEAHE;AAIhBC,IAAAA,GAAG,EAAEP,iBAJW;AAKhBQ,IAAAA,IAAI,EAAEP;AALU;AA9G6C,CAA1D;AA8PP,eAAeF,WAAW,CACxB;AACE0B,EAAAA,IAAI,EAAE,gBADR;AAEEC,EAAAA,IAAI,EAAE,SAFR;AAGEC,EAAAA,MAAM,EAAE,CACN,gCADM,EAEN,mBAFM,EAGN,uBAHM,EAIN,2BAJM,EAKN,oBALM,CAHV;AAUEC,EAAAA,SAAS,EAAE;AAVb,CADwB,EAaxB,MAAOC,QAAP,IAAoBC,MAAM,CAACC,IAAP,CAAYF,QAAZ,EAAsBG,GAAtB,CAA2BC,GAAD,IAASJ,QAAQ,CAACI,GAAD,CAA3C,CAbI,CAA1B","sourcesContent":["import { initializer } from 'knifecycle';\nimport { DEFAULT_ERROR_URI, DEFAULT_HELP_URI } from '@whook/whook';\nimport type { WhookErrorsDescriptors } from '@whook/whook';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\nexport const OAUTH2_ERRORS_DESCRIPTORS: WhookErrorsDescriptors = {\n E_UNKNOWN_AUTHORIZER_TYPE: {\n code: 'unsupported_response_type',\n status: 400,\n description: `The type \"$0\" is not supported.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNKNOWN_APPLICATION_ID: {\n code: 'unauthorized_client',\n status: 400,\n description: `The client id \"$0\" is unknown.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNAUTHORIZED_APPLICATION_ID: {\n code: 'unauthorized_client',\n status: 401,\n description: `The client id \"$0\" is not allowed.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_APPLICATION_DISABLED: {\n code: 'unauthorized_client',\n status: 401,\n description: `The client id \"$0\" is disabled.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_BAD_REDIRECT_URI: {\n code: 'invalid_request',\n status: 400,\n description: `The redirect uri \"$0\" is not allowed.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNAUTHORIZED_SCOPE: {\n code: 'invalid_scope',\n status: 403,\n description: `The scope \"$0\" is not allowed.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNAUTHORIZED_GRANT_TYPE: {\n code: 'invalid_request',\n status: 403,\n description: `The response type \"$0\" is not allowed for this application.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNAUTHORIZED_CLIENT: {\n code: 'invalid_client',\n status: 401,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_BAD_USERNAME: {\n code: 'invalid_request',\n status: 400,\n description: 'User does not exists.',\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_BAD_PASSWORD: {\n code: 'invalid_request',\n status: 400,\n description: 'Bad password sent for that user.',\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_BAD_REFRESH_TOKEN: {\n code: 'invalid_request',\n status: 400,\n description: 'The refresh token is expired/invalid.',\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_BAD_AUTHORIZATION_CODE: {\n code: 'invalid_request',\n status: 400,\n description: 'The authorization code is invalid or expired.',\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNKNOWN_ACKNOWLEDGOR_TYPE: {\n code: 'unsupported_response_type',\n status: 400,\n description: `Type \"$0\" not supported.`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_ACCESS_DENIED: {\n code: 'access_denied',\n status: 403,\n description: 'The user denied access to your application.',\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_UNKNOWN_AUTHENTICATION_TYPE: {\n code: 'unsupported_grant_type',\n status: 400,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_OAUTH2: {\n code: 'server_error',\n status: 500,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n E_REFRESH_COOKIE: {\n code: 'invalid_request',\n status: 400,\n description: `Could not find any refresh_token value in the cookie header ($0).`,\n uri: DEFAULT_ERROR_URI,\n help: DEFAULT_HELP_URI,\n },\n};\n\nexport type OAuth2CodeService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n CODE = string,\n> = {\n create: (\n authenticationData: AUTHENTICATION_DATA,\n redirectURI: string,\n additionalParameters: { [name: string]: unknown },\n ) => Promise<CODE>;\n check: (\n authenticationData: AUTHENTICATION_DATA,\n code: CODE,\n redirectURI: string,\n ) => Promise<\n AUTHENTICATION_DATA & {\n redirectURI: string;\n } & { [name: string]: unknown }\n >;\n};\n\nexport type OAuth2PasswordService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n USERNAME = string,\n PASSWORD = string,\n> = {\n check: (\n authenticationData: AUTHENTICATION_DATA,\n username: USERNAME,\n password: PASSWORD,\n demandedScope: AUTHENTICATION_DATA['scope'],\n ) => Promise<AUTHENTICATION_DATA>;\n};\n\nexport type OAuth2AccessTokenService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n TOKEN = string,\n> = {\n create: (\n authenticationData: AUTHENTICATION_DATA,\n tokenAuthenticationData: AUTHENTICATION_DATA,\n additionalParameters?: { [name: string]: unknown },\n ) => Promise<{\n token: TOKEN;\n expiresAt: number;\n }>;\n check: (\n authenticationData: AUTHENTICATION_DATA,\n token: TOKEN,\n scope?: AUTHENTICATION_DATA['scope'],\n ) => Promise<AUTHENTICATION_DATA>;\n};\n\nexport type OAuth2RefreshTokenService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n TOKEN = string,\n> = OAuth2AccessTokenService<AUTHENTICATION_DATA, TOKEN>;\n\nexport type CheckApplicationService = {\n (context: {\n applicationId: string;\n type: string;\n scope: string;\n redirectURI?: string;\n }): Promise<{\n applicationId: string;\n type: string;\n scope: string;\n redirectURI: string;\n }>;\n};\n\nexport type OAuth2GranterService<\n AUTHORIZE_PARAMETERS extends Record<string, unknown> = Record<\n string,\n unknown\n >,\n ACKNOWLEDGE_PARAMETERS extends Record<string, unknown> = Record<\n string,\n unknown\n >,\n GRANT_PARAMETERS extends Record<string, unknown> = Record<string, unknown>,\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = {\n type: string;\n authorizer?: {\n responseType: string;\n authorize: (\n context: {\n clientId: AUTHENTICATION_DATA['applicationId'];\n redirectURI: string;\n scope: AUTHENTICATION_DATA['scope'];\n },\n authorizeParameters?: AUTHORIZE_PARAMETERS,\n ) => Promise<{\n applicationId: AUTHENTICATION_DATA['applicationId'];\n redirectURI: string;\n scope: AUTHENTICATION_DATA['scope'];\n }>;\n };\n acknowledger?: {\n acknowledgmentType: string;\n acknowledge: (\n authenticationData: AUTHENTICATION_DATA,\n acknowledgeParameters: {\n clientId: AUTHENTICATION_DATA['applicationId'];\n redirectURI: string;\n scope: AUTHENTICATION_DATA['applicationId'];\n },\n additionalParameters: ACKNOWLEDGE_PARAMETERS,\n ) => Promise<\n AUTHENTICATION_DATA & {\n redirectURI: string;\n [name: string]: unknown;\n }\n >;\n };\n authenticator?: {\n grantType: string;\n authenticate: (\n grantParameters: GRANT_PARAMETERS,\n authenticationData: AUTHENTICATION_DATA,\n ) => Promise<AUTHENTICATION_DATA>;\n };\n};\n\nexport type OAuth2Options = {\n authenticateURL: string;\n defaultToClientScope?: boolean;\n};\n\nexport type OAuth2Config = {\n OAUTH2: OAuth2Options;\n ERRORS_DESCRIPTORS: WhookErrorsDescriptors;\n};\n\nexport default initializer(\n {\n name: 'oAuth2Granters',\n type: 'service',\n inject: [\n 'oAuth2ClientCredentialsGranter',\n 'oAuth2CodeGranter',\n 'oAuth2PasswordGranter',\n 'oAuth2RefreshTokenGranter',\n 'oAuth2TokenGranter',\n ],\n singleton: true,\n },\n async (services) => Object.keys(services).map((key) => services[key]),\n);\n"],"file":"oAuth2Granters.mjs"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LogService } from 'common-services';
|
|
2
|
+
import type { OAuth2GranterService, OAuth2PasswordService, CheckApplicationService } from './oAuth2Granters';
|
|
3
|
+
import type { BaseAuthenticationData } from '@whook/authorization';
|
|
4
|
+
export declare type OAuth2PasswordGranterDependencies = {
|
|
5
|
+
oAuth2Password: OAuth2PasswordService;
|
|
6
|
+
checkApplication: CheckApplicationService;
|
|
7
|
+
log?: LogService;
|
|
8
|
+
};
|
|
9
|
+
export declare type OAuth2PasswordGranterParameters = {
|
|
10
|
+
username: string;
|
|
11
|
+
password: string;
|
|
12
|
+
scope?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare type OAuth2PasswordGranterService<AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData> = OAuth2GranterService<Record<string, unknown>, Record<string, unknown>, OAuth2PasswordGranterParameters, AUTHENTICATION_DATA>;
|
|
15
|
+
declare const _default: import("knifecycle").ServiceInitializer<OAuth2PasswordGranterDependencies, OAuth2PasswordGranterService<BaseAuthenticationData<string, string>>>;
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _knifecycle = require("knifecycle");
|
|
9
|
+
|
|
10
|
+
var _whook = require("@whook/whook");
|
|
11
|
+
|
|
12
|
+
var _yerror = _interopRequireDefault(require("yerror"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
var _default = (0, _knifecycle.service)(initOAuth2PasswordGranter, "oAuth2PasswordGranter", ["oAuth2Password", "checkApplication", "?log"]); // Resource Owner Password Credentials Grant
|
|
17
|
+
// https://tools.ietf.org/html/rfc6749#section-4.3
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
exports.default = _default;
|
|
21
|
+
|
|
22
|
+
async function initOAuth2PasswordGranter({
|
|
23
|
+
oAuth2Password,
|
|
24
|
+
checkApplication,
|
|
25
|
+
log = _whook.noop
|
|
26
|
+
}) {
|
|
27
|
+
const authenticateWithPassword = async ({
|
|
28
|
+
username,
|
|
29
|
+
password,
|
|
30
|
+
scope: demandedScope = ''
|
|
31
|
+
}, authenticationData) => {
|
|
32
|
+
// The client must be authenticated
|
|
33
|
+
if (!authenticationData) {
|
|
34
|
+
throw new _yerror.default('E_UNAUTHORIZED');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await checkApplication({
|
|
38
|
+
applicationId: authenticationData.applicationId,
|
|
39
|
+
type: 'password',
|
|
40
|
+
scope: demandedScope
|
|
41
|
+
});
|
|
42
|
+
const finalAuthenticationData = await oAuth2Password.check(authenticationData, username, password, demandedScope);
|
|
43
|
+
return finalAuthenticationData;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
log('debug', '👫 - OAuth2PasswordGranter Service Initialized!');
|
|
47
|
+
return {
|
|
48
|
+
type: 'password',
|
|
49
|
+
authenticator: {
|
|
50
|
+
grantType: 'password',
|
|
51
|
+
authenticate: authenticateWithPassword
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=oAuth2PasswordGranter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/oAuth2PasswordGranter.ts"],"names":["initOAuth2PasswordGranter","oAuth2Password","checkApplication","log","noop","authenticateWithPassword","username","password","scope","demandedScope","authenticationData","YError","applicationId","type","finalAuthenticationData","check","authenticator","grantType","authenticate"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;eA4Be,yBAAYA,yBAAZ,0E,EAEf;AACA;;;;;AACA,eAAeA,yBAAf,CAAyC;AACvCC,EAAAA,cADuC;AAEvCC,EAAAA,gBAFuC;AAGvCC,EAAAA,GAAG,GAAGC;AAHiC,CAAzC,EAI6E;AAC3E,QAAMC,wBAAuF,GAC3F,OACE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,QAAZ;AAAsBC,IAAAA,KAAK,EAAEC,aAAa,GAAG;AAA7C,GADF,EAEEC,kBAFF,KAGK;AACH;AACA,QAAI,CAACA,kBAAL,EAAyB;AACvB,YAAM,IAAIC,eAAJ,CAAW,gBAAX,CAAN;AACD;;AAED,UAAMT,gBAAgB,CAAC;AACrBU,MAAAA,aAAa,EAAEF,kBAAkB,CAACE,aADb;AAErBC,MAAAA,IAAI,EAAE,UAFe;AAGrBL,MAAAA,KAAK,EAAEC;AAHc,KAAD,CAAtB;AAMA,UAAMK,uBAAuB,GAAG,MAAMb,cAAc,CAACc,KAAf,CACpCL,kBADoC,EAEpCJ,QAFoC,EAGpCC,QAHoC,EAIpCE,aAJoC,CAAtC;AAOA,WAAOK,uBAAP;AACD,GAxBH;;AA0BAX,EAAAA,GAAG,CAAC,OAAD,EAAU,iDAAV,CAAH;AAEA,SAAO;AACLU,IAAAA,IAAI,EAAE,UADD;AAELG,IAAAA,aAAa,EAAE;AACbC,MAAAA,SAAS,EAAE,UADE;AAEbC,MAAAA,YAAY,EAAEb;AAFD;AAFV,GAAP;AAOD","sourcesContent":["import { autoService } from 'knifecycle';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport type { LogService } from 'common-services';\nimport type {\n OAuth2GranterService,\n OAuth2PasswordService,\n CheckApplicationService,\n} from './oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\nexport type OAuth2PasswordGranterDependencies = {\n oAuth2Password: OAuth2PasswordService;\n checkApplication: CheckApplicationService;\n log?: LogService;\n};\nexport type OAuth2PasswordGranterParameters = {\n username: string;\n password: string;\n scope?: string;\n};\nexport type OAuth2PasswordGranterService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = OAuth2GranterService<\n Record<string, unknown>,\n Record<string, unknown>,\n OAuth2PasswordGranterParameters,\n AUTHENTICATION_DATA\n>;\n\nexport default autoService(initOAuth2PasswordGranter);\n\n// Resource Owner Password Credentials Grant\n// https://tools.ietf.org/html/rfc6749#section-4.3\nasync function initOAuth2PasswordGranter({\n oAuth2Password,\n checkApplication,\n log = noop,\n}: OAuth2PasswordGranterDependencies): Promise<OAuth2PasswordGranterService> {\n const authenticateWithPassword: OAuth2PasswordGranterService['authenticator']['authenticate'] =\n async (\n { username, password, scope: demandedScope = '' },\n authenticationData,\n ) => {\n // The client must be authenticated\n if (!authenticationData) {\n throw new YError('E_UNAUTHORIZED');\n }\n\n await checkApplication({\n applicationId: authenticationData.applicationId,\n type: 'password',\n scope: demandedScope,\n });\n\n const finalAuthenticationData = await oAuth2Password.check(\n authenticationData,\n username,\n password,\n demandedScope,\n );\n\n return finalAuthenticationData;\n };\n\n log('debug', '👫 - OAuth2PasswordGranter Service Initialized!');\n\n return {\n type: 'password',\n authenticator: {\n grantType: 'password',\n authenticate: authenticateWithPassword,\n },\n };\n}\n"],"file":"oAuth2PasswordGranter.js"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { service as _service } from 'knifecycle';
|
|
2
|
+
import { noop } from '@whook/whook';
|
|
3
|
+
import YError from 'yerror';
|
|
4
|
+
export default _service(initOAuth2PasswordGranter, "oAuth2PasswordGranter", ["oAuth2Password", "checkApplication", "?log"]); // Resource Owner Password Credentials Grant
|
|
5
|
+
// https://tools.ietf.org/html/rfc6749#section-4.3
|
|
6
|
+
|
|
7
|
+
async function initOAuth2PasswordGranter({
|
|
8
|
+
oAuth2Password,
|
|
9
|
+
checkApplication,
|
|
10
|
+
log = noop
|
|
11
|
+
}) {
|
|
12
|
+
const authenticateWithPassword = async ({
|
|
13
|
+
username,
|
|
14
|
+
password,
|
|
15
|
+
scope: demandedScope = ''
|
|
16
|
+
}, authenticationData) => {
|
|
17
|
+
// The client must be authenticated
|
|
18
|
+
if (!authenticationData) {
|
|
19
|
+
throw new YError('E_UNAUTHORIZED');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
await checkApplication({
|
|
23
|
+
applicationId: authenticationData.applicationId,
|
|
24
|
+
type: 'password',
|
|
25
|
+
scope: demandedScope
|
|
26
|
+
});
|
|
27
|
+
const finalAuthenticationData = await oAuth2Password.check(authenticationData, username, password, demandedScope);
|
|
28
|
+
return finalAuthenticationData;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
log('debug', '👫 - OAuth2PasswordGranter Service Initialized!');
|
|
32
|
+
return {
|
|
33
|
+
type: 'password',
|
|
34
|
+
authenticator: {
|
|
35
|
+
grantType: 'password',
|
|
36
|
+
authenticate: authenticateWithPassword
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=oAuth2PasswordGranter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/oAuth2PasswordGranter.ts"],"names":["autoService","noop","YError","initOAuth2PasswordGranter","oAuth2Password","checkApplication","log","authenticateWithPassword","username","password","scope","demandedScope","authenticationData","applicationId","type","finalAuthenticationData","check","authenticator","grantType","authenticate"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,SAASC,IAAT,QAAqB,cAArB;AACA,OAAOC,MAAP,MAAmB,QAAnB;AA4BA,eAAeF,QAAW,CAACG,yBAAD,0EAA1B,C,CAEA;AACA;;AACA,eAAeA,yBAAf,CAAyC;AACvCC,EAAAA,cADuC;AAEvCC,EAAAA,gBAFuC;AAGvCC,EAAAA,GAAG,GAAGL;AAHiC,CAAzC,EAI6E;AAC3E,QAAMM,wBAAuF,GAC3F,OACE;AAAEC,IAAAA,QAAF;AAAYC,IAAAA,QAAZ;AAAsBC,IAAAA,KAAK,EAAEC,aAAa,GAAG;AAA7C,GADF,EAEEC,kBAFF,KAGK;AACH;AACA,QAAI,CAACA,kBAAL,EAAyB;AACvB,YAAM,IAAIV,MAAJ,CAAW,gBAAX,CAAN;AACD;;AAED,UAAMG,gBAAgB,CAAC;AACrBQ,MAAAA,aAAa,EAAED,kBAAkB,CAACC,aADb;AAErBC,MAAAA,IAAI,EAAE,UAFe;AAGrBJ,MAAAA,KAAK,EAAEC;AAHc,KAAD,CAAtB;AAMA,UAAMI,uBAAuB,GAAG,MAAMX,cAAc,CAACY,KAAf,CACpCJ,kBADoC,EAEpCJ,QAFoC,EAGpCC,QAHoC,EAIpCE,aAJoC,CAAtC;AAOA,WAAOI,uBAAP;AACD,GAxBH;;AA0BAT,EAAAA,GAAG,CAAC,OAAD,EAAU,iDAAV,CAAH;AAEA,SAAO;AACLQ,IAAAA,IAAI,EAAE,UADD;AAELG,IAAAA,aAAa,EAAE;AACbC,MAAAA,SAAS,EAAE,UADE;AAEbC,MAAAA,YAAY,EAAEZ;AAFD;AAFV,GAAP;AAOD","sourcesContent":["import { autoService } from 'knifecycle';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport type { LogService } from 'common-services';\nimport type {\n OAuth2GranterService,\n OAuth2PasswordService,\n CheckApplicationService,\n} from './oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\nexport type OAuth2PasswordGranterDependencies = {\n oAuth2Password: OAuth2PasswordService;\n checkApplication: CheckApplicationService;\n log?: LogService;\n};\nexport type OAuth2PasswordGranterParameters = {\n username: string;\n password: string;\n scope?: string;\n};\nexport type OAuth2PasswordGranterService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = OAuth2GranterService<\n Record<string, unknown>,\n Record<string, unknown>,\n OAuth2PasswordGranterParameters,\n AUTHENTICATION_DATA\n>;\n\nexport default autoService(initOAuth2PasswordGranter);\n\n// Resource Owner Password Credentials Grant\n// https://tools.ietf.org/html/rfc6749#section-4.3\nasync function initOAuth2PasswordGranter({\n oAuth2Password,\n checkApplication,\n log = noop,\n}: OAuth2PasswordGranterDependencies): Promise<OAuth2PasswordGranterService> {\n const authenticateWithPassword: OAuth2PasswordGranterService['authenticator']['authenticate'] =\n async (\n { username, password, scope: demandedScope = '' },\n authenticationData,\n ) => {\n // The client must be authenticated\n if (!authenticationData) {\n throw new YError('E_UNAUTHORIZED');\n }\n\n await checkApplication({\n applicationId: authenticationData.applicationId,\n type: 'password',\n scope: demandedScope,\n });\n\n const finalAuthenticationData = await oAuth2Password.check(\n authenticationData,\n username,\n password,\n demandedScope,\n );\n\n return finalAuthenticationData;\n };\n\n log('debug', '👫 - OAuth2PasswordGranter Service Initialized!');\n\n return {\n type: 'password',\n authenticator: {\n grantType: 'password',\n authenticate: authenticateWithPassword,\n },\n };\n}\n"],"file":"oAuth2PasswordGranter.mjs"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LogService } from 'common-services';
|
|
2
|
+
import type { OAuth2GranterService, CheckApplicationService, OAuth2RefreshTokenService } from './oAuth2Granters';
|
|
3
|
+
import type { BaseAuthenticationData } from '@whook/authorization';
|
|
4
|
+
export declare type OAuth2RefreshTokenGranterDependencies = {
|
|
5
|
+
checkApplication: CheckApplicationService;
|
|
6
|
+
oAuth2RefreshToken: OAuth2RefreshTokenService;
|
|
7
|
+
log?: LogService;
|
|
8
|
+
};
|
|
9
|
+
export declare type OAuth2RefreshTokenGranterParameters = {
|
|
10
|
+
refreshToken: string;
|
|
11
|
+
scope?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare type OAuth2RefreshTokenGranterService<AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData> = OAuth2GranterService<Record<string, unknown>, Record<string, unknown>, OAuth2RefreshTokenGranterParameters, AUTHENTICATION_DATA>;
|
|
14
|
+
declare const _default: import("knifecycle").ServiceInitializer<OAuth2RefreshTokenGranterDependencies, OAuth2RefreshTokenGranterService<BaseAuthenticationData<string, string>>>;
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _knifecycle = require("knifecycle");
|
|
9
|
+
|
|
10
|
+
var _whook = require("@whook/whook");
|
|
11
|
+
|
|
12
|
+
var _yerror = _interopRequireDefault(require("yerror"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
var _default = (0, _knifecycle.service)(initOAuth2RefreshTokenGranter, "oAuth2RefreshTokenGranter", ["checkApplication", "oAuth2RefreshToken", "?log"]); // Refresh Token Grant
|
|
17
|
+
// https://tools.ietf.org/html/rfc6749#page-47
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
exports.default = _default;
|
|
21
|
+
|
|
22
|
+
async function initOAuth2RefreshTokenGranter({
|
|
23
|
+
checkApplication,
|
|
24
|
+
oAuth2RefreshToken,
|
|
25
|
+
log = _whook.noop
|
|
26
|
+
}) {
|
|
27
|
+
const authenticateWithRefreshToken = async ({
|
|
28
|
+
refreshToken,
|
|
29
|
+
scope: demandedScope
|
|
30
|
+
}, authenticationData) => {
|
|
31
|
+
try {
|
|
32
|
+
// The client must be authenticated
|
|
33
|
+
if (!authenticationData) {
|
|
34
|
+
throw new _yerror.default('E_UNAUTHORIZED');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
await checkApplication({
|
|
38
|
+
applicationId: authenticationData.applicationId,
|
|
39
|
+
type: 'refresh',
|
|
40
|
+
scope: demandedScope
|
|
41
|
+
});
|
|
42
|
+
const newAuthenticationData = await oAuth2RefreshToken.check(authenticationData, refreshToken, demandedScope);
|
|
43
|
+
return newAuthenticationData;
|
|
44
|
+
} catch (err) {
|
|
45
|
+
if (err.code === 'E_BAD_TOKEN') {
|
|
46
|
+
throw _yerror.default.wrap(err, 'E_BAD_REFRESH_TOKEN');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
log('debug', '👫 - OAuth2RefreshTokenGranter Service Initialized!');
|
|
54
|
+
return {
|
|
55
|
+
type: 'refresh',
|
|
56
|
+
authenticator: {
|
|
57
|
+
grantType: 'refresh_token',
|
|
58
|
+
authenticate: authenticateWithRefreshToken
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=oAuth2RefreshTokenGranter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/oAuth2RefreshTokenGranter.ts"],"names":["initOAuth2RefreshTokenGranter","checkApplication","oAuth2RefreshToken","log","noop","authenticateWithRefreshToken","refreshToken","scope","demandedScope","authenticationData","YError","applicationId","type","newAuthenticationData","check","err","code","wrap","authenticator","grantType","authenticate"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;eA2Be,yBAAYA,6BAAZ,kF,EAEf;AACA;;;;;AACA,eAAeA,6BAAf,CAA6C;AAC3CC,EAAAA,gBAD2C;AAE3CC,EAAAA,kBAF2C;AAG3CC,EAAAA,GAAG,GAAGC;AAHqC,CAA7C,EAIqF;AACnF,QAAMC,4BAA+F,GACnG,OAAO;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA,KAAK,EAAEC;AAAvB,GAAP,EAA+CC,kBAA/C,KAAsE;AACpE,QAAI;AACF;AACA,UAAI,CAACA,kBAAL,EAAyB;AACvB,cAAM,IAAIC,eAAJ,CAAW,gBAAX,CAAN;AACD;;AAED,YAAMT,gBAAgB,CAAC;AACrBU,QAAAA,aAAa,EAAEF,kBAAkB,CAACE,aADb;AAErBC,QAAAA,IAAI,EAAE,SAFe;AAGrBL,QAAAA,KAAK,EAAEC;AAHc,OAAD,CAAtB;AAMA,YAAMK,qBAAqB,GAAG,MAAMX,kBAAkB,CAACY,KAAnB,CAClCL,kBADkC,EAElCH,YAFkC,EAGlCE,aAHkC,CAApC;AAMA,aAAOK,qBAAP;AACD,KAnBD,CAmBE,OAAOE,GAAP,EAAY;AACZ,UAAIA,GAAG,CAACC,IAAJ,KAAa,aAAjB,EAAgC;AAC9B,cAAMN,gBAAOO,IAAP,CAAYF,GAAZ,EAAiB,qBAAjB,CAAN;AACD;;AACD,YAAMA,GAAN;AACD;AACF,GA3BH;;AA6BAZ,EAAAA,GAAG,CAAC,OAAD,EAAU,qDAAV,CAAH;AAEA,SAAO;AACLS,IAAAA,IAAI,EAAE,SADD;AAELM,IAAAA,aAAa,EAAE;AACbC,MAAAA,SAAS,EAAE,eADE;AAEbC,MAAAA,YAAY,EAAEf;AAFD;AAFV,GAAP;AAOD","sourcesContent":["import { autoService } from 'knifecycle';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport type { LogService } from 'common-services';\nimport type {\n OAuth2GranterService,\n CheckApplicationService,\n OAuth2RefreshTokenService,\n} from './oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\nexport type OAuth2RefreshTokenGranterDependencies = {\n checkApplication: CheckApplicationService;\n oAuth2RefreshToken: OAuth2RefreshTokenService;\n log?: LogService;\n};\nexport type OAuth2RefreshTokenGranterParameters = {\n refreshToken: string;\n scope?: string;\n};\nexport type OAuth2RefreshTokenGranterService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = OAuth2GranterService<\n Record<string, unknown>,\n Record<string, unknown>,\n OAuth2RefreshTokenGranterParameters,\n AUTHENTICATION_DATA\n>;\n\nexport default autoService(initOAuth2RefreshTokenGranter);\n\n// Refresh Token Grant\n// https://tools.ietf.org/html/rfc6749#page-47\nasync function initOAuth2RefreshTokenGranter({\n checkApplication,\n oAuth2RefreshToken,\n log = noop,\n}: OAuth2RefreshTokenGranterDependencies): Promise<OAuth2RefreshTokenGranterService> {\n const authenticateWithRefreshToken: OAuth2RefreshTokenGranterService['authenticator']['authenticate'] =\n async ({ refreshToken, scope: demandedScope }, authenticationData) => {\n try {\n // The client must be authenticated\n if (!authenticationData) {\n throw new YError('E_UNAUTHORIZED');\n }\n\n await checkApplication({\n applicationId: authenticationData.applicationId,\n type: 'refresh',\n scope: demandedScope,\n });\n\n const newAuthenticationData = await oAuth2RefreshToken.check(\n authenticationData,\n refreshToken,\n demandedScope,\n );\n\n return newAuthenticationData;\n } catch (err) {\n if (err.code === 'E_BAD_TOKEN') {\n throw YError.wrap(err, 'E_BAD_REFRESH_TOKEN');\n }\n throw err;\n }\n };\n\n log('debug', '👫 - OAuth2RefreshTokenGranter Service Initialized!');\n\n return {\n type: 'refresh',\n authenticator: {\n grantType: 'refresh_token',\n authenticate: authenticateWithRefreshToken,\n },\n };\n}\n"],"file":"oAuth2RefreshTokenGranter.js"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { service as _service } from 'knifecycle';
|
|
2
|
+
import { noop } from '@whook/whook';
|
|
3
|
+
import YError from 'yerror';
|
|
4
|
+
export default _service(initOAuth2RefreshTokenGranter, "oAuth2RefreshTokenGranter", ["checkApplication", "oAuth2RefreshToken", "?log"]); // Refresh Token Grant
|
|
5
|
+
// https://tools.ietf.org/html/rfc6749#page-47
|
|
6
|
+
|
|
7
|
+
async function initOAuth2RefreshTokenGranter({
|
|
8
|
+
checkApplication,
|
|
9
|
+
oAuth2RefreshToken,
|
|
10
|
+
log = noop
|
|
11
|
+
}) {
|
|
12
|
+
const authenticateWithRefreshToken = async ({
|
|
13
|
+
refreshToken,
|
|
14
|
+
scope: demandedScope
|
|
15
|
+
}, authenticationData) => {
|
|
16
|
+
try {
|
|
17
|
+
// The client must be authenticated
|
|
18
|
+
if (!authenticationData) {
|
|
19
|
+
throw new YError('E_UNAUTHORIZED');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
await checkApplication({
|
|
23
|
+
applicationId: authenticationData.applicationId,
|
|
24
|
+
type: 'refresh',
|
|
25
|
+
scope: demandedScope
|
|
26
|
+
});
|
|
27
|
+
const newAuthenticationData = await oAuth2RefreshToken.check(authenticationData, refreshToken, demandedScope);
|
|
28
|
+
return newAuthenticationData;
|
|
29
|
+
} catch (err) {
|
|
30
|
+
if (err.code === 'E_BAD_TOKEN') {
|
|
31
|
+
throw YError.wrap(err, 'E_BAD_REFRESH_TOKEN');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
log('debug', '👫 - OAuth2RefreshTokenGranter Service Initialized!');
|
|
39
|
+
return {
|
|
40
|
+
type: 'refresh',
|
|
41
|
+
authenticator: {
|
|
42
|
+
grantType: 'refresh_token',
|
|
43
|
+
authenticate: authenticateWithRefreshToken
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=oAuth2RefreshTokenGranter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/services/oAuth2RefreshTokenGranter.ts"],"names":["autoService","noop","YError","initOAuth2RefreshTokenGranter","checkApplication","oAuth2RefreshToken","log","authenticateWithRefreshToken","refreshToken","scope","demandedScope","authenticationData","applicationId","type","newAuthenticationData","check","err","code","wrap","authenticator","grantType","authenticate"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,SAASC,IAAT,QAAqB,cAArB;AACA,OAAOC,MAAP,MAAmB,QAAnB;AA2BA,eAAeF,QAAW,CAACG,6BAAD,kFAA1B,C,CAEA;AACA;;AACA,eAAeA,6BAAf,CAA6C;AAC3CC,EAAAA,gBAD2C;AAE3CC,EAAAA,kBAF2C;AAG3CC,EAAAA,GAAG,GAAGL;AAHqC,CAA7C,EAIqF;AACnF,QAAMM,4BAA+F,GACnG,OAAO;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA,KAAK,EAAEC;AAAvB,GAAP,EAA+CC,kBAA/C,KAAsE;AACpE,QAAI;AACF;AACA,UAAI,CAACA,kBAAL,EAAyB;AACvB,cAAM,IAAIT,MAAJ,CAAW,gBAAX,CAAN;AACD;;AAED,YAAME,gBAAgB,CAAC;AACrBQ,QAAAA,aAAa,EAAED,kBAAkB,CAACC,aADb;AAErBC,QAAAA,IAAI,EAAE,SAFe;AAGrBJ,QAAAA,KAAK,EAAEC;AAHc,OAAD,CAAtB;AAMA,YAAMI,qBAAqB,GAAG,MAAMT,kBAAkB,CAACU,KAAnB,CAClCJ,kBADkC,EAElCH,YAFkC,EAGlCE,aAHkC,CAApC;AAMA,aAAOI,qBAAP;AACD,KAnBD,CAmBE,OAAOE,GAAP,EAAY;AACZ,UAAIA,GAAG,CAACC,IAAJ,KAAa,aAAjB,EAAgC;AAC9B,cAAMf,MAAM,CAACgB,IAAP,CAAYF,GAAZ,EAAiB,qBAAjB,CAAN;AACD;;AACD,YAAMA,GAAN;AACD;AACF,GA3BH;;AA6BAV,EAAAA,GAAG,CAAC,OAAD,EAAU,qDAAV,CAAH;AAEA,SAAO;AACLO,IAAAA,IAAI,EAAE,SADD;AAELM,IAAAA,aAAa,EAAE;AACbC,MAAAA,SAAS,EAAE,eADE;AAEbC,MAAAA,YAAY,EAAEd;AAFD;AAFV,GAAP;AAOD","sourcesContent":["import { autoService } from 'knifecycle';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport type { LogService } from 'common-services';\nimport type {\n OAuth2GranterService,\n CheckApplicationService,\n OAuth2RefreshTokenService,\n} from './oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\nexport type OAuth2RefreshTokenGranterDependencies = {\n checkApplication: CheckApplicationService;\n oAuth2RefreshToken: OAuth2RefreshTokenService;\n log?: LogService;\n};\nexport type OAuth2RefreshTokenGranterParameters = {\n refreshToken: string;\n scope?: string;\n};\nexport type OAuth2RefreshTokenGranterService<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n> = OAuth2GranterService<\n Record<string, unknown>,\n Record<string, unknown>,\n OAuth2RefreshTokenGranterParameters,\n AUTHENTICATION_DATA\n>;\n\nexport default autoService(initOAuth2RefreshTokenGranter);\n\n// Refresh Token Grant\n// https://tools.ietf.org/html/rfc6749#page-47\nasync function initOAuth2RefreshTokenGranter({\n checkApplication,\n oAuth2RefreshToken,\n log = noop,\n}: OAuth2RefreshTokenGranterDependencies): Promise<OAuth2RefreshTokenGranterService> {\n const authenticateWithRefreshToken: OAuth2RefreshTokenGranterService['authenticator']['authenticate'] =\n async ({ refreshToken, scope: demandedScope }, authenticationData) => {\n try {\n // The client must be authenticated\n if (!authenticationData) {\n throw new YError('E_UNAUTHORIZED');\n }\n\n await checkApplication({\n applicationId: authenticationData.applicationId,\n type: 'refresh',\n scope: demandedScope,\n });\n\n const newAuthenticationData = await oAuth2RefreshToken.check(\n authenticationData,\n refreshToken,\n demandedScope,\n );\n\n return newAuthenticationData;\n } catch (err) {\n if (err.code === 'E_BAD_TOKEN') {\n throw YError.wrap(err, 'E_BAD_REFRESH_TOKEN');\n }\n throw err;\n }\n };\n\n log('debug', '👫 - OAuth2RefreshTokenGranter Service Initialized!');\n\n return {\n type: 'refresh',\n authenticator: {\n grantType: 'refresh_token',\n authenticate: authenticateWithRefreshToken,\n },\n };\n}\n"],"file":"oAuth2RefreshTokenGranter.mjs"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LogService, TimeService } from 'common-services';
|
|
2
|
+
import type { OAuth2GranterService, OAuth2AccessTokenService, CheckApplicationService, OAuth2CodeService } from './oAuth2Granters';
|
|
3
|
+
import type { BaseAuthenticationData } from '@whook/authorization';
|
|
4
|
+
export declare const IMPLICIT_GRANTER_TYPE = "token";
|
|
5
|
+
export declare type OAuth2TokenGranterDependencies = {
|
|
6
|
+
oAuth2Code: OAuth2CodeService;
|
|
7
|
+
checkApplication: CheckApplicationService;
|
|
8
|
+
oAuth2AccessToken: OAuth2AccessTokenService;
|
|
9
|
+
time?: TimeService;
|
|
10
|
+
log?: LogService;
|
|
11
|
+
};
|
|
12
|
+
export declare type OAuth2TokenGranterParameters = Record<string, unknown>;
|
|
13
|
+
export declare type OAuth2TokenGranterService<AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData> = OAuth2GranterService<Record<string, unknown>, Record<string, unknown>, OAuth2TokenGranterParameters, AUTHENTICATION_DATA>;
|
|
14
|
+
declare const _default: import("knifecycle").ServiceInitializer<OAuth2TokenGranterDependencies, OAuth2TokenGranterService<BaseAuthenticationData<string, string>>>;
|
|
15
|
+
export default _default;
|