@whook/oauth2 8.5.1 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -7
- package/dist/handlers/getOAuth2Authorize.d.ts +5 -3
- package/dist/handlers/getOAuth2Authorize.js +1 -1
- package/dist/handlers/getOAuth2Authorize.js.map +1 -1
- package/dist/handlers/getOAuth2Authorize.mjs +1 -1
- package/dist/handlers/getOAuth2Authorize.mjs.map +1 -1
- package/dist/handlers/getOAuth2Authorize.test.js.map +1 -1
- package/dist/handlers/getOAuth2Authorize.test.mjs.map +1 -1
- package/dist/handlers/postAuthLogin.d.ts +2 -2
- package/dist/handlers/postAuthLogin.js +1 -0
- package/dist/handlers/postAuthLogin.js.map +1 -1
- package/dist/handlers/postAuthLogin.mjs +1 -0
- package/dist/handlers/postAuthLogin.mjs.map +1 -1
- package/dist/handlers/postAuthLogin.test.js.map +1 -1
- package/dist/handlers/postAuthLogin.test.mjs.map +1 -1
- package/dist/handlers/postAuthLogout.js.map +1 -1
- package/dist/handlers/postAuthLogout.mjs.map +1 -1
- package/dist/handlers/postAuthLogout.test.js.map +1 -1
- package/dist/handlers/postAuthLogout.test.mjs.map +1 -1
- package/dist/handlers/postAuthRefresh.d.ts +3 -3
- package/dist/handlers/postAuthRefresh.js +1 -0
- package/dist/handlers/postAuthRefresh.js.map +1 -1
- package/dist/handlers/postAuthRefresh.mjs +1 -0
- package/dist/handlers/postAuthRefresh.mjs.map +1 -1
- package/dist/handlers/postAuthRefresh.test.js.map +1 -1
- package/dist/handlers/postAuthRefresh.test.mjs.map +1 -1
- package/dist/handlers/postOAuth2Acknowledge.d.ts +10 -7
- package/dist/handlers/postOAuth2Acknowledge.js +2 -2
- package/dist/handlers/postOAuth2Acknowledge.js.map +1 -1
- package/dist/handlers/postOAuth2Acknowledge.mjs +2 -2
- package/dist/handlers/postOAuth2Acknowledge.mjs.map +1 -1
- package/dist/handlers/postOAuth2Acknowledge.test.js.map +1 -1
- package/dist/handlers/postOAuth2Acknowledge.test.mjs.map +1 -1
- package/dist/handlers/postOAuth2Token.d.ts +3 -3
- package/dist/handlers/postOAuth2Token.js +2 -2
- package/dist/handlers/postOAuth2Token.js.map +1 -1
- package/dist/handlers/postOAuth2Token.mjs +2 -2
- package/dist/handlers/postOAuth2Token.mjs.map +1 -1
- package/dist/handlers/postOAuth2Token.test.js.map +1 -1
- package/dist/handlers/postOAuth2Token.test.mjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.test.js +6 -7
- package/dist/index.test.js.map +1 -1
- package/dist/index.test.mjs +6 -7
- package/dist/index.test.mjs.map +1 -1
- package/dist/services/authCookies.js.map +1 -1
- package/dist/services/authCookies.mjs.map +1 -1
- package/dist/services/authCookies.test.js.map +1 -1
- package/dist/services/authCookies.test.mjs.map +1 -1
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -1
- package/dist/services/oAuth2ClientCredentialsGranter.mjs.map +1 -1
- package/dist/services/oAuth2CodeGranter.js.map +1 -1
- package/dist/services/oAuth2CodeGranter.mjs.map +1 -1
- package/dist/services/oAuth2CodeGranter.test.js +8 -6
- package/dist/services/oAuth2CodeGranter.test.js.map +1 -1
- package/dist/services/oAuth2CodeGranter.test.mjs +8 -6
- package/dist/services/oAuth2CodeGranter.test.mjs.map +1 -1
- package/dist/services/oAuth2Granters.d.ts +22 -19
- package/dist/services/oAuth2Granters.js.map +1 -1
- package/dist/services/oAuth2Granters.mjs.map +1 -1
- package/dist/services/oAuth2PasswordGranter.js.map +1 -1
- package/dist/services/oAuth2PasswordGranter.mjs.map +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.js +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.mjs +1 -1
- package/dist/services/oAuth2RefreshTokenGranter.mjs.map +1 -1
- package/dist/services/oAuth2TokenGranter.js.map +1 -1
- package/dist/services/oAuth2TokenGranter.mjs.map +1 -1
- package/package.json +34 -35
- package/src/handlers/getOAuth2Authorize.ts +15 -14
- package/src/handlers/postAuthLogin.ts +4 -3
- package/src/handlers/postAuthRefresh.ts +4 -3
- package/src/handlers/postOAuth2Acknowledge.ts +34 -26
- package/src/handlers/postOAuth2Token.test.ts +2 -2
- package/src/handlers/postOAuth2Token.ts +4 -4
- package/src/index.test.ts +8 -9
- package/src/services/oAuth2ClientCredentialsGranter.ts +25 -21
- package/src/services/oAuth2CodeGranter.test.ts +15 -14
- package/src/services/oAuth2CodeGranter.ts +66 -60
- package/src/services/oAuth2Granters.ts +59 -29
- package/src/services/oAuth2PasswordGranter.ts +23 -22
- package/src/services/oAuth2RefreshTokenGranter.ts +28 -24
- package/src/services/oAuth2TokenGranter.ts +44 -42
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"postAuthRefresh.js","names":["authCookieHeaderParameter","name","example","parameter","in","required","schema","type","definition","method","path","AUTH_API_PREFIX","operation","operationId","summary","tags","disabled","parameters","refersTo","requestBody","content","properties","scope","remember","responses","description","access_token","expiration_date","expires_in","token_type","autoHandler","postAuthRefresh","ROOT_AUTHENTICATION_DATA","authCookies","postOAuth2Token","body","cookie","parsedCookies","parse","refresh_token","YHTTPError","response","grant_type","authenticationData","headers","build","status","undefined","session","err","newErr","wrap"],"sources":["../../src/handlers/postAuthRefresh.ts"],"sourcesContent":["import { autoHandler } from 'knifecycle';\nimport YHTTPError from 'yhttperror';\nimport { refersTo } from '@whook/whook';\nimport initPostOauth2Token from './postOAuth2Token';\nimport { AUTH_API_PREFIX } from '../services/authCookies';\nimport type {\n WhookAPIHandlerDefinition,\n WhookAPIParameterDefinition,\n} from '@whook/whook';\nimport type {\n AuthCookiesService,\n AuthHandlersConfig,\n} from '../services/authCookies';\nimport type { AsyncReturnType } from 'type-fest';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\nexport const authCookieHeaderParameter: WhookAPIParameterDefinition<string> = {\n name: 'cookie',\n example: 'access_token=an_access_token; refresh_token=a_refresh_token;',\n parameter: {\n name: 'cookie',\n in: 'header',\n required: false,\n schema: {\n type: 'string',\n },\n },\n};\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: `${AUTH_API_PREFIX}/refresh`,\n operation: {\n operationId: 'postAuthRefresh',\n summary: 'Refreshs a user auth',\n tags: ['auth'],\n 'x-whook': {\n disabled: true,\n },\n parameters: [refersTo(authCookieHeaderParameter)],\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: [],\n properties: {\n scope: { type: 'string' },\n remember: { type: 'boolean' },\n },\n },\n },\n },\n },\n responses: {\n 200: {\n description: 'Successfuly refreshed.',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n properties: {\n access_token: { type: 'string' },\n expiration_date: { type: 'string' },\n expires_in: { type: 'string' },\n token_type: { type: 'string' },\n },\n },\n },\n },\n },\n },\n },\n};\n\nexport default autoHandler(postAuthRefresh);\n\nasync function postAuthRefresh<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n ROOT_AUTHENTICATION_DATA,\n authCookies,\n postOAuth2Token,\n }: AuthHandlersConfig<AUTHENTICATION_DATA> & {\n authCookies: AuthCookiesService;\n postOAuth2Token: AsyncReturnType<typeof initPostOauth2Token>;\n },\n {\n body,\n cookie = '',\n }: {\n body: {\n scope: string;\n remember: boolean;\n };\n cookie?: string;\n },\n) {\n const parsedCookies = authCookies.parse(cookie);\n\n try {\n if (!parsedCookies.refresh_token) {\n throw new YHTTPError(401, 'E_REFRESH_COOKIE', cookie);\n }\n\n const response = await postOAuth2Token({\n body: {\n grant_type: 'refresh_token',\n scope: body.scope,\n refresh_token: parsedCookies.refresh_token,\n },\n authenticationData: ROOT_AUTHENTICATION_DATA,\n });\n\n return {\n ...response,\n headers: {\n ...(response.headers || {}),\n 'Set-Cookie': authCookies.build(\n response.status === 200 ? response.body : undefined,\n { session: !body.remember },\n ),\n },\n body: {\n access_token: response.body.access_token,\n expiration_date: response.body.expiration_date,\n expires_in: response.body.expires_in,\n token_type: response.body.token_type,\n },\n };\n } catch (err) {\n const newErr = YHTTPError.wrap(err as Error);\n\n newErr.headers = {\n ...((err as YHTTPError).headers || {}),\n // TODO: Allow string[] in YHTTPError\n 'Set-Cookie': authCookies.build() as unknown as string,\n };\n\n throw newErr;\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;AAYO,MAAMA,yBAA8D,GAAG;EAC5EC,IAAI,EAAE,QADsE;EAE5EC,OAAO,EAAE,8DAFmE;EAG5EC,SAAS,EAAE;IACTF,IAAI,EAAE,QADG;IAETG,EAAE,EAAE,QAFK;IAGTC,QAAQ,EAAE,KAHD;IAITC,MAAM,EAAE;MACNC,IAAI,EAAE;IADA;EAJC;AAHiE,CAAvE;;AAaA,MAAMC,UAAqC,GAAG;EACnDC,MAAM,EAAE,MAD2C;EAEnDC,IAAI,EAAG,GAAEC,4BAAgB,UAF0B;EAGnDC,SAAS,EAAE;IACTC,WAAW,EAAE,iBADJ;IAETC,OAAO,EAAE,sBAFA;IAGTC,IAAI,EAAE,CAAC,MAAD,CAHG;IAIT,WAAW;MACTC,QAAQ,EAAE;IADD,CAJF;IAOTC,UAAU,EAAE,CAAC,IAAAC,eAAA,EAASlB,yBAAT,CAAD,CAPH;IAQTmB,WAAW,EAAE;MACXd,QAAQ,EAAE,IADC;MAEXe,OAAO,EAAE;QACP,oBAAoB;UAClBd,MAAM,EAAE;YACNC,IAAI,EAAE,QADA;YAENF,QAAQ,EAAE,EAFJ;YAGNgB,UAAU,EAAE;cACVC,KAAK,EAAE;gBAAEf,IAAI,EAAE;cAAR,CADG;cAEVgB,QAAQ,EAAE;gBAAEhB,IAAI,EAAE;cAAR;YAFA;UAHN;QADU;MADb;IAFE,CARJ;IAuBTiB,SAAS,EAAE;MACT,KAAK;QACHC,WAAW,EAAE,wBADV;QAEHL,OAAO,EAAE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LY,IAAI,EAAE;QACJT,YAAY,EAAEe,QAAQ,CAACN,IAAT,CAAcT,YADxB;QAEJC,eAAe,EAAEc,QAAQ,CAACN,IAAT,CAAcR,eAF3B;QAGJC,UAAU,EAAEa,QAAQ,CAACN,IAAT,CAAcP,UAHtB;QAIJC,UAAU,EAAEY,QAAQ,CAACN,IAAT,CAAcN;MAJtB;IATD,CAAP;EAgBD,CA9BD,CA8BE,OAAOoB,GAAP,EAAY;IACZ,MAAMC,MAAM,GAAGV,mBAAA,CAAWW,IAAX,CAAgBF,GAAhB,CAAf;;IAEAC,MAAM,CAACN,OAAP,GAAiB,EACf,IAAKK,GAAD,CAAoBL,OAApB,IAA+B,EAAnC,CADe;MAEf;MACA,cAAcX,WAAW,CAACY,KAAZ;IAHC,CAAjB;IAMA,MAAMK,MAAN;EACD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"postAuthRefresh.mjs","names":["autoHandler","YHTTPError","refersTo","AUTH_API_PREFIX","authCookieHeaderParameter","name","example","parameter","in","required","schema","type","definition","method","path","operation","operationId","summary","tags","disabled","parameters","requestBody","content","properties","scope","remember","responses","description","access_token","expiration_date","expires_in","token_type","postAuthRefresh","ROOT_AUTHENTICATION_DATA","authCookies","postOAuth2Token","body","cookie","parsedCookies","parse","refresh_token","response","grant_type","authenticationData","headers","build","status","undefined","session","err","newErr","wrap"],"sources":["../../src/handlers/postAuthRefresh.ts"],"sourcesContent":["import { autoHandler } from 'knifecycle';\nimport YHTTPError from 'yhttperror';\nimport { refersTo } from '@whook/whook';\nimport initPostOauth2Token from './postOAuth2Token';\nimport { AUTH_API_PREFIX } from '../services/authCookies';\nimport type {\n WhookAPIHandlerDefinition,\n WhookAPIParameterDefinition,\n} from '@whook/whook';\nimport type {\n AuthCookiesService,\n AuthHandlersConfig,\n} from '../services/authCookies';\nimport type { AsyncReturnType } from 'type-fest';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\nexport const authCookieHeaderParameter: WhookAPIParameterDefinition<string> = {\n name: 'cookie',\n example: 'access_token=an_access_token; refresh_token=a_refresh_token;',\n parameter: {\n name: 'cookie',\n in: 'header',\n required: false,\n schema: {\n type: 'string',\n },\n },\n};\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: `${AUTH_API_PREFIX}/refresh`,\n operation: {\n operationId: 'postAuthRefresh',\n summary: 'Refreshs a user auth',\n tags: ['auth'],\n 'x-whook': {\n disabled: true,\n },\n parameters: [refersTo(authCookieHeaderParameter)],\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: [],\n properties: {\n scope: { type: 'string' },\n remember: { type: 'boolean' },\n },\n },\n },\n },\n },\n responses: {\n 200: {\n description: 'Successfuly refreshed.',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n properties: {\n access_token: { type: 'string' },\n expiration_date: { type: 'string' },\n expires_in: { type: 'string' },\n token_type: { type: 'string' },\n },\n },\n },\n },\n },\n },\n },\n};\n\nexport default autoHandler(postAuthRefresh);\n\nasync function postAuthRefresh<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n ROOT_AUTHENTICATION_DATA,\n authCookies,\n postOAuth2Token,\n }: AuthHandlersConfig<AUTHENTICATION_DATA> & {\n authCookies: AuthCookiesService;\n postOAuth2Token: AsyncReturnType<typeof initPostOauth2Token>;\n },\n {\n body,\n cookie = '',\n }: {\n body: {\n scope: string;\n remember: boolean;\n };\n cookie?: string;\n },\n) {\n const parsedCookies = authCookies.parse(cookie);\n\n try {\n if (!parsedCookies.refresh_token) {\n throw new YHTTPError(401, 'E_REFRESH_COOKIE', cookie);\n }\n\n const response = await postOAuth2Token({\n body: {\n grant_type: 'refresh_token',\n scope: body.scope,\n refresh_token: parsedCookies.refresh_token,\n },\n authenticationData: ROOT_AUTHENTICATION_DATA,\n });\n\n return {\n ...response,\n headers: {\n ...(response.headers || {}),\n 'Set-Cookie': authCookies.build(\n response.status === 200 ? response.body : undefined,\n { session: !body.remember },\n ),\n },\n body: {\n access_token: response.body.access_token,\n expiration_date: response.body.expiration_date,\n expires_in: response.body.expires_in,\n token_type: response.body.token_type,\n },\n };\n } catch (err) {\n const newErr = YHTTPError.wrap(err as Error);\n\n newErr.headers = {\n ...((err as YHTTPError).headers || {}),\n // TODO: Allow string[] in YHTTPError\n 'Set-Cookie': authCookies.build() as unknown as string,\n };\n\n throw newErr;\n }\n}\n"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,OAAOC,UAAP,MAAuB,YAAvB;AACA,SAASC,QAAT,QAAyB,cAAzB;AAEA,SAASC,eAAT,QAAgC,yBAAhC;AAYA,OAAO,MAAMC,yBAA8D,GAAG;EAC5EC,IAAI,EAAE,QADsE;EAE5EC,OAAO,EAAE,8DAFmE;EAG5EC,SAAS,EAAE;IACTF,IAAI,EAAE,QADG;IAETG,EAAE,EAAE,QAFK;IAGTC,QAAQ,EAAE,KAHD;IAITC,MAAM,EAAE;MACNC,IAAI,EAAE;IADA;EAJC;AAHiE,CAAvE;AAaP,OAAO,MAAMC,UAAqC,GAAG;EACnDC,MAAM,EAAE,MAD2C;EAEnDC,IAAI,EAAG,GAAEX,eAAgB,UAF0B;EAGnDY,SAAS,EAAE;IACTC,WAAW,EAAE,iBADJ;IAETC,OAAO,EAAE,sBAFA;IAGTC,IAAI,EAAE,CAAC,MAAD,CAHG;IAIT,WAAW;MACTC,QAAQ,EAAE;IADD,CAJF;IAOTC,UAAU,EAAE,CAAClB,QAAQ,CAACE,yBAAD,CAAT,CAPH;IAQTiB,WAAW,EAAE;MACXZ,QAAQ,EAAE,IADC;MAEXa,OAAO,EAAE;QACP,oBAAoB;UAClBZ,MAAM,EAAE;YACNC,IAAI,EAAE,QADA;YAENF,QAAQ,EAAE,EAFJ;YAGNc,UAAU,EAAE;cACVC,KAAK,EAAE;gBAAEb,IAAI,EAAE;cAAR,CADG;cAEVc,QAAQ,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MAAT,KAAoB,GAApB,GAA0BL,QAAQ,CAACL,IAAnC,GAA0CW,SAD9B,EAEZ;UAAEC,OAAO,EAAE,CAACZ,IAAI,CAACX;QAAjB,CAFY;MAFP,CAFJ;MASLW,IAAI,EAAE;QACJR,YAAY,EAAEa,QAAQ,CAACL,IAAT,CAAcR,YADxB;QAEJC,eAAe,EAAEY,QAAQ,CAACL,IAAT,CAAcP,eAF3B;QAGJC,UAAU,EAAEW,QAAQ,CAACL,IAAT,CAAcN,UAHtB;QAIJC,UAAU,EAAEU,QAAQ,CAACL,IAAT,CAAcL;MAJtB;IATD,CAAP;EAgBD,CA9BD,CA8BE,OAAOkB,GAAP,EAAY;IACZ,MAAMC,MAAM,GAAGjD,UAAU,CAACkD,IAAX,CAAgBF,GAAhB,CAAf;IAEAC,MAAM,CAACN,OAAP,GAAiB,EACf,IAAKK,GAAD,CAAoBL,OAApB,IAA+B,EAAnC,CADe;MAEf;MACA,cAAcV,WAAW,CAACW,KAAZ;IAHC,CAAjB;IAMA,MAAMK,MAAN;EACD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"postAuthRefresh.test.js","names":["describe","test","authCookies","parse","jest","fn","build","postOAuth2Token","postAuthRefresh","initPostAuthRefresh","ROOT_AUTHENTICATION_DATA","scope","applicationId","mockReturnValueOnce","access_token","refresh_token","mockResolvedValueOnce","status","body","expiration_date","expires_in","token_type","response","cookie","remember","expect","authCookiesParseCalls","mock","calls","authCookiesBuildCalls","postOAuth2TokenCalls","toMatchInlineSnapshot"],"sources":["../../src/handlers/postAuthRefresh.test.ts"],"sourcesContent":["import initPostAuthRefresh from './postAuthRefresh';\n\ndescribe('postAuthRefresh', () => {\n test('should work', async () => {\n const authCookies = {\n parse: jest.fn(),\n build: jest.fn(),\n };\n const postOAuth2Token = jest.fn();\n const postAuthRefresh = await initPostAuthRefresh({\n ROOT_AUTHENTICATION_DATA: {\n scope: 'user',\n applicationId: 'root_app_id',\n },\n authCookies,\n postOAuth2Token,\n });\n\n authCookies.parse.mockReturnValueOnce({\n access_token: 'an_access_token',\n refresh_token: 'a_refresh_token',\n });\n authCookies.build.mockReturnValueOnce('the_build_cookies');\n postOAuth2Token.mockResolvedValueOnce({\n status: 200,\n body: {\n access_token: 'an_access_token',\n expiration_date: '2020-02-02T20:22:02Z',\n expires_in: 3600,\n token_type: 'bearer',\n },\n });\n\n const response = await postAuthRefresh({\n cookie: 'a_given_cookie',\n body: {\n remember: false,\n scope: 'user',\n },\n });\n\n expect({\n response,\n authCookiesParseCalls: authCookies.parse.mock.calls,\n authCookiesBuildCalls: authCookies.build.mock.calls,\n postOAuth2TokenCalls: postOAuth2Token.mock.calls,\n }).toMatchInlineSnapshot(`\n Object {\n \"authCookiesBuildCalls\": Array [\n Array [\n Object {\n \"access_token\": \"an_access_token\",\n \"expiration_date\": \"2020-02-02T20:22:02Z\",\n \"expires_in\": 3600,\n \"token_type\": \"bearer\",\n },\n Object {\n \"session\": true,\n },\n ],\n ],\n \"authCookiesParseCalls\": Array [\n Array [\n \"a_given_cookie\",\n ],\n ],\n \"postOAuth2TokenCalls\": Array [\n Array [\n Object {\n \"authenticationData\": Object {\n \"applicationId\": \"root_app_id\",\n \"scope\": \"user\",\n },\n \"body\": Object {\n \"grant_type\": \"refresh_token\",\n \"refresh_token\": \"a_refresh_token\",\n \"scope\": \"user\",\n },\n },\n ],\n ],\n \"response\": Object {\n \"body\": Object {\n \"access_token\": \"an_access_token\",\n \"expiration_date\": \"2020-02-02T20:22:02Z\",\n \"expires_in\": 3600,\n \"token_type\": \"bearer\",\n },\n \"headers\": Object {\n \"Set-Cookie\": \"the_build_cookies\",\n },\n \"status\": 200,\n },\n }\n `);\n });\n});\n"],"mappings":";;AAAA;;;;AAEAA,QAAQ,CAAC,iBAAD,EAAoB,MAAM;EAChCC,IAAI,CAAC,aAAD,EAAgB,YAAY;IAC9B,MAAMC,WAAW,GAAG;MAClBC,KAAK,EAAEC,IAAI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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KArDI;EAsDD,CA5FG,CAAJ;AA6FD,CA9FO,CAAR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"postAuthRefresh.test.mjs","names":["initPostAuthRefresh","describe","test","authCookies","parse","jest","fn","build","postOAuth2Token","postAuthRefresh","ROOT_AUTHENTICATION_DATA","scope","applicationId","mockReturnValueOnce","access_token","refresh_token","mockResolvedValueOnce","status","body","expiration_date","expires_in","token_type","response","cookie","remember","expect","authCookiesParseCalls","mock","calls","authCookiesBuildCalls","postOAuth2TokenCalls","toMatchInlineSnapshot"],"sources":["../../src/handlers/postAuthRefresh.test.ts"],"sourcesContent":["import initPostAuthRefresh from './postAuthRefresh';\n\ndescribe('postAuthRefresh', () => {\n test('should work', async () => {\n const authCookies = {\n parse: jest.fn(),\n build: jest.fn(),\n };\n const postOAuth2Token = jest.fn();\n const postAuthRefresh = await initPostAuthRefresh({\n ROOT_AUTHENTICATION_DATA: {\n scope: 'user',\n applicationId: 'root_app_id',\n },\n authCookies,\n postOAuth2Token,\n });\n\n authCookies.parse.mockReturnValueOnce({\n access_token: 'an_access_token',\n refresh_token: 'a_refresh_token',\n });\n authCookies.build.mockReturnValueOnce('the_build_cookies');\n postOAuth2Token.mockResolvedValueOnce({\n status: 200,\n body: {\n access_token: 'an_access_token',\n expiration_date: '2020-02-02T20:22:02Z',\n expires_in: 3600,\n token_type: 'bearer',\n },\n });\n\n const response = await postAuthRefresh({\n cookie: 'a_given_cookie',\n body: {\n remember: false,\n scope: 'user',\n },\n });\n\n expect({\n response,\n authCookiesParseCalls: authCookies.parse.mock.calls,\n authCookiesBuildCalls: authCookies.build.mock.calls,\n postOAuth2TokenCalls: postOAuth2Token.mock.calls,\n }).toMatchInlineSnapshot(`\n Object {\n \"authCookiesBuildCalls\": Array [\n Array [\n Object {\n \"access_token\": \"an_access_token\",\n \"expiration_date\": \"2020-02-02T20:22:02Z\",\n \"expires_in\": 3600,\n \"token_type\": \"bearer\",\n },\n Object {\n \"session\": true,\n },\n ],\n ],\n \"authCookiesParseCalls\": Array [\n Array [\n \"a_given_cookie\",\n ],\n ],\n \"postOAuth2TokenCalls\": Array [\n Array [\n Object {\n \"authenticationData\": Object {\n \"applicationId\": \"root_app_id\",\n \"scope\": \"user\",\n },\n \"body\": Object {\n \"grant_type\": \"refresh_token\",\n \"refresh_token\": \"a_refresh_token\",\n \"scope\": \"user\",\n },\n },\n ],\n ],\n \"response\": Object {\n \"body\": Object {\n \"access_token\": \"an_access_token\",\n \"expiration_date\": \"2020-02-02T20:22:02Z\",\n \"expires_in\": 3600,\n \"token_type\": \"bearer\",\n },\n \"headers\": Object {\n \"Set-Cookie\": \"the_build_cookies\",\n },\n \"status\": 200,\n },\n }\n `);\n });\n});\n"],"mappings":"AAAA,OAAOA,mBAAP,MAAgC,mBAAhC;AAEAC,QAAQ,CAAC,iBAAD,EAAoB,MAAM;EAChCC,IAAI,CAAC,aAAD,EAAgB,YAAY;IAC9B,MAAMC,WAAW,GAAG;MAClBC,KAAK,EAAEC,IAAI,CAACC,EAAL,EADW;MAElBC,KAAK,EAAEF,IAAI,CAACC,EAAL;IAFW,CAApB;IAIA,MAAME,eAAe,GAAGH,IAAI,CAACC,EAAL,EAAxB;IACA,MAAMG,eAAe,GAAG,MAAMT,mBAAmB,CAAC;MAChDU,wBAAwB,EAAE;QACxBC,KAAK,EAAE,MADiB;QAExBC,aAAa,EAAE;MAFS,CADsB;MAKhDT,WALgD;MAMhDK;IANgD,CAAD,CAAjD;IASAL,WAAW,CAACC,KAAZ,CAAkBS,mBAAlB,CAAsC;MACpCC,YAAY,EAAE,iBADsB;MAEpCC,aAAa,EAAE;IAFqB,CAAtC;IAIAZ,WAAW,CAACI,KAAZ,CAAkBM,mBAAlB,CAAsC,mBAAtC;IACAL,eAAe,CAACQ,qBAAhB,CAAsC;MACpCC,MAAM,EAAE,GAD4B;MAEpCC,IAAI,EAAE;QACJJ,YAAY,EAAE,iBADV;QAEJK,eAAe,EAAE,sBAFb;QAGJC,UAAU,EAAE,IAHR;QAIJC,UAAU,EAAE;MAJR;IAF8B,CAAtC;IAUA,MAAMC,QAAQ,GAAG,MAAMb,eAAe,CAAC;MACrCc,MAAM,EAAE,gBAD6B;MAErCL,IAAI,EAAE;QACJM,QAAQ,EAAE,KADN;QAEJb,KAAK,EAAE;MAFH;IAF+B,CAAD,CAAtC;IAQAc,MAAM,CAAC;MACLH,QADK;MAELI,qBAAqB,EAAEvB,WAAW,CAACC,KAAZ,CAAkBuB,IAAlB,CAAuBC,KAFzC;MAGLC,qBAAqB,EAAE1B,WAAW,CAACI,KAAZ,CAAkBoB,IAAlB,CAAuBC,KAHzC;MAILE,oBAAoB,EAAEtB,eAAe,CAACmB,IAAhB,CAAqBC;IAJtC,CAAD,CAAN,CAKGG,qBALH,CAK0B;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KArDI;EAsDD,CA5FG,CAAJ;AA6FD,CA9FO,CAAR"}
|
|
@@ -3,26 +3,29 @@ import type { CheckApplicationService, OAuth2GranterService } from '../services/
|
|
|
3
3
|
import type { LogService } from 'common-services';
|
|
4
4
|
import type { BaseAuthenticationData } from '@whook/authorization';
|
|
5
5
|
export declare const definition: WhookAPIHandlerDefinition;
|
|
6
|
-
declare
|
|
6
|
+
export declare type HandlerDependencies = {
|
|
7
7
|
ERRORS_DESCRIPTORS: WhookErrorsDescriptors;
|
|
8
|
-
oAuth2Granters: OAuth2GranterService
|
|
8
|
+
oAuth2Granters: OAuth2GranterService[];
|
|
9
9
|
checkApplication: CheckApplicationService;
|
|
10
10
|
log: LogService;
|
|
11
|
-
}
|
|
11
|
+
};
|
|
12
|
+
declare type HandlerParameters<AUTHENTICATION_DATA> = {
|
|
12
13
|
authenticationData: AUTHENTICATION_DATA;
|
|
13
14
|
body: {
|
|
14
|
-
[name: string]: unknown;
|
|
15
15
|
responseType: string;
|
|
16
16
|
clientId: string;
|
|
17
17
|
redirectURI: string;
|
|
18
18
|
scope: string;
|
|
19
19
|
state: string;
|
|
20
20
|
acknowledged: boolean;
|
|
21
|
+
[name: string]: unknown;
|
|
21
22
|
};
|
|
22
|
-
}
|
|
23
|
+
};
|
|
24
|
+
declare const _default: <AUTHENTICATION_DATA extends BaseAuthenticationData<string, string> = BaseAuthenticationData<string, string>>(dependencies: HandlerDependencies) => (parameters: HandlerParameters<AUTHENTICATION_DATA>) => ReturnType<typeof postOAuth2Acknowledge>;
|
|
25
|
+
export default _default;
|
|
26
|
+
declare function postOAuth2Acknowledge<AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData>({ ERRORS_DESCRIPTORS, oAuth2Granters, checkApplication, log, }: HandlerDependencies, { authenticationData, body: { responseType, clientId, redirectURI, scope: demandedScope, state, acknowledged, ...additionalParameters }, }: HandlerParameters<AUTHENTICATION_DATA>): Promise<{
|
|
23
27
|
status: number;
|
|
24
28
|
headers: {
|
|
25
29
|
location: string;
|
|
26
30
|
};
|
|
27
|
-
}
|
|
28
|
-
export default _default;
|
|
31
|
+
}>;
|
|
@@ -128,7 +128,7 @@ async function postOAuth2Acknowledge({
|
|
|
128
128
|
|
|
129
129
|
const granter = oAuth2Granters.find(granter => granter.acknowledger && granter.acknowledger.acknowledgmentType === responseType);
|
|
130
130
|
|
|
131
|
-
if (!granter) {
|
|
131
|
+
if (!granter || !granter.acknowledger) {
|
|
132
132
|
throw new _yerror.default('E_UNKNOWN_ACKNOWLEDGOR_TYPE', responseType);
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -147,7 +147,7 @@ async function postOAuth2Acknowledge({
|
|
|
147
147
|
Object.keys(additionalProperties).forEach(key => url.searchParams.set(snakeCase(key), additionalProperties[key]));
|
|
148
148
|
} catch (err) {
|
|
149
149
|
log('debug', '👫 - OAuth2 acknowledge error', err.code);
|
|
150
|
-
log('debug-stack', err.stack);
|
|
150
|
+
log('debug-stack', err.stack || 'no_stack_trace');
|
|
151
151
|
(0, _getOAuth2Authorize.setURLError)(url, err, ERRORS_DESCRIPTORS[err.code] || ERRORS_DESCRIPTORS.E_OAUTH2);
|
|
152
152
|
}
|
|
153
153
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"postOAuth2Acknowledge.js","names":["definition","method","path","operation","operationId","summary","tags","private","requestBody","required","content","schema","type","properties","responseType","clientId","redirectURI","pattern","format","scope","description","state","acknowledged","responses","autoHandler","postOAuth2Acknowledge","ERRORS_DESCRIPTORS","oAuth2Granters","checkApplication","log","authenticationData","body","demandedScope","additionalParameters","YError","applicationId","url","URL","granter","find","acknowledger","acknowledgmentType","additionalProperties","acknowledge","searchParams","set","Object","keys","forEach","key","snakeCase","err","code","stack","setURLError","E_OAUTH2","status","headers","location","href","s","split","map","toLowerCase","join"],"sources":["../../src/handlers/postOAuth2Acknowledge.ts"],"sourcesContent":["import { autoHandler } from 'knifecycle';\nimport YError from 'yerror';\nimport { setURLError } from './getOAuth2Authorize';\nimport type {\n WhookAPIHandlerDefinition,\n WhookErrorsDescriptors,\n} from '@whook/whook';\nimport type {\n CheckApplicationService,\n OAuth2GranterService,\n} from '../services/oAuth2Granters';\nimport type { LogService } from 'common-services';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\n/* Architecture Note #2: OAuth2 acknowledge\nThis endpoint is to be used by the authentication SSR frontend\n to acknowlege that the user accepted the client request in it.\n*/\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: '/oauth2/acknowledge',\n operation: {\n operationId: 'postOAuth2Acknowledge',\n summary: `Implements the logic that allow the authentication frontend\n to get the [Redirection Endpoint](https://tools.ietf.org/html/rfc6749#section-3.1.2).`,\n tags: ['oauth2'],\n 'x-whook': {\n private: true,\n },\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: [\n 'responseType',\n 'clientId',\n 'redirectURI',\n 'scope',\n 'state',\n 'acknowledged',\n ],\n properties: {\n responseType: {\n type: 'string',\n },\n clientId: {\n type: 'string',\n },\n redirectURI: {\n type: 'string',\n pattern: '^https?://',\n format: 'uri',\n },\n scope: {\n type: 'string',\n description:\n 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n state: {\n type: 'string',\n },\n acknowledged: {\n type: 'boolean',\n description:\n 'Wether the user acknowledged the delegation or not.',\n },\n },\n },\n },\n },\n },\n responses: {\n '201': {\n description: 'Redirection endpoint URI computed.',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['redirectURI'],\n properties: {\n redirectURI: {\n type: 'string',\n pattern: '^https?://',\n format: 'uri',\n },\n },\n },\n },\n },\n },\n },\n },\n};\n\nexport type HandlerDependencies = {\n ERRORS_DESCRIPTORS: WhookErrorsDescriptors;\n oAuth2Granters: OAuth2GranterService[];\n checkApplication: CheckApplicationService;\n log: LogService;\n};\ntype HandlerParameters<AUTHENTICATION_DATA> = {\n authenticationData: AUTHENTICATION_DATA;\n body: {\n responseType: string;\n clientId: string;\n redirectURI: string;\n scope: string;\n state: string;\n acknowledged: boolean;\n [name: string]: unknown;\n };\n};\n\nexport default autoHandler(postOAuth2Acknowledge) as unknown as <\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n dependencies: HandlerDependencies,\n) => (\n parameters: HandlerParameters<AUTHENTICATION_DATA>,\n) => ReturnType<typeof postOAuth2Acknowledge>;\n\nasync function postOAuth2Acknowledge<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n checkApplication,\n log,\n }: HandlerDependencies,\n {\n authenticationData,\n body: {\n responseType,\n clientId,\n redirectURI,\n scope: demandedScope,\n state,\n acknowledged = false,\n ...additionalParameters\n },\n }: HandlerParameters<AUTHENTICATION_DATA>,\n) {\n if (!authenticationData) {\n throw new YError('E_UNAUTHORIZED');\n }\n\n // Here we check the applicationId has the right to authenticate a user\n // with the special type 'root'\n await checkApplication({\n applicationId: authenticationData.applicationId,\n type: 'root',\n scope: '',\n });\n\n const url = new URL(redirectURI);\n\n try {\n if (!acknowledged) {\n throw new YError('E_ACCESS_DENIED', clientId);\n }\n\n const granter = oAuth2Granters.find(\n (granter) =>\n granter.acknowledger &&\n granter.acknowledger.acknowledgmentType === responseType,\n );\n\n if (!granter || !granter.acknowledger) {\n throw new YError('E_UNKNOWN_ACKNOWLEDGOR_TYPE', responseType);\n }\n\n const { applicationId, scope, ...additionalProperties } =\n await granter.acknowledger.acknowledge(\n authenticationData,\n {\n clientId,\n redirectURI,\n scope: demandedScope,\n },\n additionalParameters,\n );\n\n url.searchParams.set('client_id', applicationId);\n url.searchParams.set('scope', scope);\n url.searchParams.set('state', state);\n Object.keys(additionalProperties).forEach((key) =>\n url.searchParams.set(snakeCase(key), additionalProperties[key] as string),\n );\n } catch (err) {\n log('debug', '👫 - OAuth2 acknowledge error', (err as YError).code);\n log('debug-stack', (err as Error).stack || 'no_stack_trace');\n\n setURLError(\n url,\n err as YError,\n ERRORS_DESCRIPTORS[(err as YError).code] || ERRORS_DESCRIPTORS.E_OAUTH2,\n );\n }\n\n return {\n status: 302,\n headers: {\n location: url.href,\n },\n };\n}\n\nfunction snakeCase(s: string): string {\n return s\n .split(/(?=(?<![A-Z])[A-Z])|[^a-zA-Z]+/)\n .map((s) => s.toLowerCase())\n .join('_');\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;AAYA;AACA;AACA;AACA;AAEO,MAAMA,UAAqC,GAAG;EACnDC,MAAM,EAAE,MAD2C;EAEnDC,IAAI,EAAE,qB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,CAAiBC,GAAjB,CAAqB,OAArB,EAA8B1B,KAA9B;IACAiB,GAAG,CAACQ,YAAJ,CAAiBC,GAAjB,CAAqB,OAArB,EAA8BxB,KAA9B;IACAyB,MAAM,CAACC,IAAP,CAAYL,oBAAZ,EAAkCM,OAAlC,CAA2CC,GAAD,IACxCb,GAAG,CAACQ,YAAJ,CAAiBC,GAAjB,CAAqBK,SAAS,CAACD,GAAD,CAA9B,EAAqCP,oBAAoB,CAACO,GAAD,CAAzD,CADF;EAGD,CAhCD,CAgCE,OAAOE,GAAP,EAAY;IACZtB,GAAG,CAAC,OAAD,EAAU,+BAAV,EAA4CsB,GAAD,CAAgBC,IAA3D,CAAH;IACAvB,GAAG,CAAC,aAAD,EAAiBsB,GAAD,CAAeE,KAAf,IAAwB,gBAAxC,CAAH;IAEA,IAAAC,+BAAA,EACElB,GADF,EAEEe,GAFF,EAGEzB,kBAAkB,CAAEyB,GAAD,CAAgBC,IAAjB,CAAlB,IAA4C1B,kBAAkB,CAAC6B,QAHjE;EAKD;;EAED,OAAO;IACLC,MAAM,EAAE,GADH;IAELC,OAAO,EAAE;MACPC,QAAQ,EAAEtB,GAAG,CAACuB;IADP;EAFJ,CAAP;AAMD;;AAED,SAAST,SAAT,CAAmBU,CAAnB,EAAsC;EACpC,OAAOA,CAAC,CACLC,KADI,CACE,gCADF,EAEJC,GAFI,CAECF,CAAD,IAAOA,CAAC,CAACG,WAAF,EAFP,EAGJC,IAHI,CAGC,GAHD,CAAP;AAID"}
|
|
@@ -113,7 +113,7 @@ async function postOAuth2Acknowledge({
|
|
|
113
113
|
|
|
114
114
|
const granter = oAuth2Granters.find(granter => granter.acknowledger && granter.acknowledger.acknowledgmentType === responseType);
|
|
115
115
|
|
|
116
|
-
if (!granter) {
|
|
116
|
+
if (!granter || !granter.acknowledger) {
|
|
117
117
|
throw new YError('E_UNKNOWN_ACKNOWLEDGOR_TYPE', responseType);
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -132,7 +132,7 @@ async function postOAuth2Acknowledge({
|
|
|
132
132
|
Object.keys(additionalProperties).forEach(key => url.searchParams.set(snakeCase(key), additionalProperties[key]));
|
|
133
133
|
} catch (err) {
|
|
134
134
|
log('debug', '👫 - OAuth2 acknowledge error', err.code);
|
|
135
|
-
log('debug-stack', err.stack);
|
|
135
|
+
log('debug-stack', err.stack || 'no_stack_trace');
|
|
136
136
|
setURLError(url, err, ERRORS_DESCRIPTORS[err.code] || ERRORS_DESCRIPTORS.E_OAUTH2);
|
|
137
137
|
}
|
|
138
138
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"postOAuth2Acknowledge.mjs","names":["autoHandler","YError","setURLError","definition","method","path","operation","operationId","summary","tags","private","requestBody","required","content","schema","type","properties","responseType","clientId","redirectURI","pattern","format","scope","description","state","acknowledged","responses","postOAuth2Acknowledge","ERRORS_DESCRIPTORS","oAuth2Granters","checkApplication","log","authenticationData","body","demandedScope","additionalParameters","applicationId","url","URL","granter","find","acknowledger","acknowledgmentType","additionalProperties","acknowledge","searchParams","set","Object","keys","forEach","key","snakeCase","err","code","stack","E_OAUTH2","status","headers","location","href","s","split","map","toLowerCase","join"],"sources":["../../src/handlers/postOAuth2Acknowledge.ts"],"sourcesContent":["import { autoHandler } from 'knifecycle';\nimport YError from 'yerror';\nimport { setURLError } from './getOAuth2Authorize';\nimport type {\n WhookAPIHandlerDefinition,\n WhookErrorsDescriptors,\n} from '@whook/whook';\nimport type {\n CheckApplicationService,\n OAuth2GranterService,\n} from '../services/oAuth2Granters';\nimport type { LogService } from 'common-services';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\n/* Architecture Note #2: OAuth2 acknowledge\nThis endpoint is to be used by the authentication SSR frontend\n to acknowlege that the user accepted the client request in it.\n*/\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: '/oauth2/acknowledge',\n operation: {\n operationId: 'postOAuth2Acknowledge',\n summary: `Implements the logic that allow the authentication frontend\n to get the [Redirection Endpoint](https://tools.ietf.org/html/rfc6749#section-3.1.2).`,\n tags: ['oauth2'],\n 'x-whook': {\n private: true,\n },\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: [\n 'responseType',\n 'clientId',\n 'redirectURI',\n 'scope',\n 'state',\n 'acknowledged',\n ],\n properties: {\n responseType: {\n type: 'string',\n },\n clientId: {\n type: 'string',\n },\n redirectURI: {\n type: 'string',\n pattern: '^https?://',\n format: 'uri',\n },\n scope: {\n type: 'string',\n description:\n 'See https://tools.ietf.org/html/rfc6749#section-3.3',\n },\n state: {\n type: 'string',\n },\n acknowledged: {\n type: 'boolean',\n description:\n 'Wether the user acknowledged the delegation or not.',\n },\n },\n },\n },\n },\n },\n responses: {\n '201': {\n description: 'Redirection endpoint URI computed.',\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['redirectURI'],\n properties: {\n redirectURI: {\n type: 'string',\n pattern: '^https?://',\n format: 'uri',\n },\n },\n },\n },\n },\n },\n },\n },\n};\n\nexport type HandlerDependencies = {\n ERRORS_DESCRIPTORS: WhookErrorsDescriptors;\n oAuth2Granters: OAuth2GranterService[];\n checkApplication: CheckApplicationService;\n log: LogService;\n};\ntype HandlerParameters<AUTHENTICATION_DATA> = {\n authenticationData: AUTHENTICATION_DATA;\n body: {\n responseType: string;\n clientId: string;\n redirectURI: string;\n scope: string;\n state: string;\n acknowledged: boolean;\n [name: string]: unknown;\n };\n};\n\nexport default autoHandler(postOAuth2Acknowledge) as unknown as <\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n dependencies: HandlerDependencies,\n) => (\n parameters: HandlerParameters<AUTHENTICATION_DATA>,\n) => ReturnType<typeof postOAuth2Acknowledge>;\n\nasync function postOAuth2Acknowledge<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n checkApplication,\n log,\n }: HandlerDependencies,\n {\n authenticationData,\n body: {\n responseType,\n clientId,\n redirectURI,\n scope: demandedScope,\n state,\n acknowledged = false,\n ...additionalParameters\n },\n }: HandlerParameters<AUTHENTICATION_DATA>,\n) {\n if (!authenticationData) {\n throw new YError('E_UNAUTHORIZED');\n }\n\n // Here we check the applicationId has the right to authenticate a user\n // with the special type 'root'\n await checkApplication({\n applicationId: authenticationData.applicationId,\n type: 'root',\n scope: '',\n });\n\n const url = new URL(redirectURI);\n\n try {\n if (!acknowledged) {\n throw new YError('E_ACCESS_DENIED', clientId);\n }\n\n const granter = oAuth2Granters.find(\n (granter) =>\n granter.acknowledger &&\n granter.acknowledger.acknowledgmentType === responseType,\n );\n\n if (!granter || !granter.acknowledger) {\n throw new YError('E_UNKNOWN_ACKNOWLEDGOR_TYPE', responseType);\n }\n\n const { applicationId, scope, ...additionalProperties } =\n await granter.acknowledger.acknowledge(\n authenticationData,\n {\n clientId,\n redirectURI,\n scope: demandedScope,\n },\n additionalParameters,\n );\n\n url.searchParams.set('client_id', applicationId);\n url.searchParams.set('scope', scope);\n url.searchParams.set('state', state);\n Object.keys(additionalProperties).forEach((key) =>\n url.searchParams.set(snakeCase(key), additionalProperties[key] as string),\n );\n } catch (err) {\n log('debug', '👫 - OAuth2 acknowledge error', (err as YError).code);\n log('debug-stack', (err as Error).stack || 'no_stack_trace');\n\n setURLError(\n url,\n err as YError,\n ERRORS_DESCRIPTORS[(err as YError).code] || ERRORS_DESCRIPTORS.E_OAUTH2,\n );\n }\n\n return {\n status: 302,\n headers: {\n location: url.href,\n },\n };\n}\n\nfunction snakeCase(s: string): string {\n return s\n .split(/(?=(?<![A-Z])[A-Z])|[^a-zA-Z]+/)\n .map((s) => s.toLowerCase())\n .join('_');\n}\n"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,SAASC,WAAT,QAA4B,sBAA5B;;AAYA;AACA;AACA;AACA;AAEA,OA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,YAAJ,CAAiBC,GAAjB,CAAqB,WAArB,EAAkCV,aAAlC;IACAC,GAAG,CAACQ,YAAJ,CAAiBC,GAAjB,CAAqB,OAArB,EAA8BxB,KAA9B;IACAe,GAAG,CAACQ,YAAJ,CAAiBC,GAAjB,CAAqB,OAArB,EAA8BtB,KAA9B;IACAuB,MAAM,CAACC,IAAP,CAAYL,oBAAZ,EAAkCM,OAAlC,CAA2CC,GAAD,IACxCb,GAAG,CAACQ,YAAJ,CAAiBC,GAAjB,CAAqBK,SAAS,CAACD,GAAD,CAA9B,EAAqCP,oBAAoB,CAACO,GAAD,CAAzD,CADF;EAGD,CAhCD,CAgCE,OAAOE,GAAP,EAAY;IACZrB,GAAG,CAAC,OAAD,EAAU,+BAAV,EAA4CqB,GAAD,CAAgBC,IAA3D,CAAH;IACAtB,GAAG,CAAC,aAAD,EAAiBqB,GAAD,CAAeE,KAAf,IAAwB,gBAAxC,CAAH;IAEApD,WAAW,CACTmC,GADS,EAETe,GAFS,EAGTxB,kBAAkB,CAAEwB,GAAD,CAAgBC,IAAjB,CAAlB,IAA4CzB,kBAAkB,CAAC2B,QAHtD,CAAX;EAKD;;EAED,OAAO;IACLC,MAAM,EAAE,GADH;IAELC,OAAO,EAAE;MACPC,QAAQ,EAAErB,GAAG,CAACsB;IADP;EAFJ,CAAP;AAMD;;AAED,SAASR,SAAT,CAAmBS,CAAnB,EAAsC;EACpC,OAAOA,CAAC,CACLC,KADI,CACE,gCADF,EAEJC,GAFI,CAECF,CAAD,IAAOA,CAAC,CAACG,WAAF,EAFP,EAGJC,IAHI,CAGC,GAHD,CAAP;AAID"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/handlers/postOAuth2Acknowledge.test.ts"],"names":["describe","ERRORS_DESCRIPTORS","DEFAULT_ERRORS_DESCRIPTORS","OAUTH2_ERRORS_DESCRIPTORS","checkApplication","jest","fn","log","codeGranter","type","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate","tokenGranter","oAuth2Granters","beforeEach","mockReset","forEach","mock","test","mockRejectedValueOnce","YError","mockResolvedValueOnce","applicationId","redirectURI","scope","userId","postOAuth2Acknowledge","response","authenticationData","body","clientId","state","acknowledged","expect","toMatchInlineSnapshot","logCalls","calls","filter","endsWith","checkApplicationCalls","codeGranterAuthorizerAuthorizeCalls","codeGranterAcknowledgerAcknowledgeCalls","codeGranterAuthenticatorAuthenticateCalls","tokenGranterAuthorizerAuthorizeCalls","tokenGranterAcknowledgerAcknowledgeCalls","toMatchSnapshot"],"mappings":";;AAAA;;AACA;;AACA;;AACA;;;;AAIAA,QAAQ,CAAC,uBAAD,EAA0B,MAAM;AACtC,QAAMC,kBAAkB,GAAG,EACzB,GAAGC,iCADsB;AAEzB,OAAGC;AAFsB,GAA3B;AAIA,QAAMC,gBAAgB,GAAGC,IAAI,CAACC,EAAL,EAAzB;AACA,QAAMC,GAAG,GAAGF,IAAI,CAACC,EAAL,EAAZ;AACA,QAAME,WAAW,GAAG;AAClBC,IAAAA,IAAI,EAAE,MADY;AAElBC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,YAAY,EAAE,MAAhB;AAAwBC,MAAAA,SAAS,EAAEP,IAAI,CAACC,EAAL;AAAnC,KAFM;AAGlBO,IAAAA,YAAY,EAAE;AAAEC,MAAAA,kBAAkB,EAAE,MAAtB;AAA8BC,MAAAA,WAAW,EAAEV,IAAI,CAACC,EAAL;AAA3C,KAHI;AAIlBU,IAAAA,aAAa,EAAE;AACbC,MAAAA,SAAS,EAAE,oBADE;AAEbC,MAAAA,YAAY,EAAEb,IAAI,CAACC,EAAL;AAFD;AAJG,GAApB;AASA,QAAMa,YAAY,GAAG;AACnBV,IAAAA,IAAI,EAAE,OADa;AAEnBC,IAAAA,UAAU,EAAE;AAAEC,MAAAA,YAAY,EAAE,OAAhB;AAAyBC,MAAAA,SAAS,EAAEP,IAAI,CAACC,EAAL;AAApC,KAFO;AAGnBO,IAAAA,YAAY,E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,QAAQ,EAAEnC,GAAG,CAACiB,IAAJ,CAASmB,KAAT,CAAeC,MAAf,CAAsB,CAAC,CAACnC,IAAD,CAAD,KAAY,CAACA,IAAI,CAACoC,QAAL,CAAc,OAAd,CAAnC,CADL;AAELC,MAAAA,qBAAqB,EAAE1C,gBAAgB,CAACoB,IAAjB,CAAsBmB,KAFxC;AAGLI,MAAAA,mCAAmC,EACjCvC,WAAW,CAACE,UAAZ,CAAuBE,SAAvB,CAAiCY,IAAjC,CAAsCmB,KAJnC;AAKLK,MAAAA,uCAAuC,EACrCxC,WAAW,CAACK,YAAZ,CAAyBE,WAAzB,CAAqCS,IAArC,CAA0CmB,KANvC;AAOLM,MAAAA,yCAAyC,EACvCzC,WAAW,CAACQ,aAAZ,CAA0BE,YAA1B,CAAuCM,IAAvC,CAA4CmB,KARzC;AASLO,MAAAA,oCAAoC,EAClC/B,YAAY,CAACT,UAAb,CAAwBE,SAAxB,CAAkCY,IAAlC,CAAuCmB,KAVpC;AAWLQ,MAAAA,wCAAwC,EACtChC,YAAY,CAACN,YAAb,CAA0BE,WAA1B,CAAsCS,IAAtC,CAA2CmB;AAZxC,KAAD,CAAN,CAaGS,eAbH;AAcD,GA9DG,CAAJ;AA+DD,CAvKO,CAAR","sourcesContent":["import initPostOAuth2Acknowledge from './postOAuth2Acknowledge';\nimport YError from 'yerror';\nimport { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/whook';\nimport { OAUTH2_ERRORS_DESCRIPTORS } from '../services/oAuth2Granters';\nimport type { OAuth2GranterService } from '../services/oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\ndescribe('postOAuth2Acknowledge', () => {\n const ERRORS_DESCRIPTORS = {\n ...DEFAULT_ERRORS_DESCRIPTORS,\n ...OAUTH2_ERRORS_DESCRIPTORS,\n };\n const checkApplication = jest.fn();\n const log = 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 tokenGranter = {\n type: 'token',\n authorizer: { responseType: 'token', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'token', acknowledge: jest.fn() },\n };\n const oAuth2Granters: OAuth2GranterService[] = [codeGranter, tokenGranter];\n\n beforeEach(() => {\n checkApplication.mockReset();\n log.mockReset();\n [\n codeGranter.authorizer.authorize,\n codeGranter.acknowledger.acknowledge,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) => mock.mockReset());\n });\n\n test('should redirect', async () => {\n [\n codeGranter.authorizer.authorize,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n codeGranter.acknowledger.acknowledge.mockResolvedValueOnce({\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'http://lol',\n scope: 'user',\n userId: 1,\n });\n\n const postOAuth2Acknowledge = await initPostOAuth2Acknowledge<\n BaseAuthenticationData & {\n userId: number;\n }\n >({\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n checkApplication,\n log,\n });\n const response = await postOAuth2Acknowledge({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'auth',\n userId: 1,\n },\n body: {\n responseType: 'code',\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n acknowledged: true,\n },\n });\n expect({\n response,\n }).toMatchInlineSnapshot(`\n Object {\n \"response\": Object {\n \"headers\": Object {\n \"location\": \"https://www.example.com/?client_id=abbacaca-abba-caca-abba-cacaabbacaca&scope=user&state=bancal&redirect_uri=http%3A%2F%2Flol&user_id=1\",\n },\n \"status\": 302,\n },\n }\n `);\n expect({\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n checkApplicationCalls: checkApplication.mock.calls,\n codeGranterAuthorizerAuthorizeCalls:\n codeGranter.authorizer.authorize.mock.calls,\n codeGranterAcknowledgerAcknowledgeCalls:\n codeGranter.acknowledger.acknowledge.mock.calls,\n codeGranterAuthenticatorAuthenticateCalls:\n codeGranter.authenticator.authenticate.mock.calls,\n tokenGranterAuthorizerAuthorizeCalls:\n tokenGranter.authorizer.authorize.mock.calls,\n tokenGranterAcknowledgerAcknowledgeCalls:\n tokenGranter.acknowledger.acknowledge.mock.calls,\n }).toMatchSnapshot();\n });\n\n test('should redirect errors too', async () => {\n [\n codeGranter.authorizer.authorize,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n codeGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n\n const postOAuth2Acknowledge = await initPostOAuth2Acknowledge<\n BaseAuthenticationData & {\n userId: number;\n }\n >({\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n checkApplication,\n log,\n });\n const response = await postOAuth2Acknowledge({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'auth',\n userId: 1,\n },\n body: {\n responseType: 'yolo',\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n acknowledged: true,\n },\n });\n expect({\n response,\n }).toMatchInlineSnapshot(`\n Object {\n \"response\": Object {\n \"headers\": Object {\n \"location\": \"https://www.example.com/?error=unsupported_response_type&error_decription=Type+%22yolo%22+not+supported.\",\n },\n \"status\": 302,\n },\n }\n `);\n expect({\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n checkApplicationCalls: checkApplication.mock.calls,\n codeGranterAuthorizerAuthorizeCalls:\n codeGranter.authorizer.authorize.mock.calls,\n codeGranterAcknowledgerAcknowledgeCalls:\n codeGranter.acknowledger.acknowledge.mock.calls,\n codeGranterAuthenticatorAuthenticateCalls:\n codeGranter.authenticator.authenticate.mock.calls,\n tokenGranterAuthorizerAuthorizeCalls:\n tokenGranter.authorizer.authorize.mock.calls,\n tokenGranterAcknowledgerAcknowledgeCalls:\n tokenGranter.acknowledger.acknowledge.mock.calls,\n }).toMatchSnapshot();\n });\n});\n"],"file":"postOAuth2Acknowledge.test.js"}
|
|
1
|
+
{"version":3,"file":"postOAuth2Acknowledge.test.js","names":["describe","ERRORS_DESCRIPTORS","DEFAULT_ERRORS_DESCRIPTORS","OAUTH2_ERRORS_DESCRIPTORS","checkApplication","jest","fn","log","codeGranter","type","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate","tokenGranter","oAuth2Granters","beforeEach","mockReset","forEach","mock","test","mockRejectedValueOnce","YError","mockResolvedValueOnce","applicationId","redirectURI","scope","userId","postOAuth2Acknowledge","initPostOAuth2Acknowledge","response","authenticationData","body","clientId","state","acknowledged","expect","toMatchInlineSnapshot","logCalls","calls","filter","endsWith","checkApplicationCalls","codeGranterAuthorizerAuthorizeCalls","codeGranterAcknowledgerAcknowledgeCalls","codeGranterAuthenticatorAuthenticateCalls","tokenGranterAuthorizerAuthorizeCalls","tokenGranterAcknowledgerAcknowledgeCalls","toMatchSnapshot"],"sources":["../../src/handlers/postOAuth2Acknowledge.test.ts"],"sourcesContent":["import initPostOAuth2Acknowledge from './postOAuth2Acknowledge';\nimport YError from 'yerror';\nimport { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/whook';\nimport { OAUTH2_ERRORS_DESCRIPTORS } from '../services/oAuth2Granters';\nimport type { OAuth2GranterService } from '../services/oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\ndescribe('postOAuth2Acknowledge', () => {\n const ERRORS_DESCRIPTORS = {\n ...DEFAULT_ERRORS_DESCRIPTORS,\n ...OAUTH2_ERRORS_DESCRIPTORS,\n };\n const checkApplication = jest.fn();\n const log = 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 tokenGranter = {\n type: 'token',\n authorizer: { responseType: 'token', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'token', acknowledge: jest.fn() },\n };\n const oAuth2Granters: OAuth2GranterService[] = [codeGranter, tokenGranter];\n\n beforeEach(() => {\n checkApplication.mockReset();\n log.mockReset();\n [\n codeGranter.authorizer.authorize,\n codeGranter.acknowledger.acknowledge,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) => mock.mockReset());\n });\n\n test('should redirect', async () => {\n [\n codeGranter.authorizer.authorize,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n codeGranter.acknowledger.acknowledge.mockResolvedValueOnce({\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'http://lol',\n scope: 'user',\n userId: 1,\n });\n\n const postOAuth2Acknowledge = await initPostOAuth2Acknowledge<\n BaseAuthenticationData & {\n userId: number;\n }\n >({\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n checkApplication,\n log,\n });\n const response = await postOAuth2Acknowledge({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'auth',\n userId: 1,\n },\n body: {\n responseType: 'code',\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n acknowledged: true,\n },\n });\n expect({\n response,\n }).toMatchInlineSnapshot(`\n Object {\n \"response\": Object {\n \"headers\": Object {\n \"location\": \"https://www.example.com/?client_id=abbacaca-abba-caca-abba-cacaabbacaca&scope=user&state=bancal&redirect_uri=http%3A%2F%2Flol&user_id=1\",\n },\n \"status\": 302,\n },\n }\n `);\n expect({\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n checkApplicationCalls: checkApplication.mock.calls,\n codeGranterAuthorizerAuthorizeCalls:\n codeGranter.authorizer.authorize.mock.calls,\n codeGranterAcknowledgerAcknowledgeCalls:\n codeGranter.acknowledger.acknowledge.mock.calls,\n codeGranterAuthenticatorAuthenticateCalls:\n codeGranter.authenticator.authenticate.mock.calls,\n tokenGranterAuthorizerAuthorizeCalls:\n tokenGranter.authorizer.authorize.mock.calls,\n tokenGranterAcknowledgerAcknowledgeCalls:\n tokenGranter.acknowledger.acknowledge.mock.calls,\n }).toMatchSnapshot();\n });\n\n test('should redirect errors too', async () => {\n [\n codeGranter.authorizer.authorize,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n codeGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n\n const postOAuth2Acknowledge = await initPostOAuth2Acknowledge<\n BaseAuthenticationData & {\n userId: number;\n }\n >({\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n checkApplication,\n log,\n });\n const response = await postOAuth2Acknowledge({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'auth',\n userId: 1,\n },\n body: {\n responseType: 'yolo',\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n acknowledged: true,\n },\n });\n expect({\n response,\n }).toMatchInlineSnapshot(`\n Object {\n \"response\": Object {\n \"headers\": Object {\n \"location\": \"https://www.example.com/?error=unsupported_response_type&error_decription=Type+%22yolo%22+not+supported.\",\n },\n \"status\": 302,\n },\n }\n `);\n expect({\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n checkApplicationCalls: checkApplication.mock.calls,\n codeGranterAuthorizerAuthorizeCalls:\n codeGranter.authorizer.authorize.mock.calls,\n codeGranterAcknowledgerAcknowledgeCalls:\n codeGranter.acknowledger.acknowledge.mock.calls,\n codeGranterAuthenticatorAuthenticateCalls:\n codeGranter.authenticator.authenticate.mock.calls,\n tokenGranterAuthorizerAuthorizeCalls:\n tokenGranter.authorizer.authorize.mock.calls,\n tokenGranterAcknowledgerAcknowledgeCalls:\n tokenGranter.acknowledger.acknowledge.mock.calls,\n }).toMatchSnapshot();\n });\n});\n"],"mappings":";;AAAA;;AACA;;AACA;;AACA;;;;AAIAA,QAAQ,CAAC,uBAAD,EAA0B,MAAM;EACtC,MAAMC,kBAAkB,GAAG,EACzB,GAAGC,iCADsB;IAEzB,GAAGC;EAFsB,CAA3B;EAIA,MAAMC,gBAAgB,GAAGC,IAAI,CAACC,EAAL,EAAzB;EACA,MAAMC,GAAG,GAAGF,IAAI,CAACC,EAAL,EAAZ;EACA,MAAME,WAAW,GAAG;IAClBC,IAAI,EAAE,MADY;IAElBC,UAAU,EAAE;MAAEC,YAAY,EAAE,MAAhB;MAAwBC,SAAS,EAAEP,IAAI,CAACC,EAAL;IAAnC,CAFM;IAGlBO,YAAY,EAAE;MAAEC,kBAAkB,EAAE,MAAtB;MAA8BC,WAAW,EAAEV,IAAI,CAACC,EAAL;IAA3C,CAHI;IAIlBU,aAAa,EAAE;MACbC,SAAS,EAAE,oBADE;MAEbC,YAAY,EAAEb,IAAI,CAACC,EAAL;IAFD;EAJG,CAApB;EASA,MAAMa,YAAY,GAAG;IACnBV,IAAI,EAAE,OADa;IAEnBC,UAAU,EAAE;MAAEC,YAAY,EAAE,OAAhB;MAAyBC,SAAS,EAAEP,IAAI,CAACC,EAAL;IAApC,CAFO;IAGnBO,YAAY,EAAE;MAAEC,kBAA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ANvC;MAOLM,yCAAyC,EACvC1C,WAAW,CAACQ,aAAZ,CAA0BE,YAA1B,CAAuCM,IAAvC,CAA4CoB,KARzC;MASLO,oCAAoC,EAClChC,YAAY,CAACT,UAAb,CAAwBE,SAAxB,CAAkCY,IAAlC,CAAuCoB,KAVpC;MAWLQ,wCAAwC,EACtCjC,YAAY,CAACN,YAAb,CAA0BE,WAA1B,CAAsCS,IAAtC,CAA2CoB;IAZxC,CAAD,CAAN,CAaGS,eAbH;EAcD,CA9DG,CAAJ;AA+DD,CAvKO,CAAR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/handlers/postOAuth2Acknowledge.test.ts"],"names":["initPostOAuth2Acknowledge","YError","DEFAULT_ERRORS_DESCRIPTORS","OAUTH2_ERRORS_DESCRIPTORS","describe","ERRORS_DESCRIPTORS","checkApplication","jest","fn","log","codeGranter","type","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate","tokenGranter","oAuth2Granters","beforeEach","mockReset","forEach","mock","test","mockRejectedValueOnce","mockResolvedValueOnce","applicationId","redirectURI","scope","userId","postOAuth2Acknowledge","response","authenticationData","body","clientId","state","acknowledged","expect","toMatchInlineSnapshot","logCalls","calls","filter","endsWith","checkApplicationCalls","codeGranterAuthorizerAuthorizeCalls","codeGranterAcknowledgerAcknowledgeCalls","codeGranterAuthenticatorAuthenticateCalls","tokenGranterAuthorizerAuthorizeCalls","tokenGranterAcknowledgerAcknowledgeCalls","toMatchSnapshot"],"mappings":"AAAA,OAAOA,yBAAP,MAAsC,yBAAtC;AACA,OAAOC,MAAP,MAAmB,QAAnB;AACA,SAASC,0BAAT,QAA2C,cAA3C;AACA,SAASC,yBAAT,QAA0C,4BAA1C;AAIAC,QAAQ,CAAC,uBAAD,EAA0B,MAAM;AACtC,QAAMC,kBAAkB,GAAG,EACzB,GAAGH,0BADsB;AAEzB,OAAGC;AAFsB,GAA3B;AAIA,QAAMG,gBAAgB,GAAG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;AASLO,MAAAA,oCAAoC,EAClC9B,YAAY,CAACT,UAAb,CAAwBE,SAAxB,CAAkCY,IAAlC,CAAuCkB,KAVpC;AAWLQ,MAAAA,wCAAwC,EACtC/B,YAAY,CAACN,YAAb,CAA0BE,WAA1B,CAAsCS,IAAtC,CAA2CkB;AAZxC,KAAD,CAAN,CAaGS,eAbH;AAcD,GA9DG,CAAJ;AA+DD,CAvKO,CAAR","sourcesContent":["import initPostOAuth2Acknowledge from './postOAuth2Acknowledge';\nimport YError from 'yerror';\nimport { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/whook';\nimport { OAUTH2_ERRORS_DESCRIPTORS } from '../services/oAuth2Granters';\nimport type { OAuth2GranterService } from '../services/oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\ndescribe('postOAuth2Acknowledge', () => {\n const ERRORS_DESCRIPTORS = {\n ...DEFAULT_ERRORS_DESCRIPTORS,\n ...OAUTH2_ERRORS_DESCRIPTORS,\n };\n const checkApplication = jest.fn();\n const log = 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 tokenGranter = {\n type: 'token',\n authorizer: { responseType: 'token', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'token', acknowledge: jest.fn() },\n };\n const oAuth2Granters: OAuth2GranterService[] = [codeGranter, tokenGranter];\n\n beforeEach(() => {\n checkApplication.mockReset();\n log.mockReset();\n [\n codeGranter.authorizer.authorize,\n codeGranter.acknowledger.acknowledge,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) => mock.mockReset());\n });\n\n test('should redirect', async () => {\n [\n codeGranter.authorizer.authorize,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n codeGranter.acknowledger.acknowledge.mockResolvedValueOnce({\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'http://lol',\n scope: 'user',\n userId: 1,\n });\n\n const postOAuth2Acknowledge = await initPostOAuth2Acknowledge<\n BaseAuthenticationData & {\n userId: number;\n }\n >({\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n checkApplication,\n log,\n });\n const response = await postOAuth2Acknowledge({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'auth',\n userId: 1,\n },\n body: {\n responseType: 'code',\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n acknowledged: true,\n },\n });\n expect({\n response,\n }).toMatchInlineSnapshot(`\n Object {\n \"response\": Object {\n \"headers\": Object {\n \"location\": \"https://www.example.com/?client_id=abbacaca-abba-caca-abba-cacaabbacaca&scope=user&state=bancal&redirect_uri=http%3A%2F%2Flol&user_id=1\",\n },\n \"status\": 302,\n },\n }\n `);\n expect({\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n checkApplicationCalls: checkApplication.mock.calls,\n codeGranterAuthorizerAuthorizeCalls:\n codeGranter.authorizer.authorize.mock.calls,\n codeGranterAcknowledgerAcknowledgeCalls:\n codeGranter.acknowledger.acknowledge.mock.calls,\n codeGranterAuthenticatorAuthenticateCalls:\n codeGranter.authenticator.authenticate.mock.calls,\n tokenGranterAuthorizerAuthorizeCalls:\n tokenGranter.authorizer.authorize.mock.calls,\n tokenGranterAcknowledgerAcknowledgeCalls:\n tokenGranter.acknowledger.acknowledge.mock.calls,\n }).toMatchSnapshot();\n });\n\n test('should redirect errors too', async () => {\n [\n codeGranter.authorizer.authorize,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n codeGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n\n const postOAuth2Acknowledge = await initPostOAuth2Acknowledge<\n BaseAuthenticationData & {\n userId: number;\n }\n >({\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n checkApplication,\n log,\n });\n const response = await postOAuth2Acknowledge({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'auth',\n userId: 1,\n },\n body: {\n responseType: 'yolo',\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n acknowledged: true,\n },\n });\n expect({\n response,\n }).toMatchInlineSnapshot(`\n Object {\n \"response\": Object {\n \"headers\": Object {\n \"location\": \"https://www.example.com/?error=unsupported_response_type&error_decription=Type+%22yolo%22+not+supported.\",\n },\n \"status\": 302,\n },\n }\n `);\n expect({\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n checkApplicationCalls: checkApplication.mock.calls,\n codeGranterAuthorizerAuthorizeCalls:\n codeGranter.authorizer.authorize.mock.calls,\n codeGranterAcknowledgerAcknowledgeCalls:\n codeGranter.acknowledger.acknowledge.mock.calls,\n codeGranterAuthenticatorAuthenticateCalls:\n codeGranter.authenticator.authenticate.mock.calls,\n tokenGranterAuthorizerAuthorizeCalls:\n tokenGranter.authorizer.authorize.mock.calls,\n tokenGranterAcknowledgerAcknowledgeCalls:\n tokenGranter.acknowledger.acknowledge.mock.calls,\n }).toMatchSnapshot();\n });\n});\n"],"file":"postOAuth2Acknowledge.test.mjs"}
|
|
1
|
+
{"version":3,"file":"postOAuth2Acknowledge.test.mjs","names":["initPostOAuth2Acknowledge","YError","DEFAULT_ERRORS_DESCRIPTORS","OAUTH2_ERRORS_DESCRIPTORS","describe","ERRORS_DESCRIPTORS","checkApplication","jest","fn","log","codeGranter","type","authorizer","responseType","authorize","acknowledger","acknowledgmentType","acknowledge","authenticator","grantType","authenticate","tokenGranter","oAuth2Granters","beforeEach","mockReset","forEach","mock","test","mockRejectedValueOnce","mockResolvedValueOnce","applicationId","redirectURI","scope","userId","postOAuth2Acknowledge","response","authenticationData","body","clientId","state","acknowledged","expect","toMatchInlineSnapshot","logCalls","calls","filter","endsWith","checkApplicationCalls","codeGranterAuthorizerAuthorizeCalls","codeGranterAcknowledgerAcknowledgeCalls","codeGranterAuthenticatorAuthenticateCalls","tokenGranterAuthorizerAuthorizeCalls","tokenGranterAcknowledgerAcknowledgeCalls","toMatchSnapshot"],"sources":["../../src/handlers/postOAuth2Acknowledge.test.ts"],"sourcesContent":["import initPostOAuth2Acknowledge from './postOAuth2Acknowledge';\nimport YError from 'yerror';\nimport { DEFAULT_ERRORS_DESCRIPTORS } from '@whook/whook';\nimport { OAUTH2_ERRORS_DESCRIPTORS } from '../services/oAuth2Granters';\nimport type { OAuth2GranterService } from '../services/oAuth2Granters';\nimport type { BaseAuthenticationData } from '@whook/authorization';\n\ndescribe('postOAuth2Acknowledge', () => {\n const ERRORS_DESCRIPTORS = {\n ...DEFAULT_ERRORS_DESCRIPTORS,\n ...OAUTH2_ERRORS_DESCRIPTORS,\n };\n const checkApplication = jest.fn();\n const log = 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 tokenGranter = {\n type: 'token',\n authorizer: { responseType: 'token', authorize: jest.fn() },\n acknowledger: { acknowledgmentType: 'token', acknowledge: jest.fn() },\n };\n const oAuth2Granters: OAuth2GranterService[] = [codeGranter, tokenGranter];\n\n beforeEach(() => {\n checkApplication.mockReset();\n log.mockReset();\n [\n codeGranter.authorizer.authorize,\n codeGranter.acknowledger.acknowledge,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) => mock.mockReset());\n });\n\n test('should redirect', async () => {\n [\n codeGranter.authorizer.authorize,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n codeGranter.acknowledger.acknowledge.mockResolvedValueOnce({\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'http://lol',\n scope: 'user',\n userId: 1,\n });\n\n const postOAuth2Acknowledge = await initPostOAuth2Acknowledge<\n BaseAuthenticationData & {\n userId: number;\n }\n >({\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n checkApplication,\n log,\n });\n const response = await postOAuth2Acknowledge({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'auth',\n userId: 1,\n },\n body: {\n responseType: 'code',\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n acknowledged: true,\n },\n });\n expect({\n response,\n }).toMatchInlineSnapshot(`\n Object {\n \"response\": Object {\n \"headers\": Object {\n \"location\": \"https://www.example.com/?client_id=abbacaca-abba-caca-abba-cacaabbacaca&scope=user&state=bancal&redirect_uri=http%3A%2F%2Flol&user_id=1\",\n },\n \"status\": 302,\n },\n }\n `);\n expect({\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n checkApplicationCalls: checkApplication.mock.calls,\n codeGranterAuthorizerAuthorizeCalls:\n codeGranter.authorizer.authorize.mock.calls,\n codeGranterAcknowledgerAcknowledgeCalls:\n codeGranter.acknowledger.acknowledge.mock.calls,\n codeGranterAuthenticatorAuthenticateCalls:\n codeGranter.authenticator.authenticate.mock.calls,\n tokenGranterAuthorizerAuthorizeCalls:\n tokenGranter.authorizer.authorize.mock.calls,\n tokenGranterAcknowledgerAcknowledgeCalls:\n tokenGranter.acknowledger.acknowledge.mock.calls,\n }).toMatchSnapshot();\n });\n\n test('should redirect errors too', async () => {\n [\n codeGranter.authorizer.authorize,\n codeGranter.authenticator.authenticate,\n tokenGranter.authorizer.authorize,\n tokenGranter.acknowledger.acknowledge,\n codeGranter.acknowledger.acknowledge,\n ].forEach((mock) =>\n mock.mockRejectedValueOnce(new YError('E_NOT_SUPPOSED_TO_BE_HERE')),\n );\n\n const postOAuth2Acknowledge = await initPostOAuth2Acknowledge<\n BaseAuthenticationData & {\n userId: number;\n }\n >({\n ERRORS_DESCRIPTORS,\n oAuth2Granters,\n checkApplication,\n log,\n });\n const response = await postOAuth2Acknowledge({\n authenticationData: {\n applicationId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n scope: 'auth',\n userId: 1,\n },\n body: {\n responseType: 'yolo',\n clientId: 'abbacaca-abba-caca-abba-cacaabbacaca',\n redirectURI: 'https://www.example.com',\n scope: 'user',\n state: 'bancal',\n acknowledged: true,\n },\n });\n expect({\n response,\n }).toMatchInlineSnapshot(`\n Object {\n \"response\": Object {\n \"headers\": Object {\n \"location\": \"https://www.example.com/?error=unsupported_response_type&error_decription=Type+%22yolo%22+not+supported.\",\n },\n \"status\": 302,\n },\n }\n `);\n expect({\n logCalls: log.mock.calls.filter(([type]) => !type.endsWith('stack')),\n checkApplicationCalls: checkApplication.mock.calls,\n codeGranterAuthorizerAuthorizeCalls:\n codeGranter.authorizer.authorize.mock.calls,\n codeGranterAcknowledgerAcknowledgeCalls:\n codeGranter.acknowledger.acknowledge.mock.calls,\n codeGranterAuthenticatorAuthenticateCalls:\n codeGranter.authenticator.authenticate.mock.calls,\n tokenGranterAuthorizerAuthorizeCalls:\n tokenGranter.authorizer.authorize.mock.calls,\n tokenGranterAcknowledgerAcknowledgeCalls:\n tokenGranter.acknowledger.acknowledge.mock.calls,\n }).toMatchSnapshot();\n });\n});\n"],"mappings":"AAAA,OAAOA,yBAAP,MAAsC,yBAAtC;AACA,OAAOC,MAAP,M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|
|
|
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: <
|
|
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
|
-
}
|
|
17
|
+
}, (parameters: {
|
|
18
18
|
body: {
|
|
19
19
|
[name: string]: unknown;
|
|
20
20
|
grant_type: string;
|
|
21
21
|
};
|
|
22
|
-
authenticationData:
|
|
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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AAE,QAFR;AAGJC,QAAAA,UAAU,EAAEoC,IAAI,CAACC,IAAL,CAAU,CAACV,oBAAoB,GAAGM,WAAxB,IAAuC,IAAjD,CAHR;AAIJK,QAAAA,eAAe,EAAE,IAAI7B,IAAJ,CAASkB,oBAAT,EAA+BY,WAA/B,EAJb;AAKJvD,QAAAA,aAAa,EAAE4C,YALX;AAMJY,QAAAA,wBAAwB,EAAEJ,IAAI,CAACC,IAAL,CACxB,CAACR,qBAAqB,GAAGI,WAAzB,IAAwC,IADhB,CANtB;AASJQ,QAAAA,6BAA6B,EAAE,IAAIhC,IAAJ,CAC7BoB,qBAD6B,EAE7BU,WAF6B;AAT3B;AAHD,KAAP;AAiBD,GAzCD,CAyCE,OAAOG,GAAP,EAAY;AACZ9B,IAAAA,GAAG,CAAC,OAAD,EAAU,iCAAV,EAA6C8B,GAAG,CAACrE,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;EAEt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