@whook/oauth2 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/README.md +384 -0
- package/dist/handlers/getOAuth2Authorize.d.ts +26 -0
- package/dist/handlers/getOAuth2Authorize.js +192 -0
- package/dist/handlers/getOAuth2Authorize.js.map +1 -0
- package/dist/handlers/getOAuth2Authorize.mjs +169 -0
- package/dist/handlers/getOAuth2Authorize.mjs.map +1 -0
- package/dist/handlers/getOAuth2Authorize.test.d.ts +1 -0
- package/dist/handlers/getOAuth2Authorize.test.js +122 -0
- package/dist/handlers/getOAuth2Authorize.test.js.map +1 -0
- package/dist/handlers/getOAuth2Authorize.test.mjs +114 -0
- package/dist/handlers/getOAuth2Authorize.test.mjs.map +1 -0
- package/dist/handlers/postAuthLogin.d.ts +45 -0
- package/dist/handlers/postAuthLogin.js +125 -0
- package/dist/handlers/postAuthLogin.js.map +1 -0
- package/dist/handlers/postAuthLogin.mjs +108 -0
- package/dist/handlers/postAuthLogin.mjs.map +1 -0
- package/dist/handlers/postAuthLogin.test.d.ts +1 -0
- package/dist/handlers/postAuthLogin.test.js +90 -0
- package/dist/handlers/postAuthLogin.test.js.map +1 -0
- package/dist/handlers/postAuthLogin.test.mjs +85 -0
- package/dist/handlers/postAuthLogin.test.mjs.map +1 -0
- package/dist/handlers/postAuthLogout.d.ts +12 -0
- package/dist/handlers/postAuthLogout.js +46 -0
- package/dist/handlers/postAuthLogout.js.map +1 -0
- package/dist/handlers/postAuthLogout.mjs +33 -0
- package/dist/handlers/postAuthLogout.mjs.map +1 -0
- package/dist/handlers/postAuthLogout.test.d.ts +1 -0
- package/dist/handlers/postAuthLogout.test.js +35 -0
- package/dist/handlers/postAuthLogout.test.js.map +1 -0
- package/dist/handlers/postAuthLogout.test.mjs +30 -0
- package/dist/handlers/postAuthLogout.test.mjs.map +1 -0
- package/dist/handlers/postAuthRefresh.d.ts +45 -0
- package/dist/handlers/postAuthRefresh.js +140 -0
- package/dist/handlers/postAuthRefresh.js.map +1 -0
- package/dist/handlers/postAuthRefresh.mjs +122 -0
- package/dist/handlers/postAuthRefresh.mjs.map +1 -0
- package/dist/handlers/postAuthRefresh.test.d.ts +1 -0
- package/dist/handlers/postAuthRefresh.test.js +99 -0
- package/dist/handlers/postAuthRefresh.test.js.map +1 -0
- package/dist/handlers/postAuthRefresh.test.mjs +94 -0
- package/dist/handlers/postAuthRefresh.test.mjs.map +1 -0
- package/dist/handlers/postOAuth2Acknowledge.d.ts +28 -0
- package/dist/handlers/postOAuth2Acknowledge.js +165 -0
- package/dist/handlers/postOAuth2Acknowledge.js.map +1 -0
- package/dist/handlers/postOAuth2Acknowledge.mjs +150 -0
- package/dist/handlers/postOAuth2Acknowledge.mjs.map +1 -0
- package/dist/handlers/postOAuth2Acknowledge.test.d.ts +1 -0
- package/dist/handlers/postOAuth2Acknowledge.test.js +148 -0
- package/dist/handlers/postOAuth2Acknowledge.test.js.map +1 -0
- package/dist/handlers/postOAuth2Acknowledge.test.mjs +140 -0
- package/dist/handlers/postOAuth2Acknowledge.test.mjs.map +1 -0
- package/dist/handlers/postOAuth2Token.d.ts +36 -0
- package/dist/handlers/postOAuth2Token.js +263 -0
- package/dist/handlers/postOAuth2Token.js.map +1 -0
- package/dist/handlers/postOAuth2Token.mjs +242 -0
- package/dist/handlers/postOAuth2Token.mjs.map +1 -0
- package/dist/handlers/postOAuth2Token.test.d.ts +1 -0
- package/dist/handlers/postOAuth2Token.test.js +166 -0
- package/dist/handlers/postOAuth2Token.test.js.map +1 -0
- package/dist/handlers/postOAuth2Token.test.mjs +160 -0
- package/dist/handlers/postOAuth2Token.test.mjs.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +230 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +15 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +759 -0
- package/dist/index.test.js.map +1 -0
- package/dist/index.test.mjs +748 -0
- package/dist/index.test.mjs.map +1 -0
- package/dist/services/authCookies.d.ts +26 -0
- package/dist/services/authCookies.js +74 -0
- package/dist/services/authCookies.js.map +1 -0
- package/dist/services/authCookies.mjs +58 -0
- package/dist/services/authCookies.mjs.map +1 -0
- package/dist/services/authCookies.test.d.ts +1 -0
- package/dist/services/authCookies.test.js +82 -0
- package/dist/services/authCookies.test.js.map +1 -0
- package/dist/services/authCookies.test.mjs +77 -0
- package/dist/services/authCookies.test.mjs.map +1 -0
- package/dist/services/oAuth2ClientCredentialsGranter.d.ts +17 -0
- package/dist/services/oAuth2ClientCredentialsGranter.js +56 -0
- package/dist/services/oAuth2ClientCredentialsGranter.js.map +1 -0
- package/dist/services/oAuth2ClientCredentialsGranter.mjs +41 -0
- package/dist/services/oAuth2ClientCredentialsGranter.mjs.map +1 -0
- package/dist/services/oAuth2CodeGranter.d.ts +17 -0
- package/dist/services/oAuth2CodeGranter.js +115 -0
- package/dist/services/oAuth2CodeGranter.js.map +1 -0
- package/dist/services/oAuth2CodeGranter.mjs +98 -0
- package/dist/services/oAuth2CodeGranter.mjs.map +1 -0
- package/dist/services/oAuth2CodeGranter.test.d.ts +1 -0
- package/dist/services/oAuth2CodeGranter.test.js +86 -0
- package/dist/services/oAuth2CodeGranter.test.js.map +1 -0
- package/dist/services/oAuth2CodeGranter.test.mjs +81 -0
- package/dist/services/oAuth2CodeGranter.test.mjs.map +1 -0
- package/dist/services/oAuth2Granters.d.ts +79 -0
- package/dist/services/oAuth2Granters.js +140 -0
- package/dist/services/oAuth2Granters.js.map +1 -0
- package/dist/services/oAuth2Granters.mjs +127 -0
- package/dist/services/oAuth2Granters.mjs.map +1 -0
- package/dist/services/oAuth2PasswordGranter.d.ts +16 -0
- package/dist/services/oAuth2PasswordGranter.js +55 -0
- package/dist/services/oAuth2PasswordGranter.js.map +1 -0
- package/dist/services/oAuth2PasswordGranter.mjs +40 -0
- package/dist/services/oAuth2PasswordGranter.mjs.map +1 -0
- package/dist/services/oAuth2RefreshTokenGranter.d.ts +15 -0
- package/dist/services/oAuth2RefreshTokenGranter.js +62 -0
- package/dist/services/oAuth2RefreshTokenGranter.js.map +1 -0
- package/dist/services/oAuth2RefreshTokenGranter.mjs +47 -0
- package/dist/services/oAuth2RefreshTokenGranter.mjs.map +1 -0
- package/dist/services/oAuth2TokenGranter.d.ts +15 -0
- package/dist/services/oAuth2TokenGranter.js +92 -0
- package/dist/services/oAuth2TokenGranter.js.map +1 -0
- package/dist/services/oAuth2TokenGranter.mjs +78 -0
- package/dist/services/oAuth2TokenGranter.mjs.map +1 -0
- package/package.json +205 -0
- package/src/__snapshots__/index.test.ts.snap +396 -0
- package/src/handlers/__snapshots__/getOAuth2Authorize.test.ts.snap +38 -0
- package/src/handlers/__snapshots__/postOAuth2Acknowledge.test.ts.snap +61 -0
- package/src/handlers/__snapshots__/postOAuth2Token.test.ts.snap +52 -0
- package/src/handlers/getOAuth2Authorize.test.ts +142 -0
- package/src/handlers/getOAuth2Authorize.ts +222 -0
- package/src/handlers/postAuthLogin.test.ts +88 -0
- package/src/handlers/postAuthLogin.ts +123 -0
- package/src/handlers/postAuthLogout.test.ts +33 -0
- package/src/handlers/postAuthLogout.ts +38 -0
- package/src/handlers/postAuthRefresh.test.ts +97 -0
- package/src/handlers/postAuthRefresh.ts +146 -0
- package/src/handlers/postOAuth2Acknowledge.test.ts +175 -0
- package/src/handlers/postOAuth2Acknowledge.ts +209 -0
- package/src/handlers/postOAuth2Token.test.ts +153 -0
- package/src/handlers/postOAuth2Token.ts +302 -0
- package/src/index.test.ts +936 -0
- package/src/index.ts +105 -0
- package/src/services/__snapshots__/oAuth2CodeGranter.test.ts.snap +49 -0
- package/src/services/authCookies.test.ts +93 -0
- package/src/services/authCookies.ts +82 -0
- package/src/services/oAuth2ClientCredentialsGranter.ts +76 -0
- package/src/services/oAuth2CodeGranter.test.ts +94 -0
- package/src/services/oAuth2CodeGranter.ts +133 -0
- package/src/services/oAuth2Granters.ts +274 -0
- package/src/services/oAuth2PasswordGranter.ts +75 -0
- package/src/services/oAuth2RefreshTokenGranter.ts +77 -0
- package/src/services/oAuth2TokenGranter.ts +105 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/handlers/postAuthLogin.ts"],"names":["definition","method","path","AUTH_API_PREFIX","operation","operationId","summary","tags","disabled","parameters","requestBody","required","content","schema","type","properties","username","password","scope","remember","responses","description","access_token","expiration_date","expires_in","token_type","postAuthLogin","ROOT_AUTHENTICATION_DATA","authCookies","postOAuth2Token","body","response","grant_type","authenticationData","headers","build","status","undefined","session","err","newErr","YHTTPError","wrap"],"mappings":";;;;;;;AAAA;;AACA;;AAEA;;;;AASO,MAAMA,UAAqC,GAAG;AACnDC,EAAAA,MAAM,EAAE,MAD2C;AAEnDC,EAAAA,IAAI,EAAG,GAAEC,4BAAgB,QAF0B;AAGnDC,EAAAA,SAAS,EAAE;AACTC,IAAAA,WAAW,EAAE,eADJ;AAETC,IAAAA,OAAO,EAAE,gBAFA;AAGTC,IAAAA,IAAI,EAAE,CAAC,MAAD,CAHG;AAIT,eAAW;AACTC,MAAAA,QAAQ,EAAE;AADD,KAJF;AAOTC,IAAAA,UAAU,EAAE,EAPH;AAQTC,IAAAA,WAAW,EAAE;AACXC,MAAAA,QAAQ,EAAE,IADC;AAEXC,MAAAA,OAAO,EAAE;AACP,4BAAoB;AAClBC,UAAAA,MAAM,EAAE;AACNC,YAAAA,IAAI,EAAE,QADA;AAENH,YAAAA,QAAQ,EAAE,CAAC,UAAD,EAAa,UAAb,CAFJ;AAGNI,YAAAA,UAAU,EAAE;AACVC,cAAAA,QAAQ,EAAE;AAAEF,gBAAAA,IAAI,EAAE;AAAR,eADA;AAEVG,cAAAA,QAAQ,EAAE;AAAEH,gBAAAA,IAAI,EAAE;AAAR,eAFA;AAGVI,cAAAA,KAAK,EAAE;AAAEJ,gBAAAA,IAAI,EAAE;AAAR,eAHG;AAIVK,cAAAA,QAAQ,EAAE;AAA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L,QAAQ,CAACD,IAAnC,GAA0CO,SAD9B,EAEZ;AAAEC,UAAAA,OAAO,EAAE,CAACR,IAAI,CAACX;AAAjB,SAFY;AAFP,OAFJ;AASLW,MAAAA,IAAI,EAAE;AACJR,QAAAA,YAAY,EAAES,QAAQ,CAACD,IAAT,CAAcR,YADxB;AAEJC,QAAAA,eAAe,EAAEQ,QAAQ,CAACD,IAAT,CAAcP,eAF3B;AAGJC,QAAAA,UAAU,EAAEO,QAAQ,CAACD,IAAT,CAAcN,UAHtB;AAIJC,QAAAA,UAAU,EAAEM,QAAQ,CAACD,IAAT,CAAcL;AAJtB;AATD,KAAP;AAgBD,GA3BD,CA2BE,OAAOc,GAAP,EAAY;AACZ,UAAMC,MAAM,GAAGC,oBAAWC,IAAX,CAAgBH,GAAhB,CAAf;;AAEAC,IAAAA,MAAM,CAACN,OAAP,GAAiB,EACf,IAAIK,GAAG,CAACL,OAAJ,IAAe,EAAnB,CADe;AAEf,oBAAcN,WAAW,CAACO,KAAZ;AAFC,KAAjB;AAKA,UAAMK,MAAN;AACD;AACF","sourcesContent":["import { autoHandler } from 'knifecycle';\nimport YHTTPError from 'yhttperror';\nimport initPostOauth2Token from './postOAuth2Token';\nimport { AUTH_API_PREFIX } from '../services/authCookies';\nimport type { WhookAPIHandlerDefinition } 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 definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: `${AUTH_API_PREFIX}/login`,\n operation: {\n operationId: 'postAuthLogin',\n summary: 'Logs a user in',\n tags: ['auth'],\n 'x-whook': {\n disabled: true,\n },\n parameters: [],\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['username', 'password'],\n properties: {\n username: { type: 'string' },\n password: { type: 'string' },\n scope: { type: 'string' },\n remember: { type: 'boolean' },\n },\n },\n },\n },\n },\n responses: {\n 200: {\n description: 'Successfuly logged in.',\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(postAuthLogin);\n\nasync function postAuthLogin<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n ROOT_AUTHENTICATION_DATA,\n authCookies,\n postOAuth2Token,\n }: AuthHandlersConfig<AUTHENTICATION_DATA> & {\n authCookies: Pick<AuthCookiesService, 'build'>;\n postOAuth2Token: AsyncReturnType<typeof initPostOauth2Token>;\n },\n {\n body,\n }: {\n body: {\n username: string;\n password: string;\n scope: string;\n remember: boolean;\n };\n },\n) {\n try {\n const response = await postOAuth2Token({\n body: {\n grant_type: 'password',\n scope: body.scope,\n username: body.username,\n password: body.password,\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);\n\n newErr.headers = {\n ...(err.headers || {}),\n 'Set-Cookie': authCookies.build(),\n };\n\n throw newErr;\n }\n}\n"],"file":"postAuthLogin.js"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { handler as _handler } from 'knifecycle';
|
|
2
|
+
import YHTTPError from 'yhttperror';
|
|
3
|
+
import { AUTH_API_PREFIX } from '../services/authCookies';
|
|
4
|
+
export const definition = {
|
|
5
|
+
method: 'post',
|
|
6
|
+
path: `${AUTH_API_PREFIX}/login`,
|
|
7
|
+
operation: {
|
|
8
|
+
operationId: 'postAuthLogin',
|
|
9
|
+
summary: 'Logs a user in',
|
|
10
|
+
tags: ['auth'],
|
|
11
|
+
'x-whook': {
|
|
12
|
+
disabled: true
|
|
13
|
+
},
|
|
14
|
+
parameters: [],
|
|
15
|
+
requestBody: {
|
|
16
|
+
required: true,
|
|
17
|
+
content: {
|
|
18
|
+
'application/json': {
|
|
19
|
+
schema: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
required: ['username', 'password'],
|
|
22
|
+
properties: {
|
|
23
|
+
username: {
|
|
24
|
+
type: 'string'
|
|
25
|
+
},
|
|
26
|
+
password: {
|
|
27
|
+
type: 'string'
|
|
28
|
+
},
|
|
29
|
+
scope: {
|
|
30
|
+
type: 'string'
|
|
31
|
+
},
|
|
32
|
+
remember: {
|
|
33
|
+
type: 'boolean'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
responses: {
|
|
41
|
+
200: {
|
|
42
|
+
description: 'Successfuly logged in.',
|
|
43
|
+
content: {
|
|
44
|
+
'application/json': {
|
|
45
|
+
schema: {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
access_token: {
|
|
49
|
+
type: 'string'
|
|
50
|
+
},
|
|
51
|
+
expiration_date: {
|
|
52
|
+
type: 'string'
|
|
53
|
+
},
|
|
54
|
+
expires_in: {
|
|
55
|
+
type: 'string'
|
|
56
|
+
},
|
|
57
|
+
token_type: {
|
|
58
|
+
type: 'string'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
export default _handler(postAuthLogin, "postAuthLogin", ["ROOT_AUTHENTICATION_DATA", "authCookies", "postOAuth2Token"]);
|
|
69
|
+
|
|
70
|
+
async function postAuthLogin({
|
|
71
|
+
ROOT_AUTHENTICATION_DATA,
|
|
72
|
+
authCookies,
|
|
73
|
+
postOAuth2Token
|
|
74
|
+
}, {
|
|
75
|
+
body
|
|
76
|
+
}) {
|
|
77
|
+
try {
|
|
78
|
+
const response = await postOAuth2Token({
|
|
79
|
+
body: {
|
|
80
|
+
grant_type: 'password',
|
|
81
|
+
scope: body.scope,
|
|
82
|
+
username: body.username,
|
|
83
|
+
password: body.password
|
|
84
|
+
},
|
|
85
|
+
authenticationData: ROOT_AUTHENTICATION_DATA
|
|
86
|
+
});
|
|
87
|
+
return { ...response,
|
|
88
|
+
headers: { ...(response.headers || {}),
|
|
89
|
+
'Set-Cookie': authCookies.build(response.status === 200 ? response.body : undefined, {
|
|
90
|
+
session: !body.remember
|
|
91
|
+
})
|
|
92
|
+
},
|
|
93
|
+
body: {
|
|
94
|
+
access_token: response.body.access_token,
|
|
95
|
+
expiration_date: response.body.expiration_date,
|
|
96
|
+
expires_in: response.body.expires_in,
|
|
97
|
+
token_type: response.body.token_type
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
} catch (err) {
|
|
101
|
+
const newErr = YHTTPError.wrap(err);
|
|
102
|
+
newErr.headers = { ...(err.headers || {}),
|
|
103
|
+
'Set-Cookie': authCookies.build()
|
|
104
|
+
};
|
|
105
|
+
throw newErr;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=postAuthLogin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/handlers/postAuthLogin.ts"],"names":["autoHandler","YHTTPError","AUTH_API_PREFIX","definition","method","path","operation","operationId","summary","tags","disabled","parameters","requestBody","required","content","schema","type","properties","username","password","scope","remember","responses","description","access_token","expiration_date","expires_in","token_type","postAuthLogin","ROOT_AUTHENTICATION_DATA","authCookies","postOAuth2Token","body","response","grant_type","authenticationData","headers","build","status","undefined","session","err","newErr","wrap"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,OAAOC,UAAP,MAAuB,YAAvB;AAEA,SA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;AAgBD,GA3BD,CA2BE,OAAOc,GAAP,EAAY;AACZ,UAAMC,MAAM,GAAGzC,UAAU,CAAC0C,IAAX,CAAgBF,GAAhB,CAAf;AAEAC,IAAAA,MAAM,CAACN,OAAP,GAAiB,EACf,IAAIK,GAAG,CAACL,OAAJ,IAAe,EAAnB,CADe;AAEf,oBAAcN,WAAW,CAACO,KAAZ;AAFC,KAAjB;AAKA,UAAMK,MAAN;AACD;AACF","sourcesContent":["import { autoHandler } from 'knifecycle';\nimport YHTTPError from 'yhttperror';\nimport initPostOauth2Token from './postOAuth2Token';\nimport { AUTH_API_PREFIX } from '../services/authCookies';\nimport type { WhookAPIHandlerDefinition } 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 definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: `${AUTH_API_PREFIX}/login`,\n operation: {\n operationId: 'postAuthLogin',\n summary: 'Logs a user in',\n tags: ['auth'],\n 'x-whook': {\n disabled: true,\n },\n parameters: [],\n requestBody: {\n required: true,\n content: {\n 'application/json': {\n schema: {\n type: 'object',\n required: ['username', 'password'],\n properties: {\n username: { type: 'string' },\n password: { type: 'string' },\n scope: { type: 'string' },\n remember: { type: 'boolean' },\n },\n },\n },\n },\n },\n responses: {\n 200: {\n description: 'Successfuly logged in.',\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(postAuthLogin);\n\nasync function postAuthLogin<\n AUTHENTICATION_DATA extends BaseAuthenticationData = BaseAuthenticationData,\n>(\n {\n ROOT_AUTHENTICATION_DATA,\n authCookies,\n postOAuth2Token,\n }: AuthHandlersConfig<AUTHENTICATION_DATA> & {\n authCookies: Pick<AuthCookiesService, 'build'>;\n postOAuth2Token: AsyncReturnType<typeof initPostOauth2Token>;\n },\n {\n body,\n }: {\n body: {\n username: string;\n password: string;\n scope: string;\n remember: boolean;\n };\n },\n) {\n try {\n const response = await postOAuth2Token({\n body: {\n grant_type: 'password',\n scope: body.scope,\n username: body.username,\n password: body.password,\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);\n\n newErr.headers = {\n ...(err.headers || {}),\n 'Set-Cookie': authCookies.build(),\n };\n\n throw newErr;\n }\n}\n"],"file":"postAuthLogin.mjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _postAuthLogin = _interopRequireDefault(require("./postAuthLogin"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
describe('postAuthLogin', () => {
|
|
8
|
+
test('should work', async () => {
|
|
9
|
+
const authCookies = {
|
|
10
|
+
build: jest.fn()
|
|
11
|
+
};
|
|
12
|
+
const postOAuth2Token = jest.fn();
|
|
13
|
+
const postAuthLogin = await (0, _postAuthLogin.default)({
|
|
14
|
+
ROOT_AUTHENTICATION_DATA: {
|
|
15
|
+
scope: 'user',
|
|
16
|
+
applicationId: 'root_app_id'
|
|
17
|
+
},
|
|
18
|
+
authCookies,
|
|
19
|
+
postOAuth2Token
|
|
20
|
+
});
|
|
21
|
+
authCookies.build.mockReturnValueOnce('the_build_cookies');
|
|
22
|
+
postOAuth2Token.mockResolvedValueOnce({
|
|
23
|
+
status: 200,
|
|
24
|
+
body: {
|
|
25
|
+
access_token: 'an_access_token',
|
|
26
|
+
expiration_date: '2020-02-02T20:22:02Z',
|
|
27
|
+
expires_in: 3600,
|
|
28
|
+
token_type: 'bearer'
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const response = await postAuthLogin({
|
|
32
|
+
body: {
|
|
33
|
+
username: 'a_username',
|
|
34
|
+
password: 'a_password',
|
|
35
|
+
remember: false,
|
|
36
|
+
scope: 'user'
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
expect({
|
|
40
|
+
response,
|
|
41
|
+
authCookiesBuildCalls: authCookies.build.mock.calls,
|
|
42
|
+
postOAuth2TokenCalls: postOAuth2Token.mock.calls
|
|
43
|
+
}).toMatchInlineSnapshot(`
|
|
44
|
+
Object {
|
|
45
|
+
"authCookiesBuildCalls": Array [
|
|
46
|
+
Array [
|
|
47
|
+
Object {
|
|
48
|
+
"access_token": "an_access_token",
|
|
49
|
+
"expiration_date": "2020-02-02T20:22:02Z",
|
|
50
|
+
"expires_in": 3600,
|
|
51
|
+
"token_type": "bearer",
|
|
52
|
+
},
|
|
53
|
+
Object {
|
|
54
|
+
"session": true,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
],
|
|
58
|
+
"postOAuth2TokenCalls": Array [
|
|
59
|
+
Array [
|
|
60
|
+
Object {
|
|
61
|
+
"authenticationData": Object {
|
|
62
|
+
"applicationId": "root_app_id",
|
|
63
|
+
"scope": "user",
|
|
64
|
+
},
|
|
65
|
+
"body": Object {
|
|
66
|
+
"grant_type": "password",
|
|
67
|
+
"password": "a_password",
|
|
68
|
+
"scope": "user",
|
|
69
|
+
"username": "a_username",
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
],
|
|
74
|
+
"response": Object {
|
|
75
|
+
"body": Object {
|
|
76
|
+
"access_token": "an_access_token",
|
|
77
|
+
"expiration_date": "2020-02-02T20:22:02Z",
|
|
78
|
+
"expires_in": 3600,
|
|
79
|
+
"token_type": "bearer",
|
|
80
|
+
},
|
|
81
|
+
"headers": Object {
|
|
82
|
+
"Set-Cookie": "the_build_cookies",
|
|
83
|
+
},
|
|
84
|
+
"status": 200,
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
`);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=postAuthLogin.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/handlers/postAuthLogin.test.ts"],"names":["describe","test","authCookies","build","jest","fn","postOAuth2Token","postAuthLogin","ROOT_AUTHENTICATION_DATA","scope","applicationId","mockReturnValueOnce","mockResolvedValueOnce","status","body","access_token","expiration_date","expires_in","token_type","response","username","password","remember","expect","authCookiesBuildCalls","mock","calls","postOAuth2TokenCalls","toMatchInlineSnapshot"],"mappings":";;AAAA;;;;AAEAA,QAAQ,CAAC,eAAD,EAAkB,MAAM;AAC9BC,EAAAA,IAAI,CAAC,aAAD,EAAgB,YAAY;AAC9B,UAAMC,WAAW,GAAG;AAClBC,MAAAA,KAAK,EAAEC,IAAI,CAACC,EAAL;AADW,KAApB;AAGA,UAAMC,eAAe,GAAGF,IAAI,CAACC,EAAL,EAAxB;AACA,UAAME,aAAa,GAAG,MAAM,4BAAkB;AAC5CC,MAAAA,wBAAwB,EAAE;AACxBC,QAAAA,KAAK,EAAE,MADiB;AAExBC,QAAAA,aAAa,EAAE;AAFS,OADkB;AAK5CR,MAAAA,WAL4C;AAM5CI,MAAAA;AAN4C,KAAlB,CAA5B;AASAJ,IAAAA,WAAW,CAACC,KAAZ,CAAkBQ,mBAAlB,CAAsC,mBAAtC;AACAL,IAAAA,eAAe,CAACM,qBAAhB,CAAsC;AACpCC,MAAAA,MAAM,EAAE,GAD4B;AAEpCC,MAAAA,IAAI,EAAE;AACJC,QAAAA,YAAY,EAAE,iBADV;AAEJC,QAAAA,eAAe,EAAE,sBAFb;AAGJC,QAAAA,UAAU,EAAE,IAHR;AAIJC,QAAAA,UAAU,EAAE;AAJR;AAF8B,KAAtC;AAUA,UAAMC,QAAQ,GAAG,MAAMZ,aAAa,CAAC;AACnCO,MAAAA,IAAI,EAAE;AACJM,QAAAA,QAAQ,EAAE,YADN;AAEJC,QAAAA,QAAQ,EAAE,YAFN;AAGJC,QAAAA,QAAQ,EAAE,KAHN;AAIJb,QAAAA,KAAK,EAAE;AAJH;AAD6B,KAAD,CAApC;AASAc,IAAAA,MAAM,CAAC;AACLJ,MAAAA,QADK;AAELK,MAAAA,qBAAqB,EAAEtB,WAAW,CAACC,KAAZ,CAAkBsB,IAAlB,CAAuBC,KAFzC;AAGLC,MAAAA,oBAAoB,EAAErB,eAAe,CAACmB,IAAhB,CAAqBC;AAHtC,KAAD,CAAN,CAIGE,qBAJH,CAI0B;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,KAhDI;AAiDD,GAnFG,CAAJ;AAoFD,CArFO,CAAR","sourcesContent":["import initPostAuthLogin from './postAuthLogin';\n\ndescribe('postAuthLogin', () => {\n test('should work', async () => {\n const authCookies = {\n build: jest.fn(),\n };\n const postOAuth2Token = jest.fn();\n const postAuthLogin = await initPostAuthLogin({\n ROOT_AUTHENTICATION_DATA: {\n scope: 'user',\n applicationId: 'root_app_id',\n },\n authCookies,\n postOAuth2Token,\n });\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 postAuthLogin({\n body: {\n username: 'a_username',\n password: 'a_password',\n remember: false,\n scope: 'user',\n },\n });\n\n expect({\n response,\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 \"postOAuth2TokenCalls\": Array [\n Array [\n Object {\n \"authenticationData\": Object {\n \"applicationId\": \"root_app_id\",\n \"scope\": \"user\",\n },\n \"body\": Object {\n \"grant_type\": \"password\",\n \"password\": \"a_password\",\n \"scope\": \"user\",\n \"username\": \"a_username\",\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"],"file":"postAuthLogin.test.js"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import initPostAuthLogin from './postAuthLogin';
|
|
2
|
+
describe('postAuthLogin', () => {
|
|
3
|
+
test('should work', async () => {
|
|
4
|
+
const authCookies = {
|
|
5
|
+
build: jest.fn()
|
|
6
|
+
};
|
|
7
|
+
const postOAuth2Token = jest.fn();
|
|
8
|
+
const postAuthLogin = await initPostAuthLogin({
|
|
9
|
+
ROOT_AUTHENTICATION_DATA: {
|
|
10
|
+
scope: 'user',
|
|
11
|
+
applicationId: 'root_app_id'
|
|
12
|
+
},
|
|
13
|
+
authCookies,
|
|
14
|
+
postOAuth2Token
|
|
15
|
+
});
|
|
16
|
+
authCookies.build.mockReturnValueOnce('the_build_cookies');
|
|
17
|
+
postOAuth2Token.mockResolvedValueOnce({
|
|
18
|
+
status: 200,
|
|
19
|
+
body: {
|
|
20
|
+
access_token: 'an_access_token',
|
|
21
|
+
expiration_date: '2020-02-02T20:22:02Z',
|
|
22
|
+
expires_in: 3600,
|
|
23
|
+
token_type: 'bearer'
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const response = await postAuthLogin({
|
|
27
|
+
body: {
|
|
28
|
+
username: 'a_username',
|
|
29
|
+
password: 'a_password',
|
|
30
|
+
remember: false,
|
|
31
|
+
scope: 'user'
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
expect({
|
|
35
|
+
response,
|
|
36
|
+
authCookiesBuildCalls: authCookies.build.mock.calls,
|
|
37
|
+
postOAuth2TokenCalls: postOAuth2Token.mock.calls
|
|
38
|
+
}).toMatchInlineSnapshot(`
|
|
39
|
+
Object {
|
|
40
|
+
"authCookiesBuildCalls": Array [
|
|
41
|
+
Array [
|
|
42
|
+
Object {
|
|
43
|
+
"access_token": "an_access_token",
|
|
44
|
+
"expiration_date": "2020-02-02T20:22:02Z",
|
|
45
|
+
"expires_in": 3600,
|
|
46
|
+
"token_type": "bearer",
|
|
47
|
+
},
|
|
48
|
+
Object {
|
|
49
|
+
"session": true,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
],
|
|
53
|
+
"postOAuth2TokenCalls": Array [
|
|
54
|
+
Array [
|
|
55
|
+
Object {
|
|
56
|
+
"authenticationData": Object {
|
|
57
|
+
"applicationId": "root_app_id",
|
|
58
|
+
"scope": "user",
|
|
59
|
+
},
|
|
60
|
+
"body": Object {
|
|
61
|
+
"grant_type": "password",
|
|
62
|
+
"password": "a_password",
|
|
63
|
+
"scope": "user",
|
|
64
|
+
"username": "a_username",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
],
|
|
69
|
+
"response": Object {
|
|
70
|
+
"body": Object {
|
|
71
|
+
"access_token": "an_access_token",
|
|
72
|
+
"expiration_date": "2020-02-02T20:22:02Z",
|
|
73
|
+
"expires_in": 3600,
|
|
74
|
+
"token_type": "bearer",
|
|
75
|
+
},
|
|
76
|
+
"headers": Object {
|
|
77
|
+
"Set-Cookie": "the_build_cookies",
|
|
78
|
+
},
|
|
79
|
+
"status": 200,
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
`);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=postAuthLogin.test.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/handlers/postAuthLogin.test.ts"],"names":["initPostAuthLogin","describe","test","authCookies","build","jest","fn","postOAuth2Token","postAuthLogin","ROOT_AUTHENTICATION_DATA","scope","applicationId","mockReturnValueOnce","mockResolvedValueOnce","status","body","access_token","expiration_date","expires_in","token_type","response","username","password","remember","expect","authCookiesBuildCalls","mock","calls","postOAuth2TokenCalls","toMatchInlineSnapshot"],"mappings":"AAAA,OAAOA,iBAAP,MAA8B,iBAA9B;AAEAC,QAAQ,CAAC,eAAD,EAAkB,MAAM;AAC9BC,EAAAA,IAAI,CAAC,aAAD,EAAgB,YAAY;AAC9B,UAAMC,WAAW,GAAG;AAClBC,MAAAA,KAAK,EAAEC,IAAI,CAACC,EAAL;AADW,KAApB;AAGA,UAAMC,eAAe,GAAGF,IAAI,CAACC,EAAL,EAAxB;AACA,UAAME,aAAa,GAAG,MAAMR,iBAAiB,CAAC;AAC5CS,MAAAA,wBAAwB,EAAE;AACxBC,QAAAA,KAAK,EAAE,MADiB;AAExBC,QAAAA,aAAa,EAAE;AAFS,OADkB;AAK5CR,MAAAA,WAL4C;AAM5CI,MAAAA;AAN4C,KAAD,CAA7C;AASAJ,IAAAA,WAAW,CAACC,KAAZ,CAAkBQ,mBAAlB,CAAsC,mBAAtC;AACAL,IAAAA,eAAe,CAACM,qBAAhB,CAAsC;AACpCC,MAAAA,MAAM,EAAE,GAD4B;AAEpCC,MAAAA,IAAI,EAAE;AACJC,QAAAA,YAAY,EAAE,iBADV;AAEJC,QAAAA,eAAe,EAAE,sBAFb;AAGJC,QAAAA,UAAU,EAAE,IAHR;AAIJC,QAAAA,UAAU,EAAE;AAJR;AAF8B,KAAtC;AAUA,UAAMC,QAAQ,GAAG,MAAMZ,aAAa,CAAC;AACnCO,MAAAA,IAAI,EAAE;AACJM,QAAAA,QAAQ,EAAE,YADN;AAEJC,QAAAA,QAAQ,EAAE,YAFN;AAGJC,QAAAA,QAAQ,EAAE,KAHN;AAIJb,QAAAA,KAAK,EAAE;AAJH;AAD6B,KAAD,CAApC;AASAc,IAAAA,MAAM,CAAC;AACLJ,MAAAA,QADK;AAELK,MAAAA,qBAAqB,EAAEtB,WAAW,CAACC,KAAZ,CAAkBsB,IAAlB,CAAuBC,KAFzC;AAGLC,MAAAA,oBAAoB,EAAErB,eAAe,CAACmB,IAAhB,CAAqBC;AAHtC,KAAD,CAAN,CAIGE,qBAJH,CAI0B;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,KAhDI;AAiDD,GAnFG,CAAJ;AAoFD,CArFO,CAAR","sourcesContent":["import initPostAuthLogin from './postAuthLogin';\n\ndescribe('postAuthLogin', () => {\n test('should work', async () => {\n const authCookies = {\n build: jest.fn(),\n };\n const postOAuth2Token = jest.fn();\n const postAuthLogin = await initPostAuthLogin({\n ROOT_AUTHENTICATION_DATA: {\n scope: 'user',\n applicationId: 'root_app_id',\n },\n authCookies,\n postOAuth2Token,\n });\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 postAuthLogin({\n body: {\n username: 'a_username',\n password: 'a_password',\n remember: false,\n scope: 'user',\n },\n });\n\n expect({\n response,\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 \"postOAuth2TokenCalls\": Array [\n Array [\n Object {\n \"authenticationData\": Object {\n \"applicationId\": \"root_app_id\",\n \"scope\": \"user\",\n },\n \"body\": Object {\n \"grant_type\": \"password\",\n \"password\": \"a_password\",\n \"scope\": \"user\",\n \"username\": \"a_username\",\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"],"file":"postAuthLogin.test.mjs"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WhookAPIHandlerDefinition } from '@whook/whook';
|
|
2
|
+
import type { AuthCookiesService } from '../services/authCookies';
|
|
3
|
+
export declare const definition: WhookAPIHandlerDefinition;
|
|
4
|
+
declare const _default: import("knifecycle").ServiceInitializer<{
|
|
5
|
+
authCookies: Pick<AuthCookiesService, "build">;
|
|
6
|
+
}, (parameters: import("knifecycle").Parameters<unknown>) => Promise<{
|
|
7
|
+
status: number;
|
|
8
|
+
headers: {
|
|
9
|
+
'Set-Cookie': string[];
|
|
10
|
+
};
|
|
11
|
+
}>>;
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.definition = void 0;
|
|
7
|
+
|
|
8
|
+
var _knifecycle = require("knifecycle");
|
|
9
|
+
|
|
10
|
+
var _authCookies = require("../services/authCookies");
|
|
11
|
+
|
|
12
|
+
const definition = {
|
|
13
|
+
method: 'post',
|
|
14
|
+
path: `${_authCookies.AUTH_API_PREFIX}/logout`,
|
|
15
|
+
operation: {
|
|
16
|
+
operationId: 'postAuthLogout',
|
|
17
|
+
summary: 'Logs a user out',
|
|
18
|
+
tags: ['auth'],
|
|
19
|
+
'x-whook': {
|
|
20
|
+
disabled: true
|
|
21
|
+
},
|
|
22
|
+
parameters: [],
|
|
23
|
+
responses: {
|
|
24
|
+
204: {
|
|
25
|
+
description: 'Successfuly logged out!'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.definition = definition;
|
|
31
|
+
|
|
32
|
+
var _default = (0, _knifecycle.handler)(postAuthLogout, "postAuthLogout", ["authCookies"]);
|
|
33
|
+
|
|
34
|
+
exports.default = _default;
|
|
35
|
+
|
|
36
|
+
async function postAuthLogout({
|
|
37
|
+
authCookies
|
|
38
|
+
}) {
|
|
39
|
+
return {
|
|
40
|
+
status: 204,
|
|
41
|
+
headers: {
|
|
42
|
+
'Set-Cookie': authCookies.build()
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=postAuthLogout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/handlers/postAuthLogout.ts"],"names":["definition","method","path","AUTH_API_PREFIX","operation","operationId","summary","tags","disabled","parameters","responses","description","postAuthLogout","authCookies","status","headers","build"],"mappings":";;;;;;;AAAA;;AACA;;AAIO,MAAMA,UAAqC,GAAG;AACnDC,EAAAA,MAAM,EAAE,MAD2C;AAEnDC,EAAAA,IAAI,EAAG,GAAEC,4BAAgB,SAF0B;AAGnDC,EAAAA,SAAS,EAAE;AACTC,IAAAA,WAAW,EAAE,gBADJ;AAETC,IAAAA,OAAO,EAAE,iBAFA;AAGTC,IAAAA,IAAI,EAAE,CAAC,MAAD,CAHG;AAIT,eAAW;AACTC,MAAAA,QAAQ,EAAE;AADD,KAJF;AAOTC,IAAAA,UAAU,EAAE,EAPH;AAQTC,IAAAA,SAAS,EAAE;AACT,WAAK;AACHC,QAAAA,WAAW,EAAE;AADV;AADI;AARF;AAHwC,CAA9C;;;eAmBQ,yBAAYC,cAAZ,oC;;;;AAEf,eAAeA,cAAf,CAA8B;AAC5BC,EAAAA;AAD4B,CAA9B,EAIG;AACD,SAAO;AACLC,IAAAA,MAAM,EAAE,GADH;AAELC,IAAAA,OAAO,EAAE;AACP,oBAAcF,WAAW,CAACG,KAAZ;AADP;AAFJ,GAAP;AAMD","sourcesContent":["import { autoHandler } from 'knifecycle';\nimport { AUTH_API_PREFIX } from '../services/authCookies';\nimport type { WhookAPIHandlerDefinition } from '@whook/whook';\nimport type { AuthCookiesService } from '../services/authCookies';\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: `${AUTH_API_PREFIX}/logout`,\n operation: {\n operationId: 'postAuthLogout',\n summary: 'Logs a user out',\n tags: ['auth'],\n 'x-whook': {\n disabled: true,\n },\n parameters: [],\n responses: {\n 204: {\n description: 'Successfuly logged out!',\n },\n },\n },\n};\n\nexport default autoHandler(postAuthLogout);\n\nasync function postAuthLogout({\n authCookies,\n}: {\n authCookies: Pick<AuthCookiesService, 'build'>;\n}) {\n return {\n status: 204,\n headers: {\n 'Set-Cookie': authCookies.build(),\n },\n };\n}\n"],"file":"postAuthLogout.js"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { handler as _handler } from 'knifecycle';
|
|
2
|
+
import { AUTH_API_PREFIX } from '../services/authCookies';
|
|
3
|
+
export const definition = {
|
|
4
|
+
method: 'post',
|
|
5
|
+
path: `${AUTH_API_PREFIX}/logout`,
|
|
6
|
+
operation: {
|
|
7
|
+
operationId: 'postAuthLogout',
|
|
8
|
+
summary: 'Logs a user out',
|
|
9
|
+
tags: ['auth'],
|
|
10
|
+
'x-whook': {
|
|
11
|
+
disabled: true
|
|
12
|
+
},
|
|
13
|
+
parameters: [],
|
|
14
|
+
responses: {
|
|
15
|
+
204: {
|
|
16
|
+
description: 'Successfuly logged out!'
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export default _handler(postAuthLogout, "postAuthLogout", ["authCookies"]);
|
|
22
|
+
|
|
23
|
+
async function postAuthLogout({
|
|
24
|
+
authCookies
|
|
25
|
+
}) {
|
|
26
|
+
return {
|
|
27
|
+
status: 204,
|
|
28
|
+
headers: {
|
|
29
|
+
'Set-Cookie': authCookies.build()
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=postAuthLogout.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/handlers/postAuthLogout.ts"],"names":["autoHandler","AUTH_API_PREFIX","definition","method","path","operation","operationId","summary","tags","disabled","parameters","responses","description","postAuthLogout","authCookies","status","headers","build"],"mappings":"AAAA,SAASA,OAAW,IAAXA,QAAT,QAA4B,YAA5B;AACA,SAASC,eAAT,QAAgC,yBAAhC;AAIA,OAAO,MAAMC,UAAqC,GAAG;AACnDC,EAAAA,MAAM,EAAE,MAD2C;AAEnDC,EAAAA,IAAI,EAAG,GAAEH,eAAgB,SAF0B;AAGnDI,EAAAA,SAAS,EAAE;AACTC,IAAAA,WAAW,EAAE,gBADJ;AAETC,IAAAA,OAAO,EAAE,iBAFA;AAGTC,IAAAA,IAAI,EAAE,CAAC,MAAD,CAHG;AAIT,eAAW;AACTC,MAAAA,QAAQ,EAAE;AADD,KAJF;AAOTC,IAAAA,UAAU,EAAE,EAPH;AAQTC,IAAAA,SAAS,EAAE;AACT,WAAK;AACHC,QAAAA,WAAW,EAAE;AADV;AADI;AARF;AAHwC,CAA9C;AAmBP,eAAeZ,QAAW,CAACa,cAAD,oCAA1B;;AAEA,eAAeA,cAAf,CAA8B;AAC5BC,EAAAA;AAD4B,CAA9B,EAIG;AACD,SAAO;AACLC,IAAAA,MAAM,EAAE,GADH;AAELC,IAAAA,OAAO,EAAE;AACP,oBAAcF,WAAW,CAACG,KAAZ;AADP;AAFJ,GAAP;AAMD","sourcesContent":["import { autoHandler } from 'knifecycle';\nimport { AUTH_API_PREFIX } from '../services/authCookies';\nimport type { WhookAPIHandlerDefinition } from '@whook/whook';\nimport type { AuthCookiesService } from '../services/authCookies';\n\nexport const definition: WhookAPIHandlerDefinition = {\n method: 'post',\n path: `${AUTH_API_PREFIX}/logout`,\n operation: {\n operationId: 'postAuthLogout',\n summary: 'Logs a user out',\n tags: ['auth'],\n 'x-whook': {\n disabled: true,\n },\n parameters: [],\n responses: {\n 204: {\n description: 'Successfuly logged out!',\n },\n },\n },\n};\n\nexport default autoHandler(postAuthLogout);\n\nasync function postAuthLogout({\n authCookies,\n}: {\n authCookies: Pick<AuthCookiesService, 'build'>;\n}) {\n return {\n status: 204,\n headers: {\n 'Set-Cookie': authCookies.build(),\n },\n };\n}\n"],"file":"postAuthLogout.mjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _postAuthLogout = _interopRequireDefault(require("./postAuthLogout"));
|
|
4
|
+
|
|
5
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
|
+
|
|
7
|
+
describe('postAuthLogout', () => {
|
|
8
|
+
test('should work', async () => {
|
|
9
|
+
const authCookies = {
|
|
10
|
+
build: jest.fn()
|
|
11
|
+
};
|
|
12
|
+
const postAuthLogout = await (0, _postAuthLogout.default)({
|
|
13
|
+
authCookies
|
|
14
|
+
});
|
|
15
|
+
authCookies.build.mockReturnValueOnce('the_build_cookies');
|
|
16
|
+
const response = await postAuthLogout({});
|
|
17
|
+
expect({
|
|
18
|
+
response,
|
|
19
|
+
authCookiesBuildCalls: authCookies.build.mock.calls
|
|
20
|
+
}).toMatchInlineSnapshot(`
|
|
21
|
+
Object {
|
|
22
|
+
"authCookiesBuildCalls": Array [
|
|
23
|
+
Array [],
|
|
24
|
+
],
|
|
25
|
+
"response": Object {
|
|
26
|
+
"headers": Object {
|
|
27
|
+
"Set-Cookie": "the_build_cookies",
|
|
28
|
+
},
|
|
29
|
+
"status": 204,
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
`);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=postAuthLogout.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/handlers/postAuthLogout.test.ts"],"names":["describe","test","authCookies","build","jest","fn","postAuthLogout","mockReturnValueOnce","response","expect","authCookiesBuildCalls","mock","calls","toMatchInlineSnapshot"],"mappings":";;AAAA;;;;AAEAA,QAAQ,CAAC,gBAAD,EAAmB,MAAM;AAC/BC,EAAAA,IAAI,CAAC,aAAD,EAAgB,YAAY;AAC9B,UAAMC,WAAW,GAAG;AAClBC,MAAAA,KAAK,EAAEC,IAAI,CAACC,EAAL;AADW,KAApB;AAGA,UAAMC,cAAc,GAAG,MAAM,6BAAmB;AAC9CJ,MAAAA;AAD8C,KAAnB,CAA7B;AAIAA,IAAAA,WAAW,CAACC,KAAZ,CAAkBI,mBAAlB,CAAsC,mBAAtC;AAEA,UAAMC,QAAQ,GAAG,MAAMF,cAAc,CAAC,EAAD,CAArC;AAEAG,IAAAA,MAAM,CAAC;AACLD,MAAAA,QADK;AAELE,MAAAA,qBAAqB,EAAER,WAAW,CAACC,KAAZ,CAAkBQ,IAAlB,CAAuBC;AAFzC,KAAD,CAAN,CAGGC,qBAHH,CAG0B;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAfI;AAgBD,GA5BG,CAAJ;AA6BD,CA9BO,CAAR","sourcesContent":["import initPostAuthLogout from './postAuthLogout';\n\ndescribe('postAuthLogout', () => {\n test('should work', async () => {\n const authCookies = {\n build: jest.fn(),\n };\n const postAuthLogout = await initPostAuthLogout({\n authCookies,\n });\n\n authCookies.build.mockReturnValueOnce('the_build_cookies');\n\n const response = await postAuthLogout({});\n\n expect({\n response,\n authCookiesBuildCalls: authCookies.build.mock.calls,\n }).toMatchInlineSnapshot(`\n Object {\n \"authCookiesBuildCalls\": Array [\n Array [],\n ],\n \"response\": Object {\n \"headers\": Object {\n \"Set-Cookie\": \"the_build_cookies\",\n },\n \"status\": 204,\n },\n }\n `);\n });\n});\n"],"file":"postAuthLogout.test.js"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import initPostAuthLogout from './postAuthLogout';
|
|
2
|
+
describe('postAuthLogout', () => {
|
|
3
|
+
test('should work', async () => {
|
|
4
|
+
const authCookies = {
|
|
5
|
+
build: jest.fn()
|
|
6
|
+
};
|
|
7
|
+
const postAuthLogout = await initPostAuthLogout({
|
|
8
|
+
authCookies
|
|
9
|
+
});
|
|
10
|
+
authCookies.build.mockReturnValueOnce('the_build_cookies');
|
|
11
|
+
const response = await postAuthLogout({});
|
|
12
|
+
expect({
|
|
13
|
+
response,
|
|
14
|
+
authCookiesBuildCalls: authCookies.build.mock.calls
|
|
15
|
+
}).toMatchInlineSnapshot(`
|
|
16
|
+
Object {
|
|
17
|
+
"authCookiesBuildCalls": Array [
|
|
18
|
+
Array [],
|
|
19
|
+
],
|
|
20
|
+
"response": Object {
|
|
21
|
+
"headers": Object {
|
|
22
|
+
"Set-Cookie": "the_build_cookies",
|
|
23
|
+
},
|
|
24
|
+
"status": 204,
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
`);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=postAuthLogout.test.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/handlers/postAuthLogout.test.ts"],"names":["initPostAuthLogout","describe","test","authCookies","build","jest","fn","postAuthLogout","mockReturnValueOnce","response","expect","authCookiesBuildCalls","mock","calls","toMatchInlineSnapshot"],"mappings":"AAAA,OAAOA,kBAAP,MAA+B,kBAA/B;AAEAC,QAAQ,CAAC,gBAAD,EAAmB,MAAM;AAC/BC,EAAAA,IAAI,CAAC,aAAD,EAAgB,YAAY;AAC9B,UAAMC,WAAW,GAAG;AAClBC,MAAAA,KAAK,EAAEC,IAAI,CAACC,EAAL;AADW,KAApB;AAGA,UAAMC,cAAc,GAAG,MAAMP,kBAAkB,CAAC;AAC9CG,MAAAA;AAD8C,KAAD,CAA/C;AAIAA,IAAAA,WAAW,CAACC,KAAZ,CAAkBI,mBAAlB,CAAsC,mBAAtC;AAEA,UAAMC,QAAQ,GAAG,MAAMF,cAAc,CAAC,EAAD,CAArC;AAEAG,IAAAA,MAAM,CAAC;AACLD,MAAAA,QADK;AAELE,MAAAA,qBAAqB,EAAER,WAAW,CAACC,KAAZ,CAAkBQ,IAAlB,CAAuBC;AAFzC,KAAD,CAAN,CAGGC,qBAHH,CAG0B;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAfI;AAgBD,GA5BG,CAAJ;AA6BD,CA9BO,CAAR","sourcesContent":["import initPostAuthLogout from './postAuthLogout';\n\ndescribe('postAuthLogout', () => {\n test('should work', async () => {\n const authCookies = {\n build: jest.fn(),\n };\n const postAuthLogout = await initPostAuthLogout({\n authCookies,\n });\n\n authCookies.build.mockReturnValueOnce('the_build_cookies');\n\n const response = await postAuthLogout({});\n\n expect({\n response,\n authCookiesBuildCalls: authCookies.build.mock.calls,\n }).toMatchInlineSnapshot(`\n Object {\n \"authCookiesBuildCalls\": Array [\n Array [],\n ],\n \"response\": Object {\n \"headers\": Object {\n \"Set-Cookie\": \"the_build_cookies\",\n },\n \"status\": 204,\n },\n }\n `);\n });\n});\n"],"file":"postAuthLogout.test.mjs"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { WhookAPIHandlerDefinition, WhookAPIParameterDefinition } from '@whook/whook';
|
|
2
|
+
import type { AuthCookiesService, AuthHandlersConfig } from '../services/authCookies';
|
|
3
|
+
import type { BaseAuthenticationData } from '@whook/authorization';
|
|
4
|
+
export declare const authCookieHeaderParameter: WhookAPIParameterDefinition<string>;
|
|
5
|
+
export declare const definition: WhookAPIHandlerDefinition;
|
|
6
|
+
declare const _default: <AUTHENTICATION_DATA extends BaseAuthenticationData<string, string> = BaseAuthenticationData<string, string>>(dependencies?: AuthHandlersConfig<AUTHENTICATION_DATA> & {
|
|
7
|
+
authCookies: AuthCookiesService;
|
|
8
|
+
postOAuth2Token: (parameters: {
|
|
9
|
+
body: {
|
|
10
|
+
[name: string]: unknown;
|
|
11
|
+
grant_type: string;
|
|
12
|
+
};
|
|
13
|
+
authenticationData: BaseAuthenticationData<string, string>;
|
|
14
|
+
}) => Promise<{
|
|
15
|
+
status: number;
|
|
16
|
+
headers: {};
|
|
17
|
+
body: {
|
|
18
|
+
access_token: string;
|
|
19
|
+
token_type: string;
|
|
20
|
+
expires_in: number;
|
|
21
|
+
expiration_date: string;
|
|
22
|
+
refresh_token: string;
|
|
23
|
+
refresh_token_expires_in: number;
|
|
24
|
+
refresh_token_expiration_date: string;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
27
|
+
}) => Promise<(parameters: {
|
|
28
|
+
body: {
|
|
29
|
+
scope: string;
|
|
30
|
+
remember: boolean;
|
|
31
|
+
};
|
|
32
|
+
cookie?: string;
|
|
33
|
+
}) => Promise<{
|
|
34
|
+
headers: {
|
|
35
|
+
'Set-Cookie': string[];
|
|
36
|
+
};
|
|
37
|
+
body: {
|
|
38
|
+
access_token: string;
|
|
39
|
+
expiration_date: string;
|
|
40
|
+
expires_in: number;
|
|
41
|
+
token_type: string;
|
|
42
|
+
};
|
|
43
|
+
status: number;
|
|
44
|
+
}>>;
|
|
45
|
+
export default _default;
|