@whook/oauth2 8.5.0 → 9.0.1

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.
Files changed (88) hide show
  1. package/README.md +87 -56
  2. package/dist/handlers/getOAuth2Authorize.d.ts +5 -3
  3. package/dist/handlers/getOAuth2Authorize.js +1 -1
  4. package/dist/handlers/getOAuth2Authorize.js.map +1 -1
  5. package/dist/handlers/getOAuth2Authorize.mjs +1 -1
  6. package/dist/handlers/getOAuth2Authorize.mjs.map +1 -1
  7. package/dist/handlers/getOAuth2Authorize.test.js.map +1 -1
  8. package/dist/handlers/getOAuth2Authorize.test.mjs.map +1 -1
  9. package/dist/handlers/postAuthLogin.d.ts +2 -2
  10. package/dist/handlers/postAuthLogin.js +1 -0
  11. package/dist/handlers/postAuthLogin.js.map +1 -1
  12. package/dist/handlers/postAuthLogin.mjs +1 -0
  13. package/dist/handlers/postAuthLogin.mjs.map +1 -1
  14. package/dist/handlers/postAuthLogin.test.js.map +1 -1
  15. package/dist/handlers/postAuthLogin.test.mjs.map +1 -1
  16. package/dist/handlers/postAuthLogout.js.map +1 -1
  17. package/dist/handlers/postAuthLogout.mjs.map +1 -1
  18. package/dist/handlers/postAuthLogout.test.js.map +1 -1
  19. package/dist/handlers/postAuthLogout.test.mjs.map +1 -1
  20. package/dist/handlers/postAuthRefresh.d.ts +3 -3
  21. package/dist/handlers/postAuthRefresh.js +1 -0
  22. package/dist/handlers/postAuthRefresh.js.map +1 -1
  23. package/dist/handlers/postAuthRefresh.mjs +1 -0
  24. package/dist/handlers/postAuthRefresh.mjs.map +1 -1
  25. package/dist/handlers/postAuthRefresh.test.js.map +1 -1
  26. package/dist/handlers/postAuthRefresh.test.mjs.map +1 -1
  27. package/dist/handlers/postOAuth2Acknowledge.d.ts +10 -7
  28. package/dist/handlers/postOAuth2Acknowledge.js +2 -2
  29. package/dist/handlers/postOAuth2Acknowledge.js.map +1 -1
  30. package/dist/handlers/postOAuth2Acknowledge.mjs +2 -2
  31. package/dist/handlers/postOAuth2Acknowledge.mjs.map +1 -1
  32. package/dist/handlers/postOAuth2Acknowledge.test.js.map +1 -1
  33. package/dist/handlers/postOAuth2Acknowledge.test.mjs.map +1 -1
  34. package/dist/handlers/postOAuth2Token.d.ts +3 -3
  35. package/dist/handlers/postOAuth2Token.js +2 -2
  36. package/dist/handlers/postOAuth2Token.js.map +1 -1
  37. package/dist/handlers/postOAuth2Token.mjs +2 -2
  38. package/dist/handlers/postOAuth2Token.mjs.map +1 -1
  39. package/dist/handlers/postOAuth2Token.test.js.map +1 -1
  40. package/dist/handlers/postOAuth2Token.test.mjs.map +1 -1
  41. package/dist/index.d.ts +2 -2
  42. package/dist/index.js.map +1 -1
  43. package/dist/index.mjs.map +1 -1
  44. package/dist/index.test.js +6 -7
  45. package/dist/index.test.js.map +1 -1
  46. package/dist/index.test.mjs +6 -7
  47. package/dist/index.test.mjs.map +1 -1
  48. package/dist/services/authCookies.d.ts +7 -4
  49. package/dist/services/authCookies.js.map +1 -1
  50. package/dist/services/authCookies.mjs.map +1 -1
  51. package/dist/services/authCookies.test.js.map +1 -1
  52. package/dist/services/authCookies.test.mjs.map +1 -1
  53. package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
  54. package/dist/services/oAuth2ClientCredentialsGranter.mjs.map +1 -1
  55. package/dist/services/oAuth2CodeGranter.js.map +1 -1
  56. package/dist/services/oAuth2CodeGranter.mjs.map +1 -1
  57. package/dist/services/oAuth2CodeGranter.test.js +8 -6
  58. package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
  59. package/dist/services/oAuth2CodeGranter.test.mjs +8 -6
  60. package/dist/services/oAuth2CodeGranter.test.mjs.map +1 -1
  61. package/dist/services/oAuth2Granters.d.ts +22 -19
  62. package/dist/services/oAuth2Granters.js.map +1 -1
  63. package/dist/services/oAuth2Granters.mjs.map +1 -1
  64. package/dist/services/oAuth2PasswordGranter.js.map +1 -1
  65. package/dist/services/oAuth2PasswordGranter.mjs.map +1 -1
  66. package/dist/services/oAuth2RefreshTokenGranter.js +1 -1
  67. package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
  68. package/dist/services/oAuth2RefreshTokenGranter.mjs +1 -1
  69. package/dist/services/oAuth2RefreshTokenGranter.mjs.map +1 -1
  70. package/dist/services/oAuth2TokenGranter.js.map +1 -1
  71. package/dist/services/oAuth2TokenGranter.mjs.map +1 -1
  72. package/package.json +34 -34
  73. package/src/handlers/getOAuth2Authorize.ts +15 -14
  74. package/src/handlers/postAuthLogin.ts +4 -3
  75. package/src/handlers/postAuthRefresh.ts +4 -3
  76. package/src/handlers/postOAuth2Acknowledge.ts +34 -26
  77. package/src/handlers/postOAuth2Token.test.ts +2 -2
  78. package/src/handlers/postOAuth2Token.ts +4 -4
  79. package/src/index.test.ts +8 -9
  80. package/src/index.ts +6 -4
  81. package/src/services/authCookies.ts +8 -4
  82. package/src/services/oAuth2ClientCredentialsGranter.ts +25 -21
  83. package/src/services/oAuth2CodeGranter.test.ts +15 -14
  84. package/src/services/oAuth2CodeGranter.ts +66 -60
  85. package/src/services/oAuth2Granters.ts +59 -29
  86. package/src/services/oAuth2PasswordGranter.ts +23 -22
  87. package/src/services/oAuth2RefreshTokenGranter.ts +28 -24
  88. package/src/services/oAuth2TokenGranter.ts +44 -42
@@ -8,18 +8,18 @@ export declare const clientCredentialsTokenRequestBodySchema: WhookAPISchemaDefi
8
8
  export declare const refreshTokenRequestBodySchema: WhookAPISchemaDefinition;
9
9
  export declare const tokenBodySchema: WhookAPISchemaDefinition;
10
10
  export declare const definition: WhookAPIHandlerDefinition;
11
- declare const _default: <AUTHENTICATION_DATA extends BaseAuthenticationData<string, string> = BaseAuthenticationData<string, string>>(dependencies?: {
11
+ declare const _default: import("knifecycle").ServiceInitializer<{
12
12
  oAuth2Granters: OAuth2GranterService<Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, BaseAuthenticationData<string, string>>[];
13
13
  oAuth2AccessToken: OAuth2AccessTokenService<BaseAuthenticationData<string, string>, string>;
14
14
  oAuth2RefreshToken: OAuth2RefreshTokenService<BaseAuthenticationData<string, string>, string>;
15
15
  log: LogService;
16
16
  time: TimeService;
17
- }) => Promise<(parameters: {
17
+ }, (parameters: {
18
18
  body: {
19
19
  [name: string]: unknown;
20
20
  grant_type: string;
21
21
  };
22
- authenticationData: AUTHENTICATION_DATA;
22
+ authenticationData: BaseAuthenticationData<string, string>;
23
23
  }) => Promise<{
24
24
  status: number;
25
25
  headers: {};
@@ -216,7 +216,7 @@ async function postOAuth2Token({
216
216
  try {
217
217
  const granter = oAuth2Granters.find(granter => granter.authenticator && granter.authenticator.grantType === grantType);
218
218
 
219
- if (!granter) {
219
+ if (!granter || !granter.authenticator) {
220
220
  throw new _yerror.default('E_UNKNOWN_AUTHENTICATOR_TYPE', grantType);
221
221
  }
222
222
 
@@ -244,7 +244,7 @@ async function postOAuth2Token({
244
244
  };
245
245
  } catch (err) {
246
246
  log('debug', '👫 - OAuth2 token issuing error', err.code);
247
- log('debug-stack', err.stack);
247
+ log('debug-stack', err.stack || 'no_stack_trace');
248
248
  throw _yerror.default.cast(err, 'E_OAUTH2');
249
249
  }
250
250
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/handlers/postOAuth2Token.ts"],"names":["authorizationCodeTokenRequestBodySchema","name","schema","type","description","required","properties","grant_type","enum","code","client_id","redirect_uri","pattern","format","passwordTokenRequestBodySchema","username","password","scope","clientCredentialsTokenRequestBodySchema","refreshTokenRequestBodySchema","refresh_token","tokenBodySchema","oneOf","definition","method","path","operation","operationId","summary","tags","parameters","requestBody","content","responses","access_token","token_type","expires_in","error","error_description","error_uri","postOAuth2Token","oAuth2Granters","oAuth2AccessToken","oAuth2RefreshToken","time","Date","now","bind","log","noop","body","grantType","grantParameters","authenticationData","granter","find","authenticator","YError","newAuthenticationData","authenticate","token","accessToken","expiresAt","accessTokenExpiresAt","refreshToken","refreshTokenExpiresAt","Promise","all","create","currentTime","status","headers","Math","ceil","expiration_date","toISOString","refresh_token_expires_in","refresh_token_expiration_date","err","stack","cast"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;AAeA;AACA;AACA;AACA;AACO,MAAMA,uCAAiE,GAC5E;AACEC,EAAAA,IAAI,EAAE,8BADR;AAEEC,EAAAA,MAAM,EAAE;AACNC,IAAAA,IAAI,EAAE,QADA;AAENC,IAAAA,WAAW,EACT,+EAHI;AAINC,IAAAA,QAAQ,EAAE,CAAC,YAAD,CAJJ;AAKNC,IAAAA,UAAU,EAAE;AACVC,MAAAA,UAAU,EAAE;AACVJ,QAAAA,IAAI,EAAE,QADI;AAEVK,QAAAA,IAAI,EAAE,CAAC,oBAAD;AAFI,OADF;AAKVC,MAAAA,IAAI,EAAE;AACJN,QAAAA,IAAI,EAAE;AADF,OALI;AAQVO,MAAAA,SAAS,EAAE;AACTP,QAAAA,IAAI,EAAE;AADG,OARD;AAWVQ,MAAAA,YAAY,EAAE;AACZR,QAAAA,IAAI,EAAE,QADM;AAEZS,QAAAA,OAAO,EAAE,YAFG;AAGZC,QAAAA,MAAM,EAAE;AAHI;AAXJ;AALN;AAFV,CADK;;AA4BA,MAAMC,8BAAwD,GAAG;AACtEb,EAAAA,IAAI,EAAE,qBADgE;AAEtEC,EAAAA,MAAM,EAAE;AACNC,IAAAA,IAAI,EAAE,QADA;AAENC,IAAAA,WAAW,EACT,gGAHI;AAINC,IAAAA,QAAQ,EAAE,CAAC,YAAD,EAAe,UAAf,EAA2B,UAA3B,CAJJ;AAKNC,IAAAA,UAAU,EAAE;AACVC,MAAAA,UAAU,EAAE;AACVJ,QAAAA,IAAI,EAAE,QADI;AAEVK,QAAAA,IAAI,EAAE,CAAC,UAAD;AAFI,OADF;AAKVO,MAAAA,QAAQ,EAAE;AACRZ,QAAAA,IAAI,EAAE;AADE,OALA;AAQVa,MAAAA,QAAQ,EAAE;AACRb,QAAAA,IAAI,EAAE;AADE,OARA;AAWVc,MAAAA,KAAK,EAAE;AACLd,QAAAA,IAAI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rE,IAAjD,CAAH;AACAuC,IAAAA,GAAG,CAAC,aAAD,EAAgB8B,GAAG,CAACC,KAApB,CAAH;AAEA,UAAMtB,gBAAOuB,IAAP,CAAYF,GAAZ,EAAiB,UAAjB,CAAN;AACD;AACF","sourcesContent":["import { autoHandler } from 'knifecycle';\nimport { camelCaseObjectProperties } from './getOAuth2Authorize';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport { refersTo } from '@whook/whook';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { LogService, TimeService } from 'common-services';\nimport type {\n WhookAPISchemaDefinition,\n WhookAPIHandlerDefinition,\n} from '@whook/whook';\nimport type {\n OAuth2GranterService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n} from '../services/oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\n/* Architecture Note #2: OAuth2 acknowledge\nThis endpoint is to be used by the authentication server page\n to acknowlege that the user accepted the client request.\n*/\nexport const authorizationCodeTokenRequestBodySchema: WhookAPISchemaDefinition =\n {\n name: 'AuthorizationCodeRequestBody',\n schema: {\n type: 'object',\n description:\n 'Authorization code grant, see https://tools.ietf.org/html/rfc6749#section-4.1',\n required: ['grant_type'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['authorization_code'],\n },\n code: {\n type: 'string',\n },\n client_id: {\n type: 'string',\n },\n redirect_uri: {\n type: 'string',\n pattern: '^https?://',\n format: 'uri',\n },\n },\n },\n };\n\nexport const passwordTokenRequestBodySchema: WhookAPISchemaDefinition = {\n name: 'PasswordRequestBody',\n schema: {\n type: 'object',\n description:\n 'Resource owner password credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.3',\n required: ['grant_type', 'username', 'password'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['password'],\n },\n username: {\n type: 'string',\n },\n password: {\n type: 'string',\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n};\n\nexport const clientCredentialsTokenRequestBodySchema: WhookAPISchemaDefinition =\n {\n name: 'ClientCredentialsRequestBody',\n schema: {\n type: 'object',\n description:\n 'Client credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.4',\n required: ['grant_type'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['client_credentials'],\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n };\n\nexport const refreshTokenRequestBodySchema: WhookAPISchemaDefinition = {\n name: 'RefreshTokenRequestBody',\n schema: {\n type: 'object',\n description:\n 'Token refresh grant type, see https://tools.ietf.org/html/rfc6749#section-6 .',\n required: ['grant_type', 'refresh_token'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['refresh_token'],\n },\n refresh_token: {\n type: 'string',\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n};\n\nexport const tokenBodySchema: WhookAPISchemaDefinition = {\n name: 'TokenRequestBody',\n schema: {\n oneOf: [\n refersTo(passwordTokenRequestBodySchema),\n refersTo(authorizationCodeTokenRequestBodySchema),\n refersTo(clientCredentialsTokenRequestBodySchema),\n refersTo(refreshTokenRequestBodySchema),\n ],\n } as OpenAPIV3.SchemaObject,\n};\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: '/oauth2/token',\n operation: {\n operationId: 'postOAuth2Token',\n summary: `Implements the [Token Endpoint](https://tools.ietf.org/html/rfc6749#section-3.2)\n as defined per the OAuth2 RFC.`,\n tags: ['oauth2'],\n parameters: [],\n requestBody: {\n required: true,\n content: {\n 'application/x-www-form-urlencoded': {\n schema: refersTo(tokenBodySchema),\n },\n 'application/json': {\n schema: refersTo(tokenBodySchema),\n },\n },\n },\n responses: {\n '200': {\n description:\n 'Token successfully issued, see https://tools.ietf.org/html/rfc6749#section-5 .',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['access_token', 'token_type'],\n properties: {\n access_token: { type: 'string' },\n token_type: {\n description:\n 'See https://tools.ietf.org/html/rfc6749#section-7.1',\n type: 'string',\n enum: ['bearer', 'mac'],\n },\n expires_in: {\n description: 'The lifetime in seconds of the access token',\n type: 'number',\n },\n refresh_token: {\n description:\n 'See https://tools.ietf.org/html/rfc6749#section-6',\n type: 'string',\n },\n },\n },\n },\n },\n },\n '400': {\n description:\n 'Access token error response, see https://tools.ietf.org/html/rfc6749#section-5.2',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['error'],\n properties: {\n error: {\n type: 'string',\n enum: [\n 'invalid_request',\n 'invalid_client',\n 'invalid_grant',\n 'unauthorized_client',\n 'unsupported_grant_type',\n 'invalid_scope',\n ],\n },\n error_description: { type: 'string' },\n error_uri: { type: 'string' },\n },\n },\n },\n },\n },\n },\n },\n};\n\nexport default autoHandler(postOAuth2Token);\n\nasync function postOAuth2Token<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time = Date.now.bind(Date),\n log = noop,\n }: {\n oAuth2Granters: OAuth2GranterService[];\n oAuth2AccessToken: OAuth2AccessTokenService;\n oAuth2RefreshToken: OAuth2RefreshTokenService;\n log: LogService;\n time: TimeService;\n },\n {\n body: { grant_type: grantType, ...grantParameters },\n authenticationData,\n }: {\n body: {\n grant_type: string;\n [name: string]: unknown;\n };\n authenticationData: AUTHENTICATION_DATA;\n },\n) {\n try {\n const granter = oAuth2Granters.find(\n (granter) =>\n granter.authenticator && granter.authenticator.grantType === grantType,\n );\n\n if (!granter) {\n throw new YError('E_UNKNOWN_AUTHENTICATOR_TYPE', grantType);\n }\n\n const newAuthenticationData = await granter.authenticator.authenticate(\n camelCaseObjectProperties(grantParameters),\n authenticationData,\n );\n\n const [\n { token: accessToken, expiresAt: accessTokenExpiresAt },\n { token: refreshToken, expiresAt: refreshTokenExpiresAt },\n ] = await Promise.all([\n oAuth2AccessToken.create(authenticationData, newAuthenticationData),\n oAuth2RefreshToken.create(authenticationData, newAuthenticationData),\n ]);\n const currentTime = time();\n\n return {\n status: 200,\n headers: {},\n body: {\n access_token: accessToken,\n token_type: 'bearer',\n expires_in: Math.ceil((accessTokenExpiresAt - currentTime) / 1000),\n expiration_date: new Date(accessTokenExpiresAt).toISOString(),\n refresh_token: refreshToken,\n refresh_token_expires_in: Math.ceil(\n (refreshTokenExpiresAt - currentTime) / 1000,\n ),\n refresh_token_expiration_date: new Date(\n refreshTokenExpiresAt,\n ).toISOString(),\n },\n };\n } catch (err) {\n log('debug', '👫 - OAuth2 token issuing error', err.code);\n log('debug-stack', err.stack);\n\n throw YError.cast(err, 'E_OAUTH2');\n }\n}\n"],"file":"postOAuth2Token.js"}
1
+ {"version":3,"file":"postOAuth2Token.js","names":["authorizationCodeTokenRequestBodySchema","name","schema","type","description","required","properties","grant_type","enum","code","client_id","redirect_uri","pattern","format","passwordTokenRequestBodySchema","username","password","scope","clientCredentialsTokenRequestBodySchema","refreshTokenRequestBodySchema","refresh_token","tokenBodySchema","oneOf","refersTo","definition","method","path","operation","operationId","summary","tags","parameters","requestBody","content","responses","access_token","token_type","expires_in","error","error_description","error_uri","autoHandler","postOAuth2Token","oAuth2Granters","oAuth2AccessToken","oAuth2RefreshToken","time","Date","now","bind","log","noop","body","grantType","grantParameters","authenticationData","granter","find","authenticator","YError","newAuthenticationData","authenticate","camelCaseObjectProperties","token","accessToken","expiresAt","accessTokenExpiresAt","refreshToken","refreshTokenExpiresAt","Promise","all","create","currentTime","status","headers","Math","ceil","expiration_date","toISOString","refresh_token_expires_in","refresh_token_expiration_date","err","stack","cast"],"sources":["../../src/handlers/postOAuth2Token.ts"],"sourcesContent":["import { autoHandler } from 'knifecycle';\nimport { camelCaseObjectProperties } from './getOAuth2Authorize';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport { refersTo } from '@whook/whook';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { LogService, TimeService } from 'common-services';\nimport type {\n WhookAPISchemaDefinition,\n WhookAPIHandlerDefinition,\n} from '@whook/whook';\nimport type {\n OAuth2GranterService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n} from '../services/oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\n/* Architecture Note #2: OAuth2 acknowledge\nThis endpoint is to be used by the authentication server page\n to acknowlege that the user accepted the client request.\n*/\nexport const authorizationCodeTokenRequestBodySchema: WhookAPISchemaDefinition =\n {\n name: 'AuthorizationCodeRequestBody',\n schema: {\n type: 'object',\n description:\n 'Authorization code grant, see https://tools.ietf.org/html/rfc6749#section-4.1',\n required: ['grant_type'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['authorization_code'],\n },\n code: {\n type: 'string',\n },\n client_id: {\n type: 'string',\n },\n redirect_uri: {\n type: 'string',\n pattern: '^https?://',\n format: 'uri',\n },\n },\n },\n };\n\nexport const passwordTokenRequestBodySchema: WhookAPISchemaDefinition = {\n name: 'PasswordRequestBody',\n schema: {\n type: 'object',\n description:\n 'Resource owner password credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.3',\n required: ['grant_type', 'username', 'password'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['password'],\n },\n username: {\n type: 'string',\n },\n password: {\n type: 'string',\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n};\n\nexport const clientCredentialsTokenRequestBodySchema: WhookAPISchemaDefinition =\n {\n name: 'ClientCredentialsRequestBody',\n schema: {\n type: 'object',\n description:\n 'Client credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.4',\n required: ['grant_type'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['client_credentials'],\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n };\n\nexport const refreshTokenRequestBodySchema: WhookAPISchemaDefinition = {\n name: 'RefreshTokenRequestBody',\n schema: {\n type: 'object',\n description:\n 'Token refresh grant type, see https://tools.ietf.org/html/rfc6749#section-6 .',\n required: ['grant_type', 'refresh_token'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['refresh_token'],\n },\n refresh_token: {\n type: 'string',\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n};\n\nexport const tokenBodySchema: WhookAPISchemaDefinition = {\n name: 'TokenRequestBody',\n schema: {\n oneOf: [\n refersTo(passwordTokenRequestBodySchema),\n refersTo(authorizationCodeTokenRequestBodySchema),\n refersTo(clientCredentialsTokenRequestBodySchema),\n refersTo(refreshTokenRequestBodySchema),\n ],\n } as OpenAPIV3.SchemaObject,\n};\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: '/oauth2/token',\n operation: {\n operationId: 'postOAuth2Token',\n summary: `Implements the [Token Endpoint](https://tools.ietf.org/html/rfc6749#section-3.2)\n as defined per the OAuth2 RFC.`,\n tags: ['oauth2'],\n parameters: [],\n requestBody: {\n required: true,\n content: {\n 'application/x-www-form-urlencoded': {\n schema: refersTo(tokenBodySchema),\n },\n 'application/json': {\n schema: refersTo(tokenBodySchema),\n },\n },\n },\n responses: {\n '200': {\n description:\n 'Token successfully issued, see https://tools.ietf.org/html/rfc6749#section-5 .',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['access_token', 'token_type'],\n properties: {\n access_token: { type: 'string' },\n token_type: {\n description:\n 'See https://tools.ietf.org/html/rfc6749#section-7.1',\n type: 'string',\n enum: ['bearer', 'mac'],\n },\n expires_in: {\n description: 'The lifetime in seconds of the access token',\n type: 'number',\n },\n refresh_token: {\n description:\n 'See https://tools.ietf.org/html/rfc6749#section-6',\n type: 'string',\n },\n },\n },\n },\n },\n },\n '400': {\n description:\n 'Access token error response, see https://tools.ietf.org/html/rfc6749#section-5.2',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['error'],\n properties: {\n error: {\n type: 'string',\n enum: [\n 'invalid_request',\n 'invalid_client',\n 'invalid_grant',\n 'unauthorized_client',\n 'unsupported_grant_type',\n 'invalid_scope',\n ],\n },\n error_description: { type: 'string' },\n error_uri: { type: 'string' },\n },\n },\n },\n },\n },\n },\n },\n};\n\nexport default autoHandler(postOAuth2Token);\n\nasync function postOAuth2Token<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time = Date.now.bind(Date),\n log = noop,\n }: {\n oAuth2Granters: OAuth2GranterService[];\n oAuth2AccessToken: OAuth2AccessTokenService;\n oAuth2RefreshToken: OAuth2RefreshTokenService;\n log: LogService;\n time: TimeService;\n },\n {\n body: { grant_type: grantType, ...grantParameters },\n authenticationData,\n }: {\n body: {\n grant_type: string;\n [name: string]: unknown;\n };\n authenticationData: AUTHENTICATION_DATA;\n },\n) {\n try {\n const granter = oAuth2Granters.find(\n (granter) =>\n granter.authenticator && granter.authenticator.grantType === grantType,\n );\n\n if (!granter || !granter.authenticator) {\n throw new YError('E_UNKNOWN_AUTHENTICATOR_TYPE', grantType);\n }\n\n const newAuthenticationData = await granter.authenticator.authenticate(\n camelCaseObjectProperties(grantParameters),\n authenticationData,\n );\n\n const [\n { token: accessToken, expiresAt: accessTokenExpiresAt },\n { token: refreshToken, expiresAt: refreshTokenExpiresAt },\n ] = await Promise.all([\n oAuth2AccessToken.create(authenticationData, newAuthenticationData),\n oAuth2RefreshToken.create(authenticationData, newAuthenticationData),\n ]);\n const currentTime = time();\n\n return {\n status: 200,\n headers: {},\n body: {\n access_token: accessToken,\n token_type: 'bearer',\n expires_in: Math.ceil((accessTokenExpiresAt - currentTime) / 1000),\n expiration_date: new Date(accessTokenExpiresAt).toISOString(),\n refresh_token: refreshToken,\n refresh_token_expires_in: Math.ceil(\n (refreshTokenExpiresAt - currentTime) / 1000,\n ),\n refresh_token_expiration_date: new Date(\n refreshTokenExpiresAt,\n ).toISOString(),\n },\n };\n } catch (err) {\n log('debug', '👫 - OAuth2 token issuing error', (err as YError).code);\n log('debug-stack', (err as Error).stack || 'no_stack_trace');\n\n throw YError.cast(err as Error, 'E_OAUTH2');\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;;;AAeA;AACA;AACA;AACA;AACO,MAAMA,uCAAiE,GAC5E;EACEC,IAAI,EAAE,8BADR;EAEEC,MAAM,EAAE;IACNC,IAAI,EAAE,QADA;IAENC,WAAW,EACT,+EAHI;IAINC,QAAQ,EAAE,CAAC,YAAD,CAJJ;IAKNC,UAAU,EAAE;MACVC,UAAU,EAAE;QACVJ,IAAI,EAAE,QADI;QAEVK,IAAI,EAAE,CAAC,oBAAD;MAFI,CADF;MAKVC,IAAI,EAAE;QACJN,IAAI,EAAE;MADF,CALI;MAQVO,SAAS,EAAE;QACTP,IAAI,EAAE;MADG,CARD;MAWVQ,YAAY,EAAE;QACZR,IAAI,EAAE,QADM;QAEZS,OAAO,EAAE,YAFG;QAGZC,MAAM,EAAE;MAHI;IAXJ;EALN;AAFV,CADK;;AA4BA,MAAMC,8BAAwD,GAAG;EACtEb,IAAI,EAAE,qBADgE;EAEtEC,MAAM,EAAE;IACNC,IAAI,EAAE,QADA;IAENC,WAAW,EACT,gGAHI;IAINC,QAAQ,EAAE,CAAC,YAAD,EAAe,UAAf,EAA2B,UAA3B,CAJJ;IAKNC,UAAU,EAAE;MACVC,UAAU,EAAE;QACVJ,IAAI,EAAE,QADI;QAEVK,IAAI,EAAE,CAAC,UAAD;MAFI,CADF;MAKVO,QAAQ,EAAE;QACRZ,IAAI,EAAE;MADE,CALA;MAQVa,QAAQ,EAAE;QACRb,IAAI,EAAE;MADE,CARA;MAWVc,KAAK,EAAE;QACLd,IAAI,EAAE,QADD;QAELC,WAAW,EAAE;MAFR;IAXG;EALN;AAF8D,CAAjE;;AA0BA,MAAMc,uCAAiE,GAC5E;EACEjB,IAAI,EAAE,8BADR;EAEEC,MAAM,EAAE;IACNC,IAAI,EAAE,QADA;IAENC,WAAW,EACT,+EAHI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QAFR;QAGJC,UAAU,EAAEsC,IAAI,CAACC,IAAL,CAAU,CAACV,oBAAoB,GAAGM,WAAxB,IAAuC,IAAjD,CAHR;QAIJK,eAAe,EAAE,IAAI9B,IAAJ,CAASmB,oBAAT,EAA+BY,WAA/B,EAJb;QAKJ1D,aAAa,EAAE+C,YALX;QAMJY,wBAAwB,EAAEJ,IAAI,CAACC,IAAL,CACxB,CAACR,qBAAqB,GAAGI,WAAzB,IAAwC,IADhB,CANtB;QASJQ,6BAA6B,EAAE,IAAIjC,IAAJ,CAC7BqB,qBAD6B,EAE7BU,WAF6B;MAT3B;IAHD,CAAP;EAiBD,CAzCD,CAyCE,OAAOG,GAAP,EAAY;IACZ/B,GAAG,CAAC,OAAD,EAAU,iCAAV,EAA8C+B,GAAD,CAAgBxE,IAA7D,CAAH;IACAyC,GAAG,CAAC,aAAD,EAAiB+B,GAAD,CAAeC,KAAf,IAAwB,gBAAxC,CAAH;IAEA,MAAMvB,eAAA,CAAOwB,IAAP,CAAYF,GAAZ,EAA0B,UAA1B,CAAN;EACD;AACF"}
@@ -196,7 +196,7 @@ async function postOAuth2Token({
196
196
  try {
197
197
  const granter = oAuth2Granters.find(granter => granter.authenticator && granter.authenticator.grantType === grantType);
198
198
 
199
- if (!granter) {
199
+ if (!granter || !granter.authenticator) {
200
200
  throw new YError('E_UNKNOWN_AUTHENTICATOR_TYPE', grantType);
201
201
  }
202
202
 
@@ -224,7 +224,7 @@ async function postOAuth2Token({
224
224
  };
225
225
  } catch (err) {
226
226
  log('debug', '👫 - OAuth2 token issuing error', err.code);
227
- log('debug-stack', err.stack);
227
+ log('debug-stack', err.stack || 'no_stack_trace');
228
228
  throw YError.cast(err, 'E_OAUTH2');
229
229
  }
230
230
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/handlers/postOAuth2Token.ts"],"names":["autoHandler","camelCaseObjectProperties","noop","YError","refersTo","authorizationCodeTokenRequestBodySchema","name","schema","type","description","required","properties","grant_type","enum","code","client_id","redirect_uri","pattern","format","passwordTokenRequestBodySchema","username","password","scope","clientCredentialsTokenRequestBodySchema","refreshTokenRequestBodySchema","refresh_token","tokenBodySchema","oneOf","definition","method","path","operation","operationId","summary","tags","parameters","requestBody","content","responses","access_token","token_type","expires_in","error","error_description","error_uri","postOAuth2Token","oAuth2Granters","oAuth2AccessToken","oAuth2RefreshToken","time","Date","now","bind","log","body","grantType","grantParameters","authenticationData","granter","find","authenticator","newAuthenticationData","authenticate","token","accessToken","expiresAt","accessTokenExpiresAt","refreshToken","refreshTokenExpiresAt","Promise","all","create","currentTime","status","headers","Math","ceil","expiration_date","toISOString","refresh_token_expires_in","refresh_token_expiration_date","err","stack","cast"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,SAASC,yBAAT,QAA0C,sBAA1C;AACA,SAASC,IAAT,QAAqB,cAArB;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,SAASC,QAAT,QAAyB,cAAzB;;AAcA;AACA;AACA;AACA;AACA,OAAO,MAAMC,uCAAiE,GAC5E;AACEC,EAAAA,IAAI,EAAE,8BADR;AAEEC,EAAAA,MAAM,EAAE;AACNC,IAAAA,IAAI,EAAE,QADA;AAENC,IAAAA,WAAW,EACT,+EAHI;AAINC,IAAAA,QAAQ,EAAE,CAAC,YAAD,CAJJ;AAKNC,IAAAA,UAAU,EAAE;AACVC,MAAAA,UAAU,EAAE;AACVJ,QAAAA,IAAI,EAAE,QADI;AAEVK,QAAAA,IAAI,EAAE,CAAC,oBAAD;AAFI,OADF;AAKVC,MAAAA,IAAI,EAAE;AACJN,QAAAA,IAAI,EAAE;AADF,OALI;AAQVO,MAAAA,SAAS,EAAE;AACTP,QAAAA,IAAI,EAAE;AADG,OARD;AAWVQ,MAAAA,YAAY,EAAE;AACZR,QAAAA,IAAI,EAAE,QADM;AAEZS,QAAAA,OAAO,EAAE,YAFG;AAGZC,QAAAA,MAAM,EAAE;AAHI;AAXJ;AALN;AAFV,CADK;AA4BP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AAA,IAAI,EAAE;AACJf,QAAAA,YAAY,EAAEyB,WADV;AAEJxB,QAAAA,UAAU,EAAE,QAFR;AAGJC,QAAAA,UAAU,EAAEkC,IAAI,CAACC,IAAL,CAAU,CAACV,oBAAoB,GAAGM,WAAxB,IAAuC,IAAjD,CAHR;AAIJK,QAAAA,eAAe,EAAE,IAAI3B,IAAJ,CAASgB,oBAAT,EAA+BY,WAA/B,EAJb;AAKJrD,QAAAA,aAAa,EAAE0C,YALX;AAMJY,QAAAA,wBAAwB,EAAEJ,IAAI,CAACC,IAAL,CACxB,CAACR,qBAAqB,GAAGI,WAAzB,IAAwC,IADhB,CANtB;AASJQ,QAAAA,6BAA6B,EAAE,IAAI9B,IAAJ,CAC7BkB,qBAD6B,EAE7BU,WAF6B;AAT3B;AAHD,KAAP;AAiBD,GAzCD,CAyCE,OAAOG,GAAP,EAAY;AACZ5B,IAAAA,GAAG,CAAC,OAAD,EAAU,iCAAV,EAA6C4B,GAAG,CAACnE,IAAjD,CAAH;AACAuC,IAAAA,GAAG,CAAC,aAAD,EAAgB4B,GAAG,CAACC,KAApB,CAAH;AAEA,UAAM/E,MAAM,CAACgF,IAAP,CAAYF,GAAZ,EAAiB,UAAjB,CAAN;AACD;AACF","sourcesContent":["import { autoHandler } from 'knifecycle';\nimport { camelCaseObjectProperties } from './getOAuth2Authorize';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport { refersTo } from '@whook/whook';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { LogService, TimeService } from 'common-services';\nimport type {\n WhookAPISchemaDefinition,\n WhookAPIHandlerDefinition,\n} from '@whook/whook';\nimport type {\n OAuth2GranterService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n} from '../services/oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\n/* Architecture Note #2: OAuth2 acknowledge\nThis endpoint is to be used by the authentication server page\n to acknowlege that the user accepted the client request.\n*/\nexport const authorizationCodeTokenRequestBodySchema: WhookAPISchemaDefinition =\n {\n name: 'AuthorizationCodeRequestBody',\n schema: {\n type: 'object',\n description:\n 'Authorization code grant, see https://tools.ietf.org/html/rfc6749#section-4.1',\n required: ['grant_type'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['authorization_code'],\n },\n code: {\n type: 'string',\n },\n client_id: {\n type: 'string',\n },\n redirect_uri: {\n type: 'string',\n pattern: '^https?://',\n format: 'uri',\n },\n },\n },\n };\n\nexport const passwordTokenRequestBodySchema: WhookAPISchemaDefinition = {\n name: 'PasswordRequestBody',\n schema: {\n type: 'object',\n description:\n 'Resource owner password credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.3',\n required: ['grant_type', 'username', 'password'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['password'],\n },\n username: {\n type: 'string',\n },\n password: {\n type: 'string',\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n};\n\nexport const clientCredentialsTokenRequestBodySchema: WhookAPISchemaDefinition =\n {\n name: 'ClientCredentialsRequestBody',\n schema: {\n type: 'object',\n description:\n 'Client credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.4',\n required: ['grant_type'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['client_credentials'],\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n };\n\nexport const refreshTokenRequestBodySchema: WhookAPISchemaDefinition = {\n name: 'RefreshTokenRequestBody',\n schema: {\n type: 'object',\n description:\n 'Token refresh grant type, see https://tools.ietf.org/html/rfc6749#section-6 .',\n required: ['grant_type', 'refresh_token'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['refresh_token'],\n },\n refresh_token: {\n type: 'string',\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n};\n\nexport const tokenBodySchema: WhookAPISchemaDefinition = {\n name: 'TokenRequestBody',\n schema: {\n oneOf: [\n refersTo(passwordTokenRequestBodySchema),\n refersTo(authorizationCodeTokenRequestBodySchema),\n refersTo(clientCredentialsTokenRequestBodySchema),\n refersTo(refreshTokenRequestBodySchema),\n ],\n } as OpenAPIV3.SchemaObject,\n};\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: '/oauth2/token',\n operation: {\n operationId: 'postOAuth2Token',\n summary: `Implements the [Token Endpoint](https://tools.ietf.org/html/rfc6749#section-3.2)\n as defined per the OAuth2 RFC.`,\n tags: ['oauth2'],\n parameters: [],\n requestBody: {\n required: true,\n content: {\n 'application/x-www-form-urlencoded': {\n schema: refersTo(tokenBodySchema),\n },\n 'application/json': {\n schema: refersTo(tokenBodySchema),\n },\n },\n },\n responses: {\n '200': {\n description:\n 'Token successfully issued, see https://tools.ietf.org/html/rfc6749#section-5 .',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['access_token', 'token_type'],\n properties: {\n access_token: { type: 'string' },\n token_type: {\n description:\n 'See https://tools.ietf.org/html/rfc6749#section-7.1',\n type: 'string',\n enum: ['bearer', 'mac'],\n },\n expires_in: {\n description: 'The lifetime in seconds of the access token',\n type: 'number',\n },\n refresh_token: {\n description:\n 'See https://tools.ietf.org/html/rfc6749#section-6',\n type: 'string',\n },\n },\n },\n },\n },\n },\n '400': {\n description:\n 'Access token error response, see https://tools.ietf.org/html/rfc6749#section-5.2',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['error'],\n properties: {\n error: {\n type: 'string',\n enum: [\n 'invalid_request',\n 'invalid_client',\n 'invalid_grant',\n 'unauthorized_client',\n 'unsupported_grant_type',\n 'invalid_scope',\n ],\n },\n error_description: { type: 'string' },\n error_uri: { type: 'string' },\n },\n },\n },\n },\n },\n },\n },\n};\n\nexport default autoHandler(postOAuth2Token);\n\nasync function postOAuth2Token<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time = Date.now.bind(Date),\n log = noop,\n }: {\n oAuth2Granters: OAuth2GranterService[];\n oAuth2AccessToken: OAuth2AccessTokenService;\n oAuth2RefreshToken: OAuth2RefreshTokenService;\n log: LogService;\n time: TimeService;\n },\n {\n body: { grant_type: grantType, ...grantParameters },\n authenticationData,\n }: {\n body: {\n grant_type: string;\n [name: string]: unknown;\n };\n authenticationData: AUTHENTICATION_DATA;\n },\n) {\n try {\n const granter = oAuth2Granters.find(\n (granter) =>\n granter.authenticator && granter.authenticator.grantType === grantType,\n );\n\n if (!granter) {\n throw new YError('E_UNKNOWN_AUTHENTICATOR_TYPE', grantType);\n }\n\n const newAuthenticationData = await granter.authenticator.authenticate(\n camelCaseObjectProperties(grantParameters),\n authenticationData,\n );\n\n const [\n { token: accessToken, expiresAt: accessTokenExpiresAt },\n { token: refreshToken, expiresAt: refreshTokenExpiresAt },\n ] = await Promise.all([\n oAuth2AccessToken.create(authenticationData, newAuthenticationData),\n oAuth2RefreshToken.create(authenticationData, newAuthenticationData),\n ]);\n const currentTime = time();\n\n return {\n status: 200,\n headers: {},\n body: {\n access_token: accessToken,\n token_type: 'bearer',\n expires_in: Math.ceil((accessTokenExpiresAt - currentTime) / 1000),\n expiration_date: new Date(accessTokenExpiresAt).toISOString(),\n refresh_token: refreshToken,\n refresh_token_expires_in: Math.ceil(\n (refreshTokenExpiresAt - currentTime) / 1000,\n ),\n refresh_token_expiration_date: new Date(\n refreshTokenExpiresAt,\n ).toISOString(),\n },\n };\n } catch (err) {\n log('debug', '👫 - OAuth2 token issuing error', err.code);\n log('debug-stack', err.stack);\n\n throw YError.cast(err, 'E_OAUTH2');\n }\n}\n"],"file":"postOAuth2Token.mjs"}
1
+ {"version":3,"file":"postOAuth2Token.mjs","names":["autoHandler","camelCaseObjectProperties","noop","YError","refersTo","authorizationCodeTokenRequestBodySchema","name","schema","type","description","required","properties","grant_type","enum","code","client_id","redirect_uri","pattern","format","passwordTokenRequestBodySchema","username","password","scope","clientCredentialsTokenRequestBodySchema","refreshTokenRequestBodySchema","refresh_token","tokenBodySchema","oneOf","definition","method","path","operation","operationId","summary","tags","parameters","requestBody","content","responses","access_token","token_type","expires_in","error","error_description","error_uri","postOAuth2Token","oAuth2Granters","oAuth2AccessToken","oAuth2RefreshToken","time","Date","now","bind","log","body","grantType","grantParameters","authenticationData","granter","find","authenticator","newAuthenticationData","authenticate","token","accessToken","expiresAt","accessTokenExpiresAt","refreshToken","refreshTokenExpiresAt","Promise","all","create","currentTime","status","headers","Math","ceil","expiration_date","toISOString","refresh_token_expires_in","refresh_token_expiration_date","err","stack","cast"],"sources":["../../src/handlers/postOAuth2Token.ts"],"sourcesContent":["import { autoHandler } from 'knifecycle';\nimport { camelCaseObjectProperties } from './getOAuth2Authorize';\nimport { noop } from '@whook/whook';\nimport YError from 'yerror';\nimport { refersTo } from '@whook/whook';\nimport type { OpenAPIV3 } from 'openapi-types';\nimport type { LogService, TimeService } from 'common-services';\nimport type {\n WhookAPISchemaDefinition,\n WhookAPIHandlerDefinition,\n} from '@whook/whook';\nimport type {\n OAuth2GranterService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n} from '../services/oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\n/* Architecture Note #2: OAuth2 acknowledge\nThis endpoint is to be used by the authentication server page\n to acknowlege that the user accepted the client request.\n*/\nexport const authorizationCodeTokenRequestBodySchema: WhookAPISchemaDefinition =\n {\n name: 'AuthorizationCodeRequestBody',\n schema: {\n type: 'object',\n description:\n 'Authorization code grant, see https://tools.ietf.org/html/rfc6749#section-4.1',\n required: ['grant_type'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['authorization_code'],\n },\n code: {\n type: 'string',\n },\n client_id: {\n type: 'string',\n },\n redirect_uri: {\n type: 'string',\n pattern: '^https?://',\n format: 'uri',\n },\n },\n },\n };\n\nexport const passwordTokenRequestBodySchema: WhookAPISchemaDefinition = {\n name: 'PasswordRequestBody',\n schema: {\n type: 'object',\n description:\n 'Resource owner password credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.3',\n required: ['grant_type', 'username', 'password'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['password'],\n },\n username: {\n type: 'string',\n },\n password: {\n type: 'string',\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n};\n\nexport const clientCredentialsTokenRequestBodySchema: WhookAPISchemaDefinition =\n {\n name: 'ClientCredentialsRequestBody',\n schema: {\n type: 'object',\n description:\n 'Client credentials grant, see https://tools.ietf.org/html/rfc6749#section-4.4',\n required: ['grant_type'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['client_credentials'],\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n };\n\nexport const refreshTokenRequestBodySchema: WhookAPISchemaDefinition = {\n name: 'RefreshTokenRequestBody',\n schema: {\n type: 'object',\n description:\n 'Token refresh grant type, see https://tools.ietf.org/html/rfc6749#section-6 .',\n required: ['grant_type', 'refresh_token'],\n properties: {\n grant_type: {\n type: 'string',\n enum: ['refresh_token'],\n },\n refresh_token: {\n type: 'string',\n },\n scope: {\n type: 'string',\n description: 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n },\n },\n};\n\nexport const tokenBodySchema: WhookAPISchemaDefinition = {\n name: 'TokenRequestBody',\n schema: {\n oneOf: [\n refersTo(passwordTokenRequestBodySchema),\n refersTo(authorizationCodeTokenRequestBodySchema),\n refersTo(clientCredentialsTokenRequestBodySchema),\n refersTo(refreshTokenRequestBodySchema),\n ],\n } as OpenAPIV3.SchemaObject,\n};\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: '/oauth2/token',\n operation: {\n operationId: 'postOAuth2Token',\n summary: `Implements the [Token Endpoint](https://tools.ietf.org/html/rfc6749#section-3.2)\n as defined per the OAuth2 RFC.`,\n tags: ['oauth2'],\n parameters: [],\n requestBody: {\n required: true,\n content: {\n 'application/x-www-form-urlencoded': {\n schema: refersTo(tokenBodySchema),\n },\n 'application/json': {\n schema: refersTo(tokenBodySchema),\n },\n },\n },\n responses: {\n '200': {\n description:\n 'Token successfully issued, see https://tools.ietf.org/html/rfc6749#section-5 .',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['access_token', 'token_type'],\n properties: {\n access_token: { type: 'string' },\n token_type: {\n description:\n 'See https://tools.ietf.org/html/rfc6749#section-7.1',\n type: 'string',\n enum: ['bearer', 'mac'],\n },\n expires_in: {\n description: 'The lifetime in seconds of the access token',\n type: 'number',\n },\n refresh_token: {\n description:\n 'See https://tools.ietf.org/html/rfc6749#section-6',\n type: 'string',\n },\n },\n },\n },\n },\n },\n '400': {\n description:\n 'Access token error response, see https://tools.ietf.org/html/rfc6749#section-5.2',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['error'],\n properties: {\n error: {\n type: 'string',\n enum: [\n 'invalid_request',\n 'invalid_client',\n 'invalid_grant',\n 'unauthorized_client',\n 'unsupported_grant_type',\n 'invalid_scope',\n ],\n },\n error_description: { type: 'string' },\n error_uri: { type: 'string' },\n },\n },\n },\n },\n },\n },\n },\n};\n\nexport default autoHandler(postOAuth2Token);\n\nasync function postOAuth2Token<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time = Date.now.bind(Date),\n log = noop,\n }: {\n oAuth2Granters: OAuth2GranterService[];\n oAuth2AccessToken: OAuth2AccessTokenService;\n oAuth2RefreshToken: OAuth2RefreshTokenService;\n log: LogService;\n time: TimeService;\n },\n {\n body: { grant_type: grantType, ...grantParameters },\n authenticationData,\n }: {\n body: {\n grant_type: string;\n [name: string]: unknown;\n };\n authenticationData: AUTHENTICATION_DATA;\n },\n) {\n try {\n const granter = oAuth2Granters.find(\n (granter) =>\n granter.authenticator && granter.authenticator.grantType === grantType,\n );\n\n if (!granter || !granter.authenticator) {\n throw new YError('E_UNKNOWN_AUTHENTICATOR_TYPE', grantType);\n }\n\n const newAuthenticationData = await granter.authenticator.authenticate(\n camelCaseObjectProperties(grantParameters),\n authenticationData,\n );\n\n const [\n { token: accessToken, expiresAt: accessTokenExpiresAt },\n { token: refreshToken, expiresAt: refreshTokenExpiresAt },\n ] = await Promise.all([\n oAuth2AccessToken.create(authenticationData, newAuthenticationData),\n oAuth2RefreshToken.create(authenticationData, newAuthenticationData),\n ]);\n const currentTime = time();\n\n return {\n status: 200,\n headers: {},\n body: {\n access_token: accessToken,\n token_type: 'bearer',\n expires_in: Math.ceil((accessTokenExpiresAt - currentTime) / 1000),\n expiration_date: new Date(accessTokenExpiresAt).toISOString(),\n refresh_token: refreshToken,\n refresh_token_expires_in: Math.ceil(\n (refreshTokenExpiresAt - currentTime) / 1000,\n ),\n refresh_token_expiration_date: new Date(\n refreshTokenExpiresAt,\n ).toISOString(),\n },\n };\n } catch (err) {\n log('debug', '👫 - OAuth2 token issuing error', (err as YError).code);\n log('debug-stack', (err as Error).stack || 'no_stack_trace');\n\n throw YError.cast(err as Error, 'E_OAUTH2');\n }\n}\n"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,SAASC,yBAAT,QAA0C,sBAA1C;AACA,SAASC,IAAT,QAAqB,cAArB;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,SAASC,QAAT,QAAyB,cAAzB;;AAcA;AACA;AACA;AACA;AACA,OAAO,MAAMC,uCAAiE,GAC5E;EACEC,IAAI,EAAE,8BADR;EAEEC,MAAM,EAAE;IACNC,IAAI,EAAE,QADA;IAENC,WAAW,EACT,+EAHI;IAINC,QAAQ,EAAE,CAAC,YAAD,CAJJ;IAKNC,UAAU,EAAE;MACVC,UAAU,EAAE;QACVJ,IAAI,EAAE,QADI;QAEVK,IAAI,EAAE,CAAC,oBAAD;MAFI,CADF;MAKVC,IAAI,EAAE;QACJN,IAAI,EAAE;MADF,CALI;MAQVO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E,IAA7D,CAAH;IACAuC,GAAG,CAAC,aAAD,EAAiB4B,GAAD,CAAeC,KAAf,IAAwB,gBAAxC,CAAH;IAEA,MAAM/E,MAAM,CAACgF,IAAP,CAAYF,GAAZ,EAA0B,UAA1B,CAAN;EACD;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/handlers/postOAuth2Token.test.ts"],"names":["describe","log","jest","fn","time","oAuth2AccessToken","create","check","oAuth2RefreshToken","codeGranter","type","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate","passwordGranter","clientCredentialsGranter","tokenGranter","refreshTokenGranter","oAuth2Granters","beforeEach","mockReset","test","mockReturnValue","Date","getTime","mockResolvedValueOnce","token","expiresAt","parse","applicationId","postOAuth2Token","response","authenticationData","scope","body","grant_type","code","client_id","redirect_uri","expect","oAuth2AccessTokenCreateCalls","mock","calls","oAuth2RefreshTokenCreateCalls","logCalls","filter","endsWith","toMatchSnapshot","YError","err","errorCode","errorParams","params","toMatchInlineSnapshot"],"mappings":";;AAAA;;AACA;;;;AAGAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;AAChC,QAAMC,GAAG,GAAGC,IAAI,CAACC,EAAL,EAAZ;AACA,QAAMC,IAAI,GAAGF,IAAI,CAACC,EAAL,EAAb;AACA,QAAME,iBAAiB,GAAG;AAAEC,IAAAA,MAAM,EAAEJ,IAAI,CAACC,EAAL,EAAV;AAAqBI,IAAAA,KAAK,EAAEL,IAAI,CAACC,EAAL;AAA5B,GAA1B;AACA,QAAMK,kBAAkB,GAAG;AAAEF,IAAAA,MAAM,EAAEJ,IAAI,CAACC,EAAL,EAAV;AAAqBI,IAAAA,KAAK,EAAEL,IAAI,CAACC,EAAL;AAA5B,GAA3B;AACA,QAAMM,WAAW,GAAG;AAClBC,IAAAA,IAAI,EAAE,MADY;AAElBC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,YAAY,EAAE,MAAhB;AAAwBC,MAAAA,SAAS,EAAEX,I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GAAG,MAAM,8BAAoB;AAChDZ,MAAAA,cADgD;AAEhDnB,MAAAA,iBAFgD;AAGhDG,MAAAA,kBAHgD;AAIhDJ,MAAAA,IAJgD;AAKhDH,MAAAA;AALgD,KAApB,CAA9B;;AAQA,QAAI;AACF,YAAMmC,eAAe,CAAC;AACpBE,QAAAA,kBAAkB,EAAE;AAClBH,UAAAA,aAAa,EAAE,sCADG;AAElBI,UAAAA,KAAK,EAAE;AAFW,SADA;AAKpBC,QAAAA,IAAI,EAAE;AACJC,UAAAA,UAAU,EAAE,MADR;AAEJC,UAAAA,IAAI,EAAE,KAFF;AAGJC,UAAAA,SAAS,EAAE,sCAHP;AAIJC,UAAAA,YAAY,EAAE;AAJV;AALc,OAAD,CAArB;AAYA,YAAM,IAAIU,eAAJ,CAAW,sBAAX,CAAN;AACD,KAdD,CAcE,OAAOC,GAAP,EAAY;AACZV,MAAAA,MAAM,CAAC;AACLW,QAAAA,SAAS,EAAED,GAAG,CAACb,IADV;AAELe,QAAAA,WAAW,EAAEF,GAAG,CAACG;AAFZ,OAAD,CAAN,CAGGC,qBAHH,CAG0B;AAChC;AACA;AACA;AACA;AACA;AACA;AACA,OAVM;AAWAd,MAAAA,MAAM,CAAC;AACLC,QAAAA,4BAA4B,EAAEzC,iBAAiB,CAACC,MAAlB,CAAyByC,IAAzB,CAA8BC,KADvD;AAELC,QAAAA,6BAA6B,EAAEzC,kBAAkB,CAACF,MAAnB,CAA0ByC,IAA1B,CAA+BC,KAFzD;AAGLE,QAAAA,QAAQ,EAAEjD,GAAG,CAAC8C,IAAJ,CAASC,KAAT,CAAeG,MAAf,CAAsB,CAAC,CAACzC,IAAD,CAAD,KAAY,CAACA,IAAI,CAAC0C,QAAL,CAAc,OAAd,CAAnC;AAHL,OAAD,CAAN,CAIGC,eAJH;AAKD;AACF,GAzCG,CAAJ;AA0CD,CApJO,CAAR","sourcesContent":["import initPostOAuth2Token from './postOAuth2Token';\nimport YError from 'yerror';\nimport type { OAuth2GranterService } from '..';\n\ndescribe('postOAuth2Token', () => {\n const log = jest.fn();\n const time = jest.fn();\n const oAuth2AccessToken = { create: jest.fn(), check: jest.fn() };\n const oAuth2RefreshToken = { create: jest.fn(), check: jest.fn() };\n const codeGranter = {\n type: 'code',\n authorizer: { responseType: 'code', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'code', acknowledge: jest.fn() },\n authenticator: {\n grantType: 'authorization_code',\n authenticate: jest.fn(),\n },\n };\n const passwordGranter = {\n type: 'password',\n authenticator: {\n grantType: 'password',\n authenticate: jest.fn(),\n },\n };\n const clientCredentialsGranter = {\n type: 'client_credentials',\n authenticator: {\n grantType: 'client_credentials',\n authenticate: jest.fn(),\n },\n };\n const tokenGranter = {\n type: 'token',\n authorizer: { responseType: 'token', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'token', acknowledge: jest.fn() },\n };\n const refreshTokenGranter = {\n type: 'refresh',\n authenticator: {\n grantType: 'refresh',\n authenticate: jest.fn(),\n },\n };\n const oAuth2Granters: OAuth2GranterService[] = [\n codeGranter,\n tokenGranter,\n passwordGranter,\n refreshTokenGranter,\n clientCredentialsGranter,\n ];\n\n beforeEach(() => {\n log.mockReset();\n time.mockReset();\n oAuth2AccessToken.create.mockReset();\n oAuth2AccessToken.check.mockReset();\n oAuth2RefreshToken.create.mockReset();\n oAuth2RefreshToken.check.mockReset();\n codeGranter.authorizer.authorize.mockReset();\n codeGranter.acknowledger.acknowledge.mockReset();\n codeGranter.authenticator.authenticate.mockReset();\n tokenGranter.authorizer.authorize.mockReset();\n tokenGranter.acknowledger.acknowledge.mockReset();\n passwordGranter.authenticator.authenticate.mockReset();\n refreshTokenGranter.authenticator.authenticate.mockReset();\n clientCredentialsGranter.authenticator.authenticate.mockReset();\n });\n\n test('should create a token', async () => {\n time.mockReturnValue(new Date('2010-03-06T00:00:00Z').getTime());\n oAuth2AccessToken.create.mockResolvedValueOnce({\n token: 'an_access_token',\n expiresAt: Date.parse('2010-03-07T00:00:00Z'),\n });\n oAuth2RefreshToken.create.mockResolvedValueOnce({\n token: 'a_refresh_token',\n expiresAt: Date.parse('2180-03-06T00:00:00Z'),\n });\n codeGranter.authorizer.authorize.mockResolvedValueOnce({\n applicationId: '',\n });\n\n const postOAuth2Token = await initPostOAuth2Token({\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time,\n log,\n });\n const response = await postOAuth2Token({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n body: {\n grant_type: 'authorization_code',\n code: '007',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'http://lol',\n },\n });\n expect({\n response,\n oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,\n oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n }).toMatchSnapshot();\n });\n\n test('should fail with a bad grant type', async () => {\n const postOAuth2Token = await initPostOAuth2Token({\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time,\n log,\n });\n\n try {\n await postOAuth2Token({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n body: {\n grant_type: 'yolo',\n code: '007',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'http://lol',\n },\n });\n throw new YError('E_UNEXPECTED_SUCCESS');\n } catch (err) {\n expect({\n errorCode: err.code,\n errorParams: err.params,\n }).toMatchInlineSnapshot(`\n Object {\n \"errorCode\": \"E_UNKNOWN_AUTHENTICATOR_TYPE\",\n \"errorParams\": Array [\n \"yolo\",\n ],\n }\n `);\n expect({\n oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,\n oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n }).toMatchSnapshot();\n }\n });\n});\n"],"file":"postOAuth2Token.test.js"}
1
+ {"version":3,"file":"postOAuth2Token.test.js","names":["describe","log","jest","fn","time","oAuth2AccessToken","create","check","oAuth2RefreshToken","codeGranter","type","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate","passwordGranter","clientCredentialsGranter","tokenGranter","refreshTokenGranter","oAuth2Granters","beforeEach","mockReset","test","mockReturnValue","Date","getTime","mockResolvedValueOnce","token","expiresAt","parse","applicationId","postOAuth2Token","initPostOAuth2Token","response","authenticationData","scope","body","grant_type","code","client_id","redirect_uri","expect","oAuth2AccessTokenCreateCalls","mock","calls","oAuth2RefreshTokenCreateCalls","logCalls","filter","endsWith","toMatchSnapshot","YError","err","errorCode","errorParams","params","toMatchInlineSnapshot"],"sources":["../../src/handlers/postOAuth2Token.test.ts"],"sourcesContent":["import initPostOAuth2Token from './postOAuth2Token';\nimport YError from 'yerror';\nimport type { OAuth2GranterService } from '..';\n\ndescribe('postOAuth2Token', () => {\n const log = jest.fn();\n const time = jest.fn();\n const oAuth2AccessToken = { create: jest.fn(), check: jest.fn() };\n const oAuth2RefreshToken = { create: jest.fn(), check: jest.fn() };\n const codeGranter = {\n type: 'code',\n authorizer: { responseType: 'code', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'code', acknowledge: jest.fn() },\n authenticator: {\n grantType: 'authorization_code',\n authenticate: jest.fn(),\n },\n };\n const passwordGranter = {\n type: 'password',\n authenticator: {\n grantType: 'password',\n authenticate: jest.fn(),\n },\n };\n const clientCredentialsGranter = {\n type: 'client_credentials',\n authenticator: {\n grantType: 'client_credentials',\n authenticate: jest.fn(),\n },\n };\n const tokenGranter = {\n type: 'token',\n authorizer: { responseType: 'token', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'token', acknowledge: jest.fn() },\n };\n const refreshTokenGranter = {\n type: 'refresh',\n authenticator: {\n grantType: 'refresh',\n authenticate: jest.fn(),\n },\n };\n const oAuth2Granters: OAuth2GranterService[] = [\n codeGranter,\n tokenGranter,\n passwordGranter,\n refreshTokenGranter,\n clientCredentialsGranter,\n ];\n\n beforeEach(() => {\n log.mockReset();\n time.mockReset();\n oAuth2AccessToken.create.mockReset();\n oAuth2AccessToken.check.mockReset();\n oAuth2RefreshToken.create.mockReset();\n oAuth2RefreshToken.check.mockReset();\n codeGranter.authorizer.authorize.mockReset();\n codeGranter.acknowledger.acknowledge.mockReset();\n codeGranter.authenticator.authenticate.mockReset();\n tokenGranter.authorizer.authorize.mockReset();\n tokenGranter.acknowledger.acknowledge.mockReset();\n passwordGranter.authenticator.authenticate.mockReset();\n refreshTokenGranter.authenticator.authenticate.mockReset();\n clientCredentialsGranter.authenticator.authenticate.mockReset();\n });\n\n test('should create a token', async () => {\n time.mockReturnValue(new Date('2010-03-06T00:00:00Z').getTime());\n oAuth2AccessToken.create.mockResolvedValueOnce({\n token: 'an_access_token',\n expiresAt: Date.parse('2010-03-07T00:00:00Z'),\n });\n oAuth2RefreshToken.create.mockResolvedValueOnce({\n token: 'a_refresh_token',\n expiresAt: Date.parse('2180-03-06T00:00:00Z'),\n });\n codeGranter.authorizer.authorize.mockResolvedValueOnce({\n applicationId: '',\n });\n\n const postOAuth2Token = await initPostOAuth2Token({\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time,\n log,\n });\n const response = await postOAuth2Token({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n body: {\n grant_type: 'authorization_code',\n code: '007',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'http://lol',\n },\n });\n expect({\n response,\n oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,\n oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n }).toMatchSnapshot();\n });\n\n test('should fail with a bad grant type', async () => {\n const postOAuth2Token = await initPostOAuth2Token({\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time,\n log,\n });\n\n try {\n await postOAuth2Token({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n body: {\n grant_type: 'yolo',\n code: '007',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'http://lol',\n },\n });\n throw new YError('E_UNEXPECTED_SUCCESS');\n } catch (err) {\n expect({\n errorCode: (err as YError).code,\n errorParams: (err as YError).params,\n }).toMatchInlineSnapshot(`\n Object {\n \"errorCode\": \"E_UNKNOWN_AUTHENTICATOR_TYPE\",\n \"errorParams\": Array [\n \"yolo\",\n ],\n }\n `);\n expect({\n oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,\n oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n }).toMatchSnapshot();\n }\n });\n});\n"],"mappings":";;AAAA;;AACA;;;;AAGAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;EAChC,MAAMC,GAAG,GAAGC,IAAI,CAACC,EAAL,EAAZ;EACA,MAAMC,IAAI,GAAGF,IAAI,CAACC,EAAL,EAAb;EACA,MAAME,iBAAiB,GAAG;IAAEC,MAAM,EAAEJ,IAAI,CAACC,EAAL,EAAV;IAAqBI,KAAK,EAAEL,IAAI,CAACC,EAAL;EAA5B,CAA1B;EACA,MAAMK,kBAAkB,GAAG;IAAEF,MAAM,EAAEJ,IAAI,CAACC,EAAL,EAAV;IAAqBI,KAAK,EAAEL,IAAI,CAACC,EAAL;EAA5B,CAA3B;EACA,MAAMM,WAAW,GAAG;IAClBC,IAAI,EAAE,MADY;IAElBC,UAAU,EAAE;MAAEC,YAAY,EAAE,MAAhB;MAAwBC,SAAS,EAAEX,IAAI,CAACC,EAAL;IAAnC,CAFM;IAGlBW,YAAY,EAAE;MAAEC,kBAAkB,EAAE,MAAtB;MAA8B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AN,CAGGC,qBAHH,CAG0B;AAChC;AACA;AACA;AACA;AACA;AACA;AACA,OAVM;MAWAd,MAAM,CAAC;QACLC,4BAA4B,EAAE1C,iBAAiB,CAACC,MAAlB,CAAyB0C,IAAzB,CAA8BC,KADvD;QAELC,6BAA6B,EAAE1C,kBAAkB,CAACF,MAAnB,CAA0B0C,IAA1B,CAA+BC,KAFzD;QAGLE,QAAQ,EAAElD,GAAG,CAAC+C,IAAJ,CAASC,KAAT,CAAeG,MAAf,CAAsB,CAAC,CAAC1C,IAAD,CAAD,KAAY,CAACA,IAAI,CAAC2C,QAAL,CAAc,OAAd,CAAnC;MAHL,CAAD,CAAN,CAIGC,eAJH;IAKD;EACF,CAzCG,CAAJ;AA0CD,CApJO,CAAR"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/handlers/postOAuth2Token.test.ts"],"names":["initPostOAuth2Token","YError","describe","log","jest","fn","time","oAuth2AccessToken","create","check","oAuth2RefreshToken","codeGranter","type","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate","passwordGranter","clientCredentialsGranter","tokenGranter","refreshTokenGranter","oAuth2Granters","beforeEach","mockReset","test","mockReturnValue","Date","getTime","mockResolvedValueOnce","token","expiresAt","parse","applicationId","postOAuth2Token","response","authenticationData","scope","body","grant_type","code","client_id","redirect_uri","expect","oAuth2AccessTokenCreateCalls","mock","calls","oAuth2RefreshTokenCreateCalls","logCalls","filter","endsWith","toMatchSnapshot","err","errorCode","errorParams","params","toMatchInlineSnapshot"],"mappings":"AAAA,OAAOA,mBAAP,MAAgC,mBAAhC;AACA,OAAOC,MAAP,MAAmB,QAAnB;AAGAC,QAAQ,CAAC,iBAAD,EAAoB,MAAM;AAChC,QAAMC,GAAG,GAAGC,IAAI,CAACC,EAAL,EAAZ;AACA,QAAMC,IAAI,GAAGF,IAAI,CAACC,EAAL,EAAb;AACA,QAAME,iBAAiB,GAAG;AAAEC,IAAAA,MAAM,EAAEJ,IAAI,CA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AA,6BAA6B,EAAEzC,kBAAkB,CAACF,MAAnB,CAA0ByC,IAA1B,CAA+BC,KAFzD;AAGLE,QAAAA,QAAQ,EAAEjD,GAAG,CAAC8C,IAAJ,CAASC,KAAT,CAAeG,MAAf,CAAsB,CAAC,CAACzC,IAAD,CAAD,KAAY,CAACA,IAAI,CAAC0C,QAAL,CAAc,OAAd,CAAnC;AAHL,OAAD,CAAN,CAIGC,eAJH;AAKD;AACF,GAzCG,CAAJ;AA0CD,CApJO,CAAR","sourcesContent":["import initPostOAuth2Token from './postOAuth2Token';\nimport YError from 'yerror';\nimport type { OAuth2GranterService } from '..';\n\ndescribe('postOAuth2Token', () => {\n const log = jest.fn();\n const time = jest.fn();\n const oAuth2AccessToken = { create: jest.fn(), check: jest.fn() };\n const oAuth2RefreshToken = { create: jest.fn(), check: jest.fn() };\n const codeGranter = {\n type: 'code',\n authorizer: { responseType: 'code', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'code', acknowledge: jest.fn() },\n authenticator: {\n grantType: 'authorization_code',\n authenticate: jest.fn(),\n },\n };\n const passwordGranter = {\n type: 'password',\n authenticator: {\n grantType: 'password',\n authenticate: jest.fn(),\n },\n };\n const clientCredentialsGranter = {\n type: 'client_credentials',\n authenticator: {\n grantType: 'client_credentials',\n authenticate: jest.fn(),\n },\n };\n const tokenGranter = {\n type: 'token',\n authorizer: { responseType: 'token', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'token', acknowledge: jest.fn() },\n };\n const refreshTokenGranter = {\n type: 'refresh',\n authenticator: {\n grantType: 'refresh',\n authenticate: jest.fn(),\n },\n };\n const oAuth2Granters: OAuth2GranterService[] = [\n codeGranter,\n tokenGranter,\n passwordGranter,\n refreshTokenGranter,\n clientCredentialsGranter,\n ];\n\n beforeEach(() => {\n log.mockReset();\n time.mockReset();\n oAuth2AccessToken.create.mockReset();\n oAuth2AccessToken.check.mockReset();\n oAuth2RefreshToken.create.mockReset();\n oAuth2RefreshToken.check.mockReset();\n codeGranter.authorizer.authorize.mockReset();\n codeGranter.acknowledger.acknowledge.mockReset();\n codeGranter.authenticator.authenticate.mockReset();\n tokenGranter.authorizer.authorize.mockReset();\n tokenGranter.acknowledger.acknowledge.mockReset();\n passwordGranter.authenticator.authenticate.mockReset();\n refreshTokenGranter.authenticator.authenticate.mockReset();\n clientCredentialsGranter.authenticator.authenticate.mockReset();\n });\n\n test('should create a token', async () => {\n time.mockReturnValue(new Date('2010-03-06T00:00:00Z').getTime());\n oAuth2AccessToken.create.mockResolvedValueOnce({\n token: 'an_access_token',\n expiresAt: Date.parse('2010-03-07T00:00:00Z'),\n });\n oAuth2RefreshToken.create.mockResolvedValueOnce({\n token: 'a_refresh_token',\n expiresAt: Date.parse('2180-03-06T00:00:00Z'),\n });\n codeGranter.authorizer.authorize.mockResolvedValueOnce({\n applicationId: '',\n });\n\n const postOAuth2Token = await initPostOAuth2Token({\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time,\n log,\n });\n const response = await postOAuth2Token({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n body: {\n grant_type: 'authorization_code',\n code: '007',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'http://lol',\n },\n });\n expect({\n response,\n oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,\n oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n }).toMatchSnapshot();\n });\n\n test('should fail with a bad grant type', async () => {\n const postOAuth2Token = await initPostOAuth2Token({\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time,\n log,\n });\n\n try {\n await postOAuth2Token({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n body: {\n grant_type: 'yolo',\n code: '007',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'http://lol',\n },\n });\n throw new YError('E_UNEXPECTED_SUCCESS');\n } catch (err) {\n expect({\n errorCode: err.code,\n errorParams: err.params,\n }).toMatchInlineSnapshot(`\n Object {\n \"errorCode\": \"E_UNKNOWN_AUTHENTICATOR_TYPE\",\n \"errorParams\": Array [\n \"yolo\",\n ],\n }\n `);\n expect({\n oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,\n oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n }).toMatchSnapshot();\n }\n });\n});\n"],"file":"postOAuth2Token.test.mjs"}
1
+ {"version":3,"file":"postOAuth2Token.test.mjs","names":["initPostOAuth2Token","YError","describe","log","jest","fn","time","oAuth2AccessToken","create","check","oAuth2RefreshToken","codeGranter","type","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate","passwordGranter","clientCredentialsGranter","tokenGranter","refreshTokenGranter","oAuth2Granters","beforeEach","mockReset","test","mockReturnValue","Date","getTime","mockResolvedValueOnce","token","expiresAt","parse","applicationId","postOAuth2Token","response","authenticationData","scope","body","grant_type","code","client_id","redirect_uri","expect","oAuth2AccessTokenCreateCalls","mock","calls","oAuth2RefreshTokenCreateCalls","logCalls","filter","endsWith","toMatchSnapshot","err","errorCode","errorParams","params","toMatchInlineSnapshot"],"sources":["../../src/handlers/postOAuth2Token.test.ts"],"sourcesContent":["import initPostOAuth2Token from './postOAuth2Token';\nimport YError from 'yerror';\nimport type { OAuth2GranterService } from '..';\n\ndescribe('postOAuth2Token', () => {\n const log = jest.fn();\n const time = jest.fn();\n const oAuth2AccessToken = { create: jest.fn(), check: jest.fn() };\n const oAuth2RefreshToken = { create: jest.fn(), check: jest.fn() };\n const codeGranter = {\n type: 'code',\n authorizer: { responseType: 'code', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'code', acknowledge: jest.fn() },\n authenticator: {\n grantType: 'authorization_code',\n authenticate: jest.fn(),\n },\n };\n const passwordGranter = {\n type: 'password',\n authenticator: {\n grantType: 'password',\n authenticate: jest.fn(),\n },\n };\n const clientCredentialsGranter = {\n type: 'client_credentials',\n authenticator: {\n grantType: 'client_credentials',\n authenticate: jest.fn(),\n },\n };\n const tokenGranter = {\n type: 'token',\n authorizer: { responseType: 'token', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'token', acknowledge: jest.fn() },\n };\n const refreshTokenGranter = {\n type: 'refresh',\n authenticator: {\n grantType: 'refresh',\n authenticate: jest.fn(),\n },\n };\n const oAuth2Granters: OAuth2GranterService[] = [\n codeGranter,\n tokenGranter,\n passwordGranter,\n refreshTokenGranter,\n clientCredentialsGranter,\n ];\n\n beforeEach(() => {\n log.mockReset();\n time.mockReset();\n oAuth2AccessToken.create.mockReset();\n oAuth2AccessToken.check.mockReset();\n oAuth2RefreshToken.create.mockReset();\n oAuth2RefreshToken.check.mockReset();\n codeGranter.authorizer.authorize.mockReset();\n codeGranter.acknowledger.acknowledge.mockReset();\n codeGranter.authenticator.authenticate.mockReset();\n tokenGranter.authorizer.authorize.mockReset();\n tokenGranter.acknowledger.acknowledge.mockReset();\n passwordGranter.authenticator.authenticate.mockReset();\n refreshTokenGranter.authenticator.authenticate.mockReset();\n clientCredentialsGranter.authenticator.authenticate.mockReset();\n });\n\n test('should create a token', async () => {\n time.mockReturnValue(new Date('2010-03-06T00:00:00Z').getTime());\n oAuth2AccessToken.create.mockResolvedValueOnce({\n token: 'an_access_token',\n expiresAt: Date.parse('2010-03-07T00:00:00Z'),\n });\n oAuth2RefreshToken.create.mockResolvedValueOnce({\n token: 'a_refresh_token',\n expiresAt: Date.parse('2180-03-06T00:00:00Z'),\n });\n codeGranter.authorizer.authorize.mockResolvedValueOnce({\n applicationId: '',\n });\n\n const postOAuth2Token = await initPostOAuth2Token({\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time,\n log,\n });\n const response = await postOAuth2Token({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n body: {\n grant_type: 'authorization_code',\n code: '007',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'http://lol',\n },\n });\n expect({\n response,\n oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,\n oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n }).toMatchSnapshot();\n });\n\n test('should fail with a bad grant type', async () => {\n const postOAuth2Token = await initPostOAuth2Token({\n oAuth2Granters,\n oAuth2AccessToken,\n oAuth2RefreshToken,\n time,\n log,\n });\n\n try {\n await postOAuth2Token({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'user',\n },\n body: {\n grant_type: 'yolo',\n code: '007',\n client_id: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirect_uri: 'http://lol',\n },\n });\n throw new YError('E_UNEXPECTED_SUCCESS');\n } catch (err) {\n expect({\n errorCode: (err as YError).code,\n errorParams: (err as YError).params,\n }).toMatchInlineSnapshot(`\n Object {\n \"errorCode\": \"E_UNKNOWN_AUTHENTICATOR_TYPE\",\n \"errorParams\": Array [\n \"yolo\",\n ],\n }\n `);\n expect({\n oAuth2AccessTokenCreateCalls: oAuth2AccessToken.create.mock.calls,\n oAuth2RefreshTokenCreateCalls: oAuth2RefreshToken.create.mock.calls,\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n }).toMatchSnapshot();\n }\n });\n});\n"],"mappings":"AAAA,OAAOA,mBAAP,MAAgC,mBAAhC;AACA,OAAOC,MAAP,MAAmB,QAAnB;AAGAC,QAAQ,CAAC,iBAAD,EAAoB,MAAM;EAChC,MAAMC,GAAG,GAAGC,IAAI,CAACC,EAAL,EAAZ;EACA,MAAMC,IAAI,GAAGF,IAAI,CAACC,EAAL,EAAb;EACA,MAAME,iB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;MACF,MAAMmC,eAAe,CAAC;QACpBE,kBAAkB,EAAE;UAClBH,aAAa,EAAE,sCADG;UAElBI,KAAK,EAAE;QAFW,CADA;QAKpBC,IAAI,EAAE;UACJC,UAAU,EAAE,MADR;UAEJC,IAAI,EAAE,KAFF;UAGJC,SAAS,EAAE,sCAHP;UAIJC,YAAY,EAAE;QAJV;MALc,CAAD,CAArB;MAYA,MAAM,IAAI7C,MAAJ,CAAW,sBAAX,CAAN;IACD,CAdD,CAcE,OAAOuD,GAAP,EAAY;MACZT,MAAM,CAAC;QACLU,SAAS,EAAGD,GAAD,CAAgBZ,IADtB;QAELc,WAAW,EAAGF,GAAD,CAAgBG;MAFxB,CAAD,CAAN,CAGGC,qBAHH,CAG0B;AAChC;AACA;AACA;AACA;AACA;AACA;AACA,OAVM;MAWAb,MAAM,CAAC;QACLC,4BAA4B,EAAEzC,iBAAiB,CAACC,MAAlB,CAAyByC,IAAzB,CAA8BC,KADvD;QAELC,6BAA6B,EAAEzC,kBAAkB,CAACF,MAAnB,CAA0ByC,IAA1B,CAA+BC,KAFzD;QAGLE,QAAQ,EAAEjD,GAAG,CAAC8C,IAAJ,CAASC,KAAT,CAAeG,MAAf,CAAsB,CAAC,CAACzC,IAAD,CAAD,KAAY,CAACA,IAAI,CAAC0C,QAAL,CAAc,OAAd,CAAnC;MAHL,CAAD,CAAN,CAIGC,eAJH;IAKD;EACF,CAzCG,CAAJ;AA0CD,CApJO,CAAR"}
package/dist/index.d.ts CHANGED
@@ -12,6 +12,6 @@ import initPostAuthLogin, { definition as postAuthLoginDefinition } from './hand
12
12
  import initPostAuthLogout, { definition as postAuthLogoutDefinition } from './handlers/postAuthLogout';
13
13
  import initPostAuthRefresh, { authCookieHeaderParameter, definition as postAuthRefreshDefinition } from './handlers/postAuthRefresh';
14
14
  import initAuthCookiesService, { AUTH_API_PREFIX } from './services/authCookies';
15
- import type { AuthHandlersConfig, AuthCookiesService, AuthCookiesConfig, AuthCookiesData } from './services/authCookies';
16
- export type { OAuth2CodeService, OAuth2PasswordService, OAuth2AccessTokenService, OAuth2RefreshTokenService, CheckApplicationService, OAuth2GranterService, OAuth2Options, OAuth2Config, AuthHandlersConfig, AuthCookiesService, AuthCookiesConfig, AuthCookiesData, };
15
+ import type { AuthCookiesEnv, AuthCookiesConfig, AuthCookiesService, AuthCookiesData, AuthHandlersConfig } from './services/authCookies';
16
+ export type { OAuth2CodeService, OAuth2PasswordService, OAuth2AccessTokenService, OAuth2RefreshTokenService, CheckApplicationService, OAuth2GranterService, OAuth2Options, OAuth2Config, AuthCookiesEnv, AuthCookiesConfig, AuthCookiesService, AuthCookiesData, AuthHandlersConfig, };
17
17
  export { initGetOAuth2Authorize, getOAuth2AuthorizeDefinition, getOAuth2AuthorizeResponseTypeParameter, getOAuth2AuthorizeClientIdParameter, getOAuth2AuthorizeRedirectURIParameter, getOAuth2AuthorizeScopeParameter, getOAuth2AuthorizeStateParameter, initPostOAuth2Acknowledge, postOAuth2AcknowledgeDefinition, initPostOAuth2Token, postOAuth2TokenDefinition, postOAuth2TokenAuthorizationCodeTokenRequestBodySchema, postOAuth2TokenPasswordTokenRequestBodySchema, postOAuth2TokenClientCredentialsTokenRequestBodySchema, postOAuth2TokenRefreshTokenRequestBodySchema, postOAuth2TokenTokenBodySchema, OAUTH2_ERRORS_DESCRIPTORS, initOAuth2Granters, initOAuth2ClientCredentialsGranter, initOAuth2CodeGranter, initOAuth2PasswordGranter, initOAuth2RefreshTokenGranter, initOAuth2TokenGranter, AUTH_API_PREFIX, authCookieHeaderParameter, initPostAuthLogin, postAuthLoginDefinition, initPostAuthLogout, postAuthLogoutDefinition, initPostAuthRefresh, postAuthRefreshDefinition, initAuthCookiesService, };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAQA;;AAGA;;AAQA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAWA;;AAGA;;AAGA;;AAIA","sourcesContent":["import initGetOAuth2Authorize, {\n definition as getOAuth2AuthorizeDefinition,\n responseTypeParameter as getOAuth2AuthorizeResponseTypeParameter,\n clientIdParameter as getOAuth2AuthorizeClientIdParameter,\n redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter,\n scopeParameter as getOAuth2AuthorizeScopeParameter,\n stateParameter as getOAuth2AuthorizeStateParameter,\n} from './handlers/getOAuth2Authorize';\nimport initPostOAuth2Acknowledge, {\n definition as postOAuth2AcknowledgeDefinition,\n} from './handlers/postOAuth2Acknowledge';\nimport initPostOAuth2Token, {\n definition as postOAuth2TokenDefinition,\n authorizationCodeTokenRequestBodySchema as postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,\n passwordTokenRequestBodySchema as postOAuth2TokenPasswordTokenRequestBodySchema,\n clientCredentialsTokenRequestBodySchema as postOAuth2TokenClientCredentialsTokenRequestBodySchema,\n refreshTokenRequestBodySchema as postOAuth2TokenRefreshTokenRequestBodySchema,\n tokenBodySchema as postOAuth2TokenTokenBodySchema,\n} from './handlers/postOAuth2Token';\nimport initOAuth2Granters, {\n OAUTH2_ERRORS_DESCRIPTORS,\n} from './services/oAuth2Granters';\nimport initOAuth2ClientCredentialsGranter from './services/oAuth2ClientCredentialsGranter';\nimport initOAuth2CodeGranter from './services/oAuth2CodeGranter';\nimport initOAuth2PasswordGranter from './services/oAuth2PasswordGranter';\nimport initOAuth2RefreshTokenGranter from './services/oAuth2RefreshTokenGranter';\nimport initOAuth2TokenGranter from './services/oAuth2TokenGranter';\nimport type {\n OAuth2CodeService,\n OAuth2PasswordService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n CheckApplicationService,\n OAuth2GranterService,\n OAuth2Options,\n OAuth2Config,\n} from './services/oAuth2Granters';\nimport initPostAuthLogin, {\n definition as postAuthLoginDefinition,\n} from './handlers/postAuthLogin';\nimport initPostAuthLogout, {\n definition as postAuthLogoutDefinition,\n} from './handlers/postAuthLogout';\nimport initPostAuthRefresh, {\n authCookieHeaderParameter,\n definition as postAuthRefreshDefinition,\n} from './handlers/postAuthRefresh';\nimport initAuthCookiesService, {\n AUTH_API_PREFIX,\n} from './services/authCookies';\nimport type {\n AuthHandlersConfig,\n AuthCookiesService,\n AuthCookiesConfig,\n AuthCookiesData,\n} from './services/authCookies';\n\nexport type {\n OAuth2CodeService,\n OAuth2PasswordService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n CheckApplicationService,\n OAuth2GranterService,\n OAuth2Options,\n OAuth2Config,\n AuthHandlersConfig,\n AuthCookiesService,\n AuthCookiesConfig,\n AuthCookiesData,\n};\nexport {\n initGetOAuth2Authorize,\n getOAuth2AuthorizeDefinition,\n getOAuth2AuthorizeResponseTypeParameter,\n getOAuth2AuthorizeClientIdParameter,\n getOAuth2AuthorizeRedirectURIParameter,\n getOAuth2AuthorizeScopeParameter,\n getOAuth2AuthorizeStateParameter,\n initPostOAuth2Acknowledge,\n postOAuth2AcknowledgeDefinition,\n initPostOAuth2Token,\n postOAuth2TokenDefinition,\n postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,\n postOAuth2TokenPasswordTokenRequestBodySchema,\n postOAuth2TokenClientCredentialsTokenRequestBodySchema,\n postOAuth2TokenRefreshTokenRequestBodySchema,\n postOAuth2TokenTokenBodySchema,\n OAUTH2_ERRORS_DESCRIPTORS,\n initOAuth2Granters,\n initOAuth2ClientCredentialsGranter,\n initOAuth2CodeGranter,\n initOAuth2PasswordGranter,\n initOAuth2RefreshTokenGranter,\n initOAuth2TokenGranter,\n AUTH_API_PREFIX,\n authCookieHeaderParameter,\n initPostAuthLogin,\n postAuthLoginDefinition,\n initPostAuthLogout,\n postAuthLogoutDefinition,\n initPostAuthRefresh,\n postAuthRefreshDefinition,\n initAuthCookiesService,\n};\n"],"file":"index.js"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import initGetOAuth2Authorize, {\n definition as getOAuth2AuthorizeDefinition,\n responseTypeParameter as getOAuth2AuthorizeResponseTypeParameter,\n clientIdParameter as getOAuth2AuthorizeClientIdParameter,\n redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter,\n scopeParameter as getOAuth2AuthorizeScopeParameter,\n stateParameter as getOAuth2AuthorizeStateParameter,\n} from './handlers/getOAuth2Authorize';\nimport initPostOAuth2Acknowledge, {\n definition as postOAuth2AcknowledgeDefinition,\n} from './handlers/postOAuth2Acknowledge';\nimport initPostOAuth2Token, {\n definition as postOAuth2TokenDefinition,\n authorizationCodeTokenRequestBodySchema as postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,\n passwordTokenRequestBodySchema as postOAuth2TokenPasswordTokenRequestBodySchema,\n clientCredentialsTokenRequestBodySchema as postOAuth2TokenClientCredentialsTokenRequestBodySchema,\n refreshTokenRequestBodySchema as postOAuth2TokenRefreshTokenRequestBodySchema,\n tokenBodySchema as postOAuth2TokenTokenBodySchema,\n} from './handlers/postOAuth2Token';\nimport initOAuth2Granters, {\n OAUTH2_ERRORS_DESCRIPTORS,\n} from './services/oAuth2Granters';\nimport initOAuth2ClientCredentialsGranter from './services/oAuth2ClientCredentialsGranter';\nimport initOAuth2CodeGranter from './services/oAuth2CodeGranter';\nimport initOAuth2PasswordGranter from './services/oAuth2PasswordGranter';\nimport initOAuth2RefreshTokenGranter from './services/oAuth2RefreshTokenGranter';\nimport initOAuth2TokenGranter from './services/oAuth2TokenGranter';\nimport type {\n OAuth2CodeService,\n OAuth2PasswordService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n CheckApplicationService,\n OAuth2GranterService,\n OAuth2Options,\n OAuth2Config,\n} from './services/oAuth2Granters';\nimport initPostAuthLogin, {\n definition as postAuthLoginDefinition,\n} from './handlers/postAuthLogin';\nimport initPostAuthLogout, {\n definition as postAuthLogoutDefinition,\n} from './handlers/postAuthLogout';\nimport initPostAuthRefresh, {\n authCookieHeaderParameter,\n definition as postAuthRefreshDefinition,\n} from './handlers/postAuthRefresh';\nimport initAuthCookiesService, {\n AUTH_API_PREFIX,\n} from './services/authCookies';\nimport type {\n AuthCookiesEnv,\n AuthCookiesConfig,\n AuthCookiesService,\n AuthCookiesData,\n AuthHandlersConfig,\n} from './services/authCookies';\n\nexport type {\n OAuth2CodeService,\n OAuth2PasswordService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n CheckApplicationService,\n OAuth2GranterService,\n OAuth2Options,\n OAuth2Config,\n AuthCookiesEnv,\n AuthCookiesConfig,\n AuthCookiesService,\n AuthCookiesData,\n AuthHandlersConfig,\n};\nexport {\n initGetOAuth2Authorize,\n getOAuth2AuthorizeDefinition,\n getOAuth2AuthorizeResponseTypeParameter,\n getOAuth2AuthorizeClientIdParameter,\n getOAuth2AuthorizeRedirectURIParameter,\n getOAuth2AuthorizeScopeParameter,\n getOAuth2AuthorizeStateParameter,\n initPostOAuth2Acknowledge,\n postOAuth2AcknowledgeDefinition,\n initPostOAuth2Token,\n postOAuth2TokenDefinition,\n postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,\n postOAuth2TokenPasswordTokenRequestBodySchema,\n postOAuth2TokenClientCredentialsTokenRequestBodySchema,\n postOAuth2TokenRefreshTokenRequestBodySchema,\n postOAuth2TokenTokenBodySchema,\n OAUTH2_ERRORS_DESCRIPTORS,\n initOAuth2Granters,\n initOAuth2ClientCredentialsGranter,\n initOAuth2CodeGranter,\n initOAuth2PasswordGranter,\n initOAuth2RefreshTokenGranter,\n initOAuth2TokenGranter,\n AUTH_API_PREFIX,\n authCookieHeaderParameter,\n initPostAuthLogin,\n postAuthLoginDefinition,\n initPostAuthLogout,\n postAuthLogoutDefinition,\n initPostAuthRefresh,\n postAuthRefreshDefinition,\n initAuthCookiesService,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAQA;;AAGA;;AAQA;;AAGA;;AACA;;AACA;;AACA;;AACA;;AAWA;;AAGA;;AAGA;;AAIA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["initGetOAuth2Authorize","definition","getOAuth2AuthorizeDefinition","responseTypeParameter","getOAuth2AuthorizeResponseTypeParameter","clientIdParameter","getOAuth2AuthorizeClientIdParameter","redirectURIParameter","getOAuth2AuthorizeRedirectURIParameter","scopeParameter","getOAuth2AuthorizeScopeParameter","stateParameter","getOAuth2AuthorizeStateParameter","initPostOAuth2Acknowledge","postOAuth2AcknowledgeDefinition","initPostOAuth2Token","postOAuth2TokenDefinition","authorizationCodeTokenRequestBodySchema","postOAuth2TokenAuthorizationCodeTokenRequestBodySchema","passwordTokenRequestBodySchema","postOAuth2TokenPasswordTokenRequestBodySchema","clientCredentialsTokenRequestBodySchema","postOAuth2TokenClientCredentialsTokenRequestBodySchema","refreshTokenRequestBodySchema","postOAuth2TokenRefreshTokenRequestBodySchema","tokenBodySchema","postOAuth2TokenTokenBodySchema","initOAuth2Granters","OAUTH2_ERRORS_DESCRIPTORS","initOAuth2ClientCredentialsGranter","initOAuth2CodeGranter","initOAuth2PasswordGranter","initOAuth2RefreshTokenGranter","initOAuth2TokenGranter","initPostAuthLogin","postAuthLoginDefinition","initPostAuthLogout","postAuthLogoutDefinition","initPostAuthRefresh","authCookieHeaderParameter","postAuthRefreshDefinition","initAuthCookiesService","AUTH_API_PREFIX"],"mappings":"AAAA,OAAOA,sBAAP,IACE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EC,yBArBF,EAsBEC,6BAtBF,EAuBEC,sBAvBF,EAwBES,eAxBF,EAyBEH,yBAzBF,EA0BEL,iBA1BF,EA2BEC,uBA3BF,EA4BEC,kBA5BF,EA6BEC,wBA7BF,EA8BEC,mBA9BF,EA+BEE,yBA/BF,EAgCEC,sBAhCF","sourcesContent":["import initGetOAuth2Authorize, {\n definition as getOAuth2AuthorizeDefinition,\n responseTypeParameter as getOAuth2AuthorizeResponseTypeParameter,\n clientIdParameter as getOAuth2AuthorizeClientIdParameter,\n redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter,\n scopeParameter as getOAuth2AuthorizeScopeParameter,\n stateParameter as getOAuth2AuthorizeStateParameter,\n} from './handlers/getOAuth2Authorize';\nimport initPostOAuth2Acknowledge, {\n definition as postOAuth2AcknowledgeDefinition,\n} from './handlers/postOAuth2Acknowledge';\nimport initPostOAuth2Token, {\n definition as postOAuth2TokenDefinition,\n authorizationCodeTokenRequestBodySchema as postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,\n passwordTokenRequestBodySchema as postOAuth2TokenPasswordTokenRequestBodySchema,\n clientCredentialsTokenRequestBodySchema as postOAuth2TokenClientCredentialsTokenRequestBodySchema,\n refreshTokenRequestBodySchema as postOAuth2TokenRefreshTokenRequestBodySchema,\n tokenBodySchema as postOAuth2TokenTokenBodySchema,\n} from './handlers/postOAuth2Token';\nimport initOAuth2Granters, {\n OAUTH2_ERRORS_DESCRIPTORS,\n} from './services/oAuth2Granters';\nimport initOAuth2ClientCredentialsGranter from './services/oAuth2ClientCredentialsGranter';\nimport initOAuth2CodeGranter from './services/oAuth2CodeGranter';\nimport initOAuth2PasswordGranter from './services/oAuth2PasswordGranter';\nimport initOAuth2RefreshTokenGranter from './services/oAuth2RefreshTokenGranter';\nimport initOAuth2TokenGranter from './services/oAuth2TokenGranter';\nimport type {\n OAuth2CodeService,\n OAuth2PasswordService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n CheckApplicationService,\n OAuth2GranterService,\n OAuth2Options,\n OAuth2Config,\n} from './services/oAuth2Granters';\nimport initPostAuthLogin, {\n definition as postAuthLoginDefinition,\n} from './handlers/postAuthLogin';\nimport initPostAuthLogout, {\n definition as postAuthLogoutDefinition,\n} from './handlers/postAuthLogout';\nimport initPostAuthRefresh, {\n authCookieHeaderParameter,\n definition as postAuthRefreshDefinition,\n} from './handlers/postAuthRefresh';\nimport initAuthCookiesService, {\n AUTH_API_PREFIX,\n} from './services/authCookies';\nimport type {\n AuthHandlersConfig,\n AuthCookiesService,\n AuthCookiesConfig,\n AuthCookiesData,\n} from './services/authCookies';\n\nexport type {\n OAuth2CodeService,\n OAuth2PasswordService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n CheckApplicationService,\n OAuth2GranterService,\n OAuth2Options,\n OAuth2Config,\n AuthHandlersConfig,\n AuthCookiesService,\n AuthCookiesConfig,\n AuthCookiesData,\n};\nexport {\n initGetOAuth2Authorize,\n getOAuth2AuthorizeDefinition,\n getOAuth2AuthorizeResponseTypeParameter,\n getOAuth2AuthorizeClientIdParameter,\n getOAuth2AuthorizeRedirectURIParameter,\n getOAuth2AuthorizeScopeParameter,\n getOAuth2AuthorizeStateParameter,\n initPostOAuth2Acknowledge,\n postOAuth2AcknowledgeDefinition,\n initPostOAuth2Token,\n postOAuth2TokenDefinition,\n postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,\n postOAuth2TokenPasswordTokenRequestBodySchema,\n postOAuth2TokenClientCredentialsTokenRequestBodySchema,\n postOAuth2TokenRefreshTokenRequestBodySchema,\n postOAuth2TokenTokenBodySchema,\n OAUTH2_ERRORS_DESCRIPTORS,\n initOAuth2Granters,\n initOAuth2ClientCredentialsGranter,\n initOAuth2CodeGranter,\n initOAuth2PasswordGranter,\n initOAuth2RefreshTokenGranter,\n initOAuth2TokenGranter,\n AUTH_API_PREFIX,\n authCookieHeaderParameter,\n initPostAuthLogin,\n postAuthLoginDefinition,\n initPostAuthLogout,\n postAuthLogoutDefinition,\n initPostAuthRefresh,\n postAuthRefreshDefinition,\n initAuthCookiesService,\n};\n"],"file":"index.mjs"}
1
+ {"version":3,"file":"index.mjs","names":["initGetOAuth2Authorize","definition","getOAuth2AuthorizeDefinition","responseTypeParameter","getOAuth2AuthorizeResponseTypeParameter","clientIdParameter","getOAuth2AuthorizeClientIdParameter","redirectURIParameter","getOAuth2AuthorizeRedirectURIParameter","scopeParameter","getOAuth2AuthorizeScopeParameter","stateParameter","getOAuth2AuthorizeStateParameter","initPostOAuth2Acknowledge","postOAuth2AcknowledgeDefinition","initPostOAuth2Token","postOAuth2TokenDefinition","authorizationCodeTokenRequestBodySchema","postOAuth2TokenAuthorizationCodeTokenRequestBodySchema","passwordTokenRequestBodySchema","postOAuth2TokenPasswordTokenRequestBodySchema","clientCredentialsTokenRequestBodySchema","postOAuth2TokenClientCredentialsTokenRequestBodySchema","refreshTokenRequestBodySchema","postOAuth2TokenRefreshTokenRequestBodySchema","tokenBodySchema","postOAuth2TokenTokenBodySchema","initOAuth2Granters","OAUTH2_ERRORS_DESCRIPTORS","initOAuth2ClientCredentialsGranter","initOAuth2CodeGranter","initOAuth2PasswordGranter","initOAuth2RefreshTokenGranter","initOAuth2TokenGranter","initPostAuthLogin","postAuthLoginDefinition","initPostAuthLogout","postAuthLogoutDefinition","initPostAuthRefresh","authCookieHeaderParameter","postAuthRefreshDefinition","initAuthCookiesService","AUTH_API_PREFIX"],"sources":["../src/index.ts"],"sourcesContent":["import initGetOAuth2Authorize, {\n definition as getOAuth2AuthorizeDefinition,\n responseTypeParameter as getOAuth2AuthorizeResponseTypeParameter,\n clientIdParameter as getOAuth2AuthorizeClientIdParameter,\n redirectURIParameter as getOAuth2AuthorizeRedirectURIParameter,\n scopeParameter as getOAuth2AuthorizeScopeParameter,\n stateParameter as getOAuth2AuthorizeStateParameter,\n} from './handlers/getOAuth2Authorize';\nimport initPostOAuth2Acknowledge, {\n definition as postOAuth2AcknowledgeDefinition,\n} from './handlers/postOAuth2Acknowledge';\nimport initPostOAuth2Token, {\n definition as postOAuth2TokenDefinition,\n authorizationCodeTokenRequestBodySchema as postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,\n passwordTokenRequestBodySchema as postOAuth2TokenPasswordTokenRequestBodySchema,\n clientCredentialsTokenRequestBodySchema as postOAuth2TokenClientCredentialsTokenRequestBodySchema,\n refreshTokenRequestBodySchema as postOAuth2TokenRefreshTokenRequestBodySchema,\n tokenBodySchema as postOAuth2TokenTokenBodySchema,\n} from './handlers/postOAuth2Token';\nimport initOAuth2Granters, {\n OAUTH2_ERRORS_DESCRIPTORS,\n} from './services/oAuth2Granters';\nimport initOAuth2ClientCredentialsGranter from './services/oAuth2ClientCredentialsGranter';\nimport initOAuth2CodeGranter from './services/oAuth2CodeGranter';\nimport initOAuth2PasswordGranter from './services/oAuth2PasswordGranter';\nimport initOAuth2RefreshTokenGranter from './services/oAuth2RefreshTokenGranter';\nimport initOAuth2TokenGranter from './services/oAuth2TokenGranter';\nimport type {\n OAuth2CodeService,\n OAuth2PasswordService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n CheckApplicationService,\n OAuth2GranterService,\n OAuth2Options,\n OAuth2Config,\n} from './services/oAuth2Granters';\nimport initPostAuthLogin, {\n definition as postAuthLoginDefinition,\n} from './handlers/postAuthLogin';\nimport initPostAuthLogout, {\n definition as postAuthLogoutDefinition,\n} from './handlers/postAuthLogout';\nimport initPostAuthRefresh, {\n authCookieHeaderParameter,\n definition as postAuthRefreshDefinition,\n} from './handlers/postAuthRefresh';\nimport initAuthCookiesService, {\n AUTH_API_PREFIX,\n} from './services/authCookies';\nimport type {\n AuthCookiesEnv,\n AuthCookiesConfig,\n AuthCookiesService,\n AuthCookiesData,\n AuthHandlersConfig,\n} from './services/authCookies';\n\nexport type {\n OAuth2CodeService,\n OAuth2PasswordService,\n OAuth2AccessTokenService,\n OAuth2RefreshTokenService,\n CheckApplicationService,\n OAuth2GranterService,\n OAuth2Options,\n OAuth2Config,\n AuthCookiesEnv,\n AuthCookiesConfig,\n AuthCookiesService,\n AuthCookiesData,\n AuthHandlersConfig,\n};\nexport {\n initGetOAuth2Authorize,\n getOAuth2AuthorizeDefinition,\n getOAuth2AuthorizeResponseTypeParameter,\n getOAuth2AuthorizeClientIdParameter,\n getOAuth2AuthorizeRedirectURIParameter,\n getOAuth2AuthorizeScopeParameter,\n getOAuth2AuthorizeStateParameter,\n initPostOAuth2Acknowledge,\n postOAuth2AcknowledgeDefinition,\n initPostOAuth2Token,\n postOAuth2TokenDefinition,\n postOAuth2TokenAuthorizationCodeTokenRequestBodySchema,\n postOAuth2TokenPasswordTokenRequestBodySchema,\n postOAuth2TokenClientCredentialsTokenRequestBodySchema,\n postOAuth2TokenRefreshTokenRequestBodySchema,\n postOAuth2TokenTokenBodySchema,\n OAUTH2_ERRORS_DESCRIPTORS,\n initOAuth2Granters,\n initOAuth2ClientCredentialsGranter,\n initOAuth2CodeGranter,\n initOAuth2PasswordGranter,\n initOAuth2RefreshTokenGranter,\n initOAuth2TokenGranter,\n AUTH_API_PREFIX,\n authCookieHeaderParameter,\n initPostAuthLogin,\n postAuthLoginDefinition,\n initPostAuthLogout,\n postAuthLogoutDefinition,\n initPostAuthRefresh,\n postAuthRefreshDefinition,\n initAuthCookiesService,\n};\n"],"mappings":"AAAA,OAAOA,sBAAP,IACEC,UAAU,IAAIC,4BADhB,EAEEC,qBAAqB,IAAIC,uCAF3B,EAGEC,iBAAiB,IAAIC,mCAHvB,EAIEC,oBAAoB,IAAIC,sCAJ1B,EAKEC,cAAc,IAAIC,gCALpB,EAMEC,cAAc,IAAIC,gCANpB,QAOO,+BAPP;AAQA,OAAOC,yBAAP,IACEZ,UAAU,IAAIa,+BADhB,QAEO,kCAFP;AAGA,OAAOC,mBAAP,IACEd,UAAU,IAAIe,yBADhB,EAEEC,uCAAuC,IAAIC,sDAF7C,EAGEC,8BAA8B,IAAIC,6CAHpC,EAIEC,uCAAuC,IAAIC,sDAJ7C,EAKEC,6BAA6B,IAAIC,4CALnC,EAMEC,eAAe,IAAIC,8BANrB,QAOO,4BAPP;AAQA,OAAOC,kBAAP,IACEC,yBADF,QAEO,2BAFP;AAGA,OAAOC,kCAAP,MAA+C,2CAA/C;AACA,OAAOC,qBAAP,MAAkC,8BAAlC;AACA,OAAOC,yBAAP,MAAsC,kCAAtC;AACA,OAAOC,6BAAP,MAA0C,sCAA1C;AACA,OAAOC,sBAAP,MAAmC,+BAAnC;AAWA,OAAOC,iBAAP,IACEjC,UAAU,IAAIkC,uBADhB,QAEO,0BAFP;AAGA,OAAOC,kBAAP,IACEnC,UAAU,IAAIoC,wBADhB,QAEO,2BAFP;AAGA,OAAOC,mBAAP,IACEC,yBADF,EAEEtC,UAAU,IAAIuC,yBAFhB,QAGO,4BAHP;AAIA,OAAOC,sBAAP,IACEC,eADF,QAEO,wBAFP;AA0BA,SACE1C,sBADF,EAEEE,4BAFF,EAGEE,uCAHF,EAIEE,mCAJF,EAKEE,sCALF,EAMEE,gCANF,EAOEE,gCAPF,EAQEC,yBARF,EASEC,+BATF,EAUEC,mBAVF,EAWEC,yBAXF,EAYEE,sDAZF,EAaEE,6CAbF,EAcEE,sDAdF,EAeEE,4CAfF,EAgBEE,8BAhBF,EAiBEE,yBAjBF,EAkBED,kBAlBF,EAmBEE,kCAnBF,EAoBEC,qBApBF,EAqBEC,yBArBF,EAsBEC,6BAtBF,EAuBEC,sBAvBF,EAwBES,eAxBF,EAyBEH,yBAzBF,EA0BEL,iBA1BF,EA2BEC,uBA3BF,EA4BEC,kBA5BF,EA6BEC,wBA7BF,EA8BEC,mBA9BF,EA+BEE,yBA/BF,EAgCEC,sBAhCF"}
@@ -21,10 +21,10 @@ describe('OAuth2 server', () => {
21
21
  const PORT = 4444;
22
22
  const HOST = 'localhost';
23
23
  const logger = {
24
- info: jest.fn(),
25
- error: jest.fn()
24
+ output: jest.fn(),
25
+ error: jest.fn(),
26
+ debug: jest.fn()
26
27
  };
27
- const debug = jest.fn();
28
28
  const time = jest.fn();
29
29
  const $autoload = jest.fn();
30
30
  const API = {
@@ -124,8 +124,7 @@ describe('OAuth2 server', () => {
124
124
  $.register((0, _knifecycle.constant)('NODE_ENVS', ['test']));
125
125
  $.register((0, _knifecycle.constant)('MECHANISMS', [_httpAuthUtils.BEARER, _httpAuthUtils.BASIC]));
126
126
  $.register((0, _knifecycle.constant)('logger', logger));
127
- $.register((0, _knifecycle.constant)('time', time));
128
- $.register((0, _knifecycle.constant)('debug', debug)); // OAuth2 Specifics
127
+ $.register((0, _knifecycle.constant)('time', time)); // OAuth2 Specifics
129
128
 
130
129
  $.register((0, _knifecycle.constant)('OAUTH2', OAUTH2));
131
130
  $.register((0, _knifecycle.constant)('ERRORS_DESCRIPTORS', { ..._whook.DEFAULT_ERRORS_DESCRIPTORS,
@@ -163,9 +162,9 @@ describe('OAuth2 server', () => {
163
162
  await $instance.destroy();
164
163
  });
165
164
  beforeEach(() => {
166
- logger.info.mockReset();
165
+ logger.output.mockReset();
167
166
  logger.error.mockReset();
168
- debug.mockReset();
167
+ logger.debug.mockReset();
169
168
  time.mockReset();
170
169
  $autoload.mockClear();
171
170
  [oAuth2AccessToken.create, oAuth2AccessToken.check, oAuth2RefreshToken.create, oAuth2RefreshToken.check, oAuth2ClientCredentials.check, oAuth2Code.check, oAuth2Code.create, oAuth2Password.check, checkApplication, authentication.check].forEach(mock => mock.mockReset());