@payloadcms/figma 0.0.1-alpha.1 → 0.0.1-alpha.11
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/dist/api/control-plane.d.ts.map +1 -1
- package/dist/api/control-plane.js +11 -16
- package/dist/api/control-plane.js.map +1 -1
- package/dist/api/figma-api.js +3 -3
- package/dist/api/figma-api.js.map +1 -1
- package/dist/auth/jwt-validator.js.map +1 -1
- package/dist/auth/oauth-flow.d.ts.map +1 -1
- package/dist/auth/oauth-flow.js +3 -6
- package/dist/auth/oauth-flow.js.map +1 -1
- package/dist/auth/project-token.d.ts.map +1 -1
- package/dist/auth/project-token.js +1 -4
- package/dist/auth/project-token.js.map +1 -1
- package/dist/auth/refresh.d.ts.map +1 -1
- package/dist/auth/refresh.js +19 -28
- package/dist/auth/refresh.js.map +1 -1
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/cli.js +1 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +17 -10
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/init.d.ts +4 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +21 -85
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list-tokens.d.ts +1 -1
- package/dist/commands/list-tokens.d.ts.map +1 -1
- package/dist/commands/list-tokens.js +6 -5
- package/dist/commands/list-tokens.js.map +1 -1
- package/dist/commands/login.d.ts +2 -11
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +4 -7
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.d.ts +1 -1
- package/dist/commands/logout.js +1 -1
- package/dist/commands/logout.js.map +1 -1
- package/dist/db-adapter.d.ts +17 -0
- package/dist/db-adapter.d.ts.map +1 -0
- package/dist/db-adapter.js +757 -0
- package/dist/db-adapter.js.map +1 -0
- package/dist/endpoints/health.d.ts +3 -0
- package/dist/endpoints/health.d.ts.map +1 -0
- package/dist/endpoints/health.js +11 -0
- package/dist/endpoints/health.js.map +1 -0
- package/dist/exports/client.d.ts +3 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/oauth/components/LoginButton/index.d.ts +9 -0
- package/dist/oauth/components/LoginButton/index.d.ts.map +1 -0
- package/dist/oauth/components/LoginButton/index.js +52 -0
- package/dist/oauth/components/LoginButton/index.js.map +1 -0
- package/dist/oauth/components/LoginButton/index.scss +10 -0
- package/dist/oauth/components/LogoutButton/index.d.ts +7 -0
- package/dist/oauth/components/LogoutButton/index.d.ts.map +1 -0
- package/dist/oauth/components/LogoutButton/index.js +67 -0
- package/dist/oauth/components/LogoutButton/index.js.map +1 -0
- package/dist/oauth/components/LogoutButton/index.scss +10 -0
- package/dist/oauth/defaults.d.ts +10 -0
- package/dist/oauth/defaults.d.ts.map +1 -0
- package/dist/oauth/defaults.js +91 -0
- package/dist/oauth/defaults.js.map +1 -0
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getLoginEndpoint.js +237 -0
- package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts +12 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.js +99 -0
- package/dist/oauth/endpoints/getLogoutEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getMetaEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getMetaEndpoint.js +25 -0
- package/dist/oauth/endpoints/getMetaEndpoint.js.map +1 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts +13 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts.map +1 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js +21 -0
- package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js.map +1 -0
- package/dist/oauth/exports/client.d.ts +3 -0
- package/dist/oauth/exports/client.d.ts.map +1 -0
- package/dist/oauth/exports/client.js +4 -0
- package/dist/oauth/exports/client.js.map +1 -0
- package/dist/oauth/hooks/afterLogout.d.ts +8 -0
- package/dist/oauth/hooks/afterLogout.d.ts.map +1 -0
- package/dist/oauth/hooks/afterLogout.js +27 -0
- package/dist/oauth/hooks/afterLogout.js.map +1 -0
- package/dist/oauth/hooks/me.d.ts +5 -0
- package/dist/oauth/hooks/me.d.ts.map +1 -0
- package/dist/oauth/hooks/me.js +55 -0
- package/dist/oauth/hooks/me.js.map +1 -0
- package/dist/oauth/hooks/refresh.d.ts +8 -0
- package/dist/oauth/hooks/refresh.d.ts.map +1 -0
- package/dist/oauth/hooks/refresh.js +91 -0
- package/dist/oauth/hooks/refresh.js.map +1 -0
- package/dist/oauth/index.d.ts +4 -0
- package/dist/oauth/index.d.ts.map +1 -0
- package/dist/oauth/index.js +222 -0
- package/dist/oauth/index.js.map +1 -0
- package/dist/oauth/strategy/index.d.ts +54 -0
- package/dist/oauth/strategy/index.d.ts.map +1 -0
- package/dist/oauth/strategy/index.js +280 -0
- package/dist/oauth/strategy/index.js.map +1 -0
- package/dist/oauth/types.d.ts +192 -0
- package/dist/oauth/types.d.ts.map +1 -0
- package/dist/oauth/types.js +3 -0
- package/dist/oauth/types.js.map +1 -0
- package/dist/oauth/utilities/clearCookie.d.ts +9 -0
- package/dist/oauth/utilities/clearCookie.d.ts.map +1 -0
- package/dist/oauth/utilities/clearCookie.js +21 -0
- package/dist/oauth/utilities/clearCookie.js.map +1 -0
- package/dist/oauth/utilities/createCookieOptions.d.ts +10 -0
- package/dist/oauth/utilities/createCookieOptions.d.ts.map +1 -0
- package/dist/oauth/utilities/createCookieOptions.js +42 -0
- package/dist/oauth/utilities/createCookieOptions.js.map +1 -0
- package/dist/oauth/utilities/createDebugLogger.d.ts +4 -0
- package/dist/oauth/utilities/createDebugLogger.d.ts.map +1 -0
- package/dist/oauth/utilities/createDebugLogger.js +16 -0
- package/dist/oauth/utilities/createDebugLogger.js.map +1 -0
- package/dist/oauth/utilities/extractOrigin.d.ts +2 -0
- package/dist/oauth/utilities/extractOrigin.d.ts.map +1 -0
- package/dist/oauth/utilities/extractOrigin.js +12 -0
- package/dist/oauth/utilities/extractOrigin.js.map +1 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +3 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.d.ts.map +1 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.js +18 -0
- package/dist/oauth/utilities/getAdminCollectionSlug.js.map +1 -0
- package/dist/oauth/utilities/getAdminPath.d.ts +8 -0
- package/dist/oauth/utilities/getAdminPath.d.ts.map +1 -0
- package/dist/oauth/utilities/getAdminPath.js +9 -0
- package/dist/oauth/utilities/getAdminPath.js.map +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.d.ts +17 -0
- package/dist/oauth/utilities/getAuthorizeURL.d.ts.map +1 -0
- package/dist/oauth/utilities/getAuthorizeURL.js +45 -0
- package/dist/oauth/utilities/getAuthorizeURL.js.map +1 -0
- package/dist/oauth/utilities/getCookieExpiration.d.ts +4 -0
- package/dist/oauth/utilities/getCookieExpiration.d.ts.map +1 -0
- package/dist/oauth/utilities/getCookieExpiration.js +11 -0
- package/dist/oauth/utilities/getCookieExpiration.js.map +1 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts +2 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts.map +1 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.js +7 -0
- package/dist/oauth/utilities/getSecondsFromTokenExp.js.map +1 -0
- package/dist/oauth/utilities/getTokenExp.d.ts +6 -0
- package/dist/oauth/utilities/getTokenExp.d.ts.map +1 -0
- package/dist/oauth/utilities/getTokenExp.js +20 -0
- package/dist/oauth/utilities/getTokenExp.js.map +1 -0
- package/dist/oauth/utilities/getUsernameField.d.ts +9 -0
- package/dist/oauth/utilities/getUsernameField.d.ts.map +1 -0
- package/dist/oauth/utilities/getUsernameField.js +20 -0
- package/dist/oauth/utilities/getUsernameField.js.map +1 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts +8 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts.map +1 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js +25 -0
- package/dist/oauth/utilities/hasUserTokenPropsChanged.js.map +1 -0
- package/dist/oauth/utilities/mergeHeaders.d.ts +2 -0
- package/dist/oauth/utilities/mergeHeaders.d.ts.map +1 -0
- package/dist/oauth/utilities/mergeHeaders.js +37 -0
- package/dist/oauth/utilities/mergeHeaders.js.map +1 -0
- package/dist/oauth/utilities/refreshTokens.d.ts +16 -0
- package/dist/oauth/utilities/refreshTokens.d.ts.map +1 -0
- package/dist/oauth/utilities/refreshTokens.js +67 -0
- package/dist/oauth/utilities/refreshTokens.js.map +1 -0
- package/dist/plugin/build-config.d.ts +7 -1
- package/dist/plugin/build-config.d.ts.map +1 -1
- package/dist/plugin/build-config.js +53 -3
- package/dist/plugin/build-config.js.map +1 -1
- package/dist/types/config.d.ts +0 -11
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +1 -1
- package/dist/types/config.js.map +1 -1
- package/dist/utils/config.d.ts +0 -22
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +0 -46
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/messages.js +11 -11
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/payload-config-ast.d.ts +17 -1
- package/dist/utils/payload-config-ast.d.ts.map +1 -1
- package/dist/utils/payload-config-ast.js +166 -14
- package/dist/utils/payload-config-ast.js.map +1 -1
- package/dist/utils/payload-config-modifier.d.ts +2 -1
- package/dist/utils/payload-config-modifier.d.ts.map +1 -1
- package/dist/utils/payload-config-modifier.js +50 -79
- package/dist/utils/payload-config-modifier.js.map +1 -1
- package/dist/utils/payload-package-check.d.ts.map +1 -1
- package/dist/utils/payload-package-check.js +14 -33
- package/dist/utils/payload-package-check.js.map +1 -1
- package/dist/utils/project.d.ts +1 -1
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +3 -5
- package/dist/utils/project.js.map +1 -1
- package/dist/utils/s3-upload.d.ts.map +1 -1
- package/dist/utils/s3-upload.js +3 -8
- package/dist/utils/s3-upload.js.map +1 -1
- package/dist/utils/token-display.d.ts.map +1 -1
- package/dist/utils/token-display.js +3 -2
- package/dist/utils/token-display.js.map +1 -1
- package/package.json +9 -3
- package/dist/api/control-plane.spec.d.ts +0 -2
- package/dist/api/control-plane.spec.d.ts.map +0 -1
- package/dist/api/control-plane.spec.js +0 -296
- package/dist/api/control-plane.spec.js.map +0 -1
- package/dist/api/figma-api.spec.d.ts +0 -14
- package/dist/api/figma-api.spec.d.ts.map +0 -1
- package/dist/api/figma-api.spec.js +0 -201
- package/dist/api/figma-api.spec.js.map +0 -1
- package/dist/auth/__tests__/fixtures.d.ts +0 -26
- package/dist/auth/__tests__/fixtures.d.ts.map +0 -1
- package/dist/auth/__tests__/fixtures.js +0 -67
- package/dist/auth/__tests__/fixtures.js.map +0 -1
- package/dist/auth/__tests__/mocks.d.ts +0 -33
- package/dist/auth/__tests__/mocks.d.ts.map +0 -1
- package/dist/auth/__tests__/mocks.js +0 -63
- package/dist/auth/__tests__/mocks.js.map +0 -1
- package/dist/auth/callback-server.spec.d.ts +0 -2
- package/dist/auth/callback-server.spec.d.ts.map +0 -1
- package/dist/auth/callback-server.spec.js +0 -85
- package/dist/auth/callback-server.spec.js.map +0 -1
- package/dist/auth/crypto-utils.spec.d.ts +0 -2
- package/dist/auth/crypto-utils.spec.d.ts.map +0 -1
- package/dist/auth/crypto-utils.spec.js +0 -36
- package/dist/auth/crypto-utils.spec.js.map +0 -1
- package/dist/auth/jwt-validator.spec.d.ts +0 -10
- package/dist/auth/jwt-validator.spec.d.ts.map +0 -1
- package/dist/auth/jwt-validator.spec.js +0 -236
- package/dist/auth/jwt-validator.spec.js.map +0 -1
- package/dist/auth/oauth-flow.spec.d.ts +0 -2
- package/dist/auth/oauth-flow.spec.d.ts.map +0 -1
- package/dist/auth/oauth-flow.spec.js +0 -134
- package/dist/auth/oauth-flow.spec.js.map +0 -1
- package/dist/auth/pkce.spec.d.ts +0 -2
- package/dist/auth/pkce.spec.d.ts.map +0 -1
- package/dist/auth/pkce.spec.js +0 -32
- package/dist/auth/pkce.spec.js.map +0 -1
- package/dist/auth/project-token.spec.d.ts +0 -2
- package/dist/auth/project-token.spec.d.ts.map +0 -1
- package/dist/auth/project-token.spec.js +0 -332
- package/dist/auth/project-token.spec.js.map +0 -1
- package/dist/auth/refresh.spec.d.ts +0 -2
- package/dist/auth/refresh.spec.d.ts.map +0 -1
- package/dist/auth/refresh.spec.js +0 -105
- package/dist/auth/refresh.spec.js.map +0 -1
- package/dist/auth/token-store.spec.d.ts +0 -2
- package/dist/auth/token-store.spec.d.ts.map +0 -1
- package/dist/auth/token-store.spec.js +0 -276
- package/dist/auth/token-store.spec.js.map +0 -1
- package/dist/commands/__tests__/test-utils.d.ts +0 -28
- package/dist/commands/__tests__/test-utils.d.ts.map +0 -1
- package/dist/commands/__tests__/test-utils.js +0 -34
- package/dist/commands/__tests__/test-utils.js.map +0 -1
- package/dist/commands/deploy.spec.d.ts +0 -2
- package/dist/commands/deploy.spec.d.ts.map +0 -1
- package/dist/commands/deploy.spec.js +0 -18
- package/dist/commands/deploy.spec.js.map +0 -1
- package/dist/commands/init.spec.d.ts +0 -2
- package/dist/commands/init.spec.d.ts.map +0 -1
- package/dist/commands/init.spec.js +0 -283
- package/dist/commands/init.spec.js.map +0 -1
- package/dist/plugin/build-config.spec.d.ts +0 -2
- package/dist/plugin/build-config.spec.d.ts.map +0 -1
- package/dist/plugin/build-config.spec.js +0 -72
- package/dist/plugin/build-config.spec.js.map +0 -1
- package/dist/utils/asset-collection.spec.d.ts +0 -2
- package/dist/utils/asset-collection.spec.d.ts.map +0 -1
- package/dist/utils/asset-collection.spec.js +0 -155
- package/dist/utils/asset-collection.spec.js.map +0 -1
- package/dist/utils/build-detection.spec.d.ts +0 -2
- package/dist/utils/build-detection.spec.d.ts.map +0 -1
- package/dist/utils/build-detection.spec.js +0 -110
- package/dist/utils/build-detection.spec.js.map +0 -1
- package/dist/utils/config.spec.d.ts +0 -2
- package/dist/utils/config.spec.d.ts.map +0 -1
- package/dist/utils/config.spec.js +0 -167
- package/dist/utils/config.spec.js.map +0 -1
- package/dist/utils/download-template.spec.d.ts +0 -2
- package/dist/utils/download-template.spec.d.ts.map +0 -1
- package/dist/utils/download-template.spec.js +0 -76
- package/dist/utils/download-template.spec.js.map +0 -1
- package/dist/utils/env-management.spec.d.ts +0 -2
- package/dist/utils/env-management.spec.d.ts.map +0 -1
- package/dist/utils/env-management.spec.js +0 -123
- package/dist/utils/env-management.spec.js.map +0 -1
- package/dist/utils/git.spec.d.ts +0 -2
- package/dist/utils/git.spec.d.ts.map +0 -1
- package/dist/utils/git.spec.js +0 -99
- package/dist/utils/git.spec.js.map +0 -1
- package/dist/utils/lambda-config.spec.d.ts +0 -2
- package/dist/utils/lambda-config.spec.d.ts.map +0 -1
- package/dist/utils/lambda-config.spec.js +0 -141
- package/dist/utils/lambda-config.spec.js.map +0 -1
- package/dist/utils/payload-config-ast.spec.d.ts +0 -2
- package/dist/utils/payload-config-ast.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-ast.spec.js +0 -303
- package/dist/utils/payload-config-ast.spec.js.map +0 -1
- package/dist/utils/payload-config-modifier.int.spec.d.ts +0 -2
- package/dist/utils/payload-config-modifier.int.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.int.spec.js +0 -116
- package/dist/utils/payload-config-modifier.int.spec.js.map +0 -1
- package/dist/utils/payload-config-modifier.spec.d.ts +0 -2
- package/dist/utils/payload-config-modifier.spec.d.ts.map +0 -1
- package/dist/utils/payload-config-modifier.spec.js +0 -162
- package/dist/utils/payload-config-modifier.spec.js.map +0 -1
- package/dist/utils/payload-package-check.spec.d.ts +0 -2
- package/dist/utils/payload-package-check.spec.d.ts.map +0 -1
- package/dist/utils/payload-package-check.spec.js +0 -148
- package/dist/utils/payload-package-check.spec.js.map +0 -1
- package/dist/utils/project.spec.d.ts +0 -2
- package/dist/utils/project.spec.d.ts.map +0 -1
- package/dist/utils/project.spec.js +0 -222
- package/dist/utils/project.spec.js.map +0 -1
- package/dist/utils/s3-upload.spec.d.ts +0 -2
- package/dist/utils/s3-upload.spec.d.ts.map +0 -1
- package/dist/utils/s3-upload.spec.js +0 -140
- package/dist/utils/s3-upload.spec.js.map +0 -1
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { APIError, generateCookie, parseCookies } from 'payload';
|
|
2
|
+
import { getSafeRedirect } from 'payload/shared';
|
|
3
|
+
import { getProjectToken } from '../../api/figma-api.js';
|
|
4
|
+
import { createCookieOptions } from '../utilities/createCookieOptions.js';
|
|
5
|
+
import { createDebugLogger } from '../utilities/createDebugLogger.js';
|
|
6
|
+
import { extractOrigin } from '../utilities/extractOrigin.js';
|
|
7
|
+
import { getAdminPath } from '../utilities/getAdminPath.js';
|
|
8
|
+
import { getCookieExpiration } from '../utilities/getCookieExpiration.js';
|
|
9
|
+
const isAbsoluteURL = (url)=>/^[a-z][a-z\d+.-]*:/.test(url);
|
|
10
|
+
export const getLoginEndpoint = ({ collection, collectionOptions, endpointSlug, pluginOptions, strategy })=>({
|
|
11
|
+
handler: async (req)=>{
|
|
12
|
+
const { config } = req.payload;
|
|
13
|
+
const adminPath = getAdminPath(config);
|
|
14
|
+
try {
|
|
15
|
+
await strategy.ensureMeta();
|
|
16
|
+
const path = req.pathname;
|
|
17
|
+
const debugLogger = createDebugLogger(req.payload, pluginOptions.debug);
|
|
18
|
+
let jsonBody = {};
|
|
19
|
+
const contentType = req.headers.get('content-type');
|
|
20
|
+
// Type narrow PayloadRequst's Partial<Request>
|
|
21
|
+
if (typeof req.json !== 'function' || typeof req.formData !== 'function') {
|
|
22
|
+
debugLogger.info({
|
|
23
|
+
msg: 'Request does not have json or formData methods',
|
|
24
|
+
path
|
|
25
|
+
});
|
|
26
|
+
return Response.redirect(`${pluginOptions.redirectServerURL || config.serverURL}/login`);
|
|
27
|
+
}
|
|
28
|
+
if (collectionOptions.authorizationURLParams?.response_mode === 'query') {
|
|
29
|
+
if (Object.keys(req.query).length > 0) {
|
|
30
|
+
jsonBody = req.query;
|
|
31
|
+
}
|
|
32
|
+
} else if (contentType === 'application/json') {
|
|
33
|
+
jsonBody = await req.json();
|
|
34
|
+
} else if (contentType === 'application/x-www-form-urlencoded') {
|
|
35
|
+
const formData = await req.formData();
|
|
36
|
+
jsonBody = Object.fromEntries(formData.entries());
|
|
37
|
+
}
|
|
38
|
+
const stateRaw = jsonBody.state;
|
|
39
|
+
const state = JSON.parse(Buffer.from(stateRaw, 'base64').toString('utf-8'));
|
|
40
|
+
const redirectDestination = state.serverURL || pluginOptions.redirectServerURL || config.serverURL;
|
|
41
|
+
let failedRedirect = `${redirectDestination}${adminPath}/login`;
|
|
42
|
+
let redirectToUse = `${redirectDestination}${adminPath}`;
|
|
43
|
+
if (state.redirect) {
|
|
44
|
+
redirectToUse = state.redirect;
|
|
45
|
+
}
|
|
46
|
+
if (state.failedRedirect) {
|
|
47
|
+
failedRedirect = state.failedRedirect;
|
|
48
|
+
}
|
|
49
|
+
failedRedirect = getSafeRedirect({
|
|
50
|
+
allowAbsoluteUrls: true,
|
|
51
|
+
redirectTo: failedRedirect
|
|
52
|
+
});
|
|
53
|
+
redirectToUse = getSafeRedirect({
|
|
54
|
+
allowAbsoluteUrls: true,
|
|
55
|
+
redirectTo: redirectToUse
|
|
56
|
+
});
|
|
57
|
+
if (!isAbsoluteURL(failedRedirect)) {
|
|
58
|
+
return Response.json({
|
|
59
|
+
error: 'Invalid failed redirect provided'
|
|
60
|
+
}, {
|
|
61
|
+
status: 403
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (!isAbsoluteURL(redirectToUse)) {
|
|
65
|
+
return Response.json({
|
|
66
|
+
error: 'Invalid redirect provided'
|
|
67
|
+
}, {
|
|
68
|
+
status: 403
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (Array.isArray(req.payload.config.csrf) && req.payload.config.csrf.length > 0) {
|
|
72
|
+
const failedRedirectOrigin = extractOrigin(failedRedirect);
|
|
73
|
+
const redirectToUseOrigin = extractOrigin(redirectToUse);
|
|
74
|
+
if (failedRedirectOrigin && !req.payload.config.csrf.includes(failedRedirectOrigin)) {
|
|
75
|
+
req.payload.logger.error(`Failed redirect origin ${failedRedirectOrigin} is not allowed by CSRF configuration.`);
|
|
76
|
+
return Response.json({
|
|
77
|
+
error: 'Failed redirect origin is not allowed by CSRF configuration.'
|
|
78
|
+
}, {
|
|
79
|
+
status: 403
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (redirectToUseOrigin && !req.payload.config.csrf.includes(redirectToUseOrigin)) {
|
|
83
|
+
req.payload.logger.error(`Redirect origin ${redirectToUseOrigin} is not allowed by CSRF configuration.`);
|
|
84
|
+
return Response.json({
|
|
85
|
+
error: 'Redirect origin is not allowed by CSRF configuration.'
|
|
86
|
+
}, {
|
|
87
|
+
status: 403
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Verify signature
|
|
92
|
+
if (strategy.name !== req.payload.decrypt(state.sig)) {
|
|
93
|
+
req.payload.logger.error('Signature mismatch. Failing login and redirecting.');
|
|
94
|
+
return Response.redirect(failedRedirect);
|
|
95
|
+
}
|
|
96
|
+
if (!strategy.meta?.token_endpoint) {
|
|
97
|
+
debugLogger.error({
|
|
98
|
+
msg: `No metadata was obtained from the identity provider. Failing login and redirecting.`,
|
|
99
|
+
path
|
|
100
|
+
});
|
|
101
|
+
return Response.redirect(failedRedirect);
|
|
102
|
+
}
|
|
103
|
+
debugLogger.info({
|
|
104
|
+
body: jsonBody,
|
|
105
|
+
msg: 'Received login response body',
|
|
106
|
+
path
|
|
107
|
+
});
|
|
108
|
+
if (!jsonBody?.code) {
|
|
109
|
+
debugLogger.error({
|
|
110
|
+
msg: `No authorization code present in body. Failing login and redirecting.`,
|
|
111
|
+
path
|
|
112
|
+
});
|
|
113
|
+
return Response.redirect(failedRedirect);
|
|
114
|
+
}
|
|
115
|
+
// Exchange `code` from body for refresh token
|
|
116
|
+
const { code } = jsonBody;
|
|
117
|
+
if (typeof code !== 'string') {
|
|
118
|
+
debugLogger.error({
|
|
119
|
+
msg: `Authorization code present in body is not a string. Failing login and redirecting.`,
|
|
120
|
+
path
|
|
121
|
+
});
|
|
122
|
+
return Response.redirect(failedRedirect);
|
|
123
|
+
}
|
|
124
|
+
const body = {
|
|
125
|
+
client_id: strategy.clientID,
|
|
126
|
+
code,
|
|
127
|
+
code_verifier: req.payload.decrypt(state.verifier),
|
|
128
|
+
grant_type: 'authorization_code',
|
|
129
|
+
redirect_uri: `${redirectDestination}${config?.routes?.api || '/api'}/${collection.slug}/${endpointSlug}/login`
|
|
130
|
+
};
|
|
131
|
+
debugLogger.info({
|
|
132
|
+
msg: 'Exchanging code for access token',
|
|
133
|
+
path,
|
|
134
|
+
requestBody: body
|
|
135
|
+
});
|
|
136
|
+
if (strategy.clientSecret) {
|
|
137
|
+
body.client_secret = strategy.clientSecret;
|
|
138
|
+
}
|
|
139
|
+
const tokenRes = await fetch(strategy.meta?.token_endpoint, {
|
|
140
|
+
body: new URLSearchParams(body),
|
|
141
|
+
headers: {
|
|
142
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
143
|
+
},
|
|
144
|
+
method: 'POST'
|
|
145
|
+
}).then((r)=>r.json());
|
|
146
|
+
debugLogger.info({
|
|
147
|
+
msg: 'Token Response',
|
|
148
|
+
path,
|
|
149
|
+
tokenRes
|
|
150
|
+
});
|
|
151
|
+
const { access_token, error, error_description, expires_in: refreshTokenExpires } = tokenRes;
|
|
152
|
+
debugLogger.info({
|
|
153
|
+
msg: 'tokenResss',
|
|
154
|
+
tokenRes
|
|
155
|
+
});
|
|
156
|
+
// Swap for project token
|
|
157
|
+
const project_token = await getProjectToken(tokenRes.access_token, config.custom.figma.tenantId);
|
|
158
|
+
const refresh_token = access_token;
|
|
159
|
+
// Store project token as access_token
|
|
160
|
+
const token = project_token.token;
|
|
161
|
+
const expiresIn = project_token.expiresAt;
|
|
162
|
+
if (!token) {
|
|
163
|
+
const errMsg = `No ${collectionOptions.token || 'access_token'} was returned from the identity provider.`;
|
|
164
|
+
req.payload.logger.error({
|
|
165
|
+
msg: errMsg,
|
|
166
|
+
path
|
|
167
|
+
});
|
|
168
|
+
throw new APIError(errMsg);
|
|
169
|
+
}
|
|
170
|
+
const cookieOptions = createCookieOptions({
|
|
171
|
+
collection,
|
|
172
|
+
headers: req.headers,
|
|
173
|
+
pluginOptions
|
|
174
|
+
});
|
|
175
|
+
if (error) {
|
|
176
|
+
req.payload.logger.error('Error swapping access code with access token:');
|
|
177
|
+
req.payload.logger.error({
|
|
178
|
+
err: error,
|
|
179
|
+
error_description
|
|
180
|
+
});
|
|
181
|
+
return Response.redirect(failedRedirect);
|
|
182
|
+
}
|
|
183
|
+
// get the payloadRedirect cookie value
|
|
184
|
+
const cookies = parseCookies(req.headers);
|
|
185
|
+
const payloadRedirect = 'payloadRedirect' in cookies ? cookies.payloadRedirect : '';
|
|
186
|
+
if (!req.responseHeaders) {
|
|
187
|
+
req.responseHeaders = new Headers();
|
|
188
|
+
}
|
|
189
|
+
if (payloadRedirect) {
|
|
190
|
+
if (isAbsoluteURL(payloadRedirect)) {
|
|
191
|
+
redirectToUse = payloadRedirect;
|
|
192
|
+
} else {
|
|
193
|
+
redirectToUse += payloadRedirect;
|
|
194
|
+
}
|
|
195
|
+
req.responseHeaders.append('Set-Cookie', `payloadRedirect=${redirectToUse}; Max-Age=0; Path=/;`);
|
|
196
|
+
}
|
|
197
|
+
if (refresh_token && !collectionOptions.usePayloadJWT) {
|
|
198
|
+
debugLogger.info('Setting refresh token cookie');
|
|
199
|
+
const refreshCookie = generateCookie({
|
|
200
|
+
returnCookieAsObject: false,
|
|
201
|
+
...cookieOptions,
|
|
202
|
+
name: `${strategy.cookieName}-refresh`,
|
|
203
|
+
value: refresh_token,
|
|
204
|
+
// Default to 1 year if no expiration
|
|
205
|
+
expires: getCookieExpiration(cookieOptions?.expires ?? refreshTokenExpires ?? 31_556_952)
|
|
206
|
+
});
|
|
207
|
+
req.responseHeaders.append('Set-Cookie', refreshCookie);
|
|
208
|
+
}
|
|
209
|
+
const tokenExpires = cookieOptions?.expires ? getCookieExpiration(cookieOptions.expires) : new Date(expiresIn) // Project token uses epoch time
|
|
210
|
+
;
|
|
211
|
+
const tokenCookie = generateCookie({
|
|
212
|
+
...cookieOptions,
|
|
213
|
+
name: strategy.cookieName,
|
|
214
|
+
expires: tokenExpires,
|
|
215
|
+
returnCookieAsObject: false,
|
|
216
|
+
value: token
|
|
217
|
+
});
|
|
218
|
+
req.responseHeaders.append('Set-Cookie', tokenCookie);
|
|
219
|
+
return Response.redirect(redirectToUse);
|
|
220
|
+
} catch (err) {
|
|
221
|
+
req.payload.logger.error({
|
|
222
|
+
err,
|
|
223
|
+
msg: 'Error while attempting to login',
|
|
224
|
+
path: req.pathname
|
|
225
|
+
});
|
|
226
|
+
return Response.json({
|
|
227
|
+
error: 'Error while attempting to login'
|
|
228
|
+
}, {
|
|
229
|
+
status: 500
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
method: collectionOptions.authorizationURLParams?.response_mode === 'query' ? 'get' : 'post',
|
|
234
|
+
path: `/${endpointSlug}/login`
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
//# sourceMappingURL=getLoginEndpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/oauth/endpoints/getLoginEndpoint.ts"],"sourcesContent":["import type { CollectionConfig, Endpoint } from 'payload'\n\nimport jwt from 'jsonwebtoken'\nimport { APIError, generateCookie, parseCookies } from 'payload'\nimport { getSafeRedirect } from 'payload/shared'\n\nimport type { Strategy } from '../strategy/index.js'\nimport type {\n AfterOAuthLoginHookResult,\n CollectionOptions,\n PluginOptions,\n StateObj,\n} from '../types.js'\n\nimport { getProjectToken } from '../../api/figma-api.js'\nimport { JWTValidationError, validateProjectToken } from '../../auth/jwt-validator.js'\nimport { ProjectTokenError } from '../../auth/project-token.js'\nimport { getEnvironment } from '../../constants.js'\nimport { createCookieOptions } from '../utilities/createCookieOptions.js'\nimport { createDebugLogger } from '../utilities/createDebugLogger.js'\nimport { extractOrigin } from '../utilities/extractOrigin.js'\nimport { getAdminPath } from '../utilities/getAdminPath.js'\nimport { getCookieExpiration } from '../utilities/getCookieExpiration.js'\nimport { getSecondsFromTokenExp } from '../utilities/getSecondsFromTokenExp.js'\nimport { getTokenExp } from '../utilities/getTokenExp.js'\n\ninterface Args {\n collection: CollectionConfig\n collectionOptions: CollectionOptions\n endpointSlug: string\n pluginOptions: PluginOptions\n strategy: Strategy\n}\n\nconst isAbsoluteURL = (url: string) => /^[a-z][a-z\\d+.-]*:/.test(url)\n\nexport const getLoginEndpoint = ({\n collection,\n collectionOptions,\n endpointSlug,\n pluginOptions,\n strategy,\n}: Args): Endpoint => ({\n handler: async (req) => {\n const { config } = req.payload\n const adminPath = getAdminPath(config)\n try {\n await strategy.ensureMeta()\n\n const path = req.pathname\n const debugLogger = createDebugLogger(req.payload, pluginOptions.debug)\n\n let jsonBody: Record<string, unknown> = {}\n\n const contentType = req.headers.get('content-type')\n\n // Type narrow PayloadRequst's Partial<Request>\n if (typeof req.json !== 'function' || typeof req.formData !== 'function') {\n debugLogger.info({\n msg: 'Request does not have json or formData methods',\n path,\n })\n\n return Response.redirect(`${pluginOptions.redirectServerURL || config.serverURL}/login`)\n }\n\n if (collectionOptions.authorizationURLParams?.response_mode === 'query') {\n if (Object.keys(req.query).length > 0) {\n jsonBody = req.query\n }\n } else if (contentType === 'application/json') {\n jsonBody = await req.json()\n } else if (contentType === 'application/x-www-form-urlencoded') {\n const formData = await req.formData()\n jsonBody = Object.fromEntries(formData.entries())\n }\n\n const stateRaw = jsonBody.state as string\n const state: StateObj = JSON.parse(Buffer.from(stateRaw, 'base64').toString('utf-8'))\n\n const redirectDestination =\n state.serverURL || pluginOptions.redirectServerURL || config.serverURL\n let failedRedirect = `${redirectDestination}${adminPath}/login`\n let redirectToUse = `${redirectDestination}${adminPath}`\n\n if (state.redirect) {\n redirectToUse = state.redirect\n }\n\n if (state.failedRedirect) {\n failedRedirect = state.failedRedirect\n }\n\n failedRedirect = getSafeRedirect({ allowAbsoluteUrls: true, redirectTo: failedRedirect })\n redirectToUse = getSafeRedirect({ allowAbsoluteUrls: true, redirectTo: redirectToUse })\n\n if (!isAbsoluteURL(failedRedirect)) {\n return Response.json({ error: 'Invalid failed redirect provided' }, { status: 403 })\n }\n if (!isAbsoluteURL(redirectToUse)) {\n return Response.json({ error: 'Invalid redirect provided' }, { status: 403 })\n }\n\n if (Array.isArray(req.payload.config.csrf) && req.payload.config.csrf.length > 0) {\n const failedRedirectOrigin = extractOrigin(failedRedirect)\n const redirectToUseOrigin = extractOrigin(redirectToUse)\n\n if (failedRedirectOrigin && !req.payload.config.csrf.includes(failedRedirectOrigin)) {\n req.payload.logger.error(\n `Failed redirect origin ${failedRedirectOrigin} is not allowed by CSRF configuration.`,\n )\n return Response.json(\n { error: 'Failed redirect origin is not allowed by CSRF configuration.' },\n { status: 403 },\n )\n }\n\n if (redirectToUseOrigin && !req.payload.config.csrf.includes(redirectToUseOrigin)) {\n req.payload.logger.error(\n `Redirect origin ${redirectToUseOrigin} is not allowed by CSRF configuration.`,\n )\n return Response.json(\n { error: 'Redirect origin is not allowed by CSRF configuration.' },\n { status: 403 },\n )\n }\n }\n\n // Verify signature\n if (strategy.name !== req.payload.decrypt(state.sig)) {\n req.payload.logger.error('Signature mismatch. Failing login and redirecting.')\n return Response.redirect(failedRedirect)\n }\n\n if (!strategy.meta?.token_endpoint) {\n debugLogger.error({\n msg: `No metadata was obtained from the identity provider. Failing login and redirecting.`,\n path,\n })\n return Response.redirect(failedRedirect)\n }\n\n debugLogger.info({ body: jsonBody, msg: 'Received login response body', path })\n\n if (!jsonBody?.code) {\n debugLogger.error({\n msg: `No authorization code present in body. Failing login and redirecting.`,\n path,\n })\n return Response.redirect(failedRedirect)\n }\n\n // Exchange `code` from body for refresh token\n const { code } = jsonBody\n\n if (typeof code !== 'string') {\n debugLogger.error({\n msg: `Authorization code present in body is not a string. Failing login and redirecting.`,\n path,\n })\n return Response.redirect(failedRedirect)\n }\n\n const body: Record<string, string> = {\n client_id: strategy.clientID,\n code,\n code_verifier: req.payload.decrypt(state.verifier),\n grant_type: 'authorization_code',\n redirect_uri: `${redirectDestination}${config?.routes?.api || '/api'}/${\n collection.slug\n }/${endpointSlug}/login`,\n }\n\n debugLogger.info({\n msg: 'Exchanging code for access token',\n path,\n requestBody: body,\n })\n\n if (strategy.clientSecret) {\n body.client_secret = strategy.clientSecret\n }\n\n const tokenRes = await fetch(strategy.meta?.token_endpoint, {\n body: new URLSearchParams(body),\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n method: 'POST',\n }).then((r) => r.json())\n\n debugLogger.info({ msg: 'Token Response', path, tokenRes })\n\n const { access_token, error, error_description, expires_in: refreshTokenExpires } = tokenRes\n\n debugLogger.info({ msg: 'tokenResss', tokenRes })\n\n // Swap for project token\n const project_token = await getProjectToken(\n tokenRes.access_token,\n config.custom.figma.tenantId,\n )\n const refresh_token = access_token\n\n // Store project token as access_token\n\n const token = project_token.token\n const expiresIn = project_token.expiresAt\n\n if (!token) {\n const errMsg = `No ${\n collectionOptions.token || 'access_token'\n } was returned from the identity provider.`\n req.payload.logger.error({ msg: errMsg, path })\n throw new APIError(errMsg)\n }\n\n const cookieOptions = createCookieOptions({ collection, headers: req.headers, pluginOptions })\n\n if (error) {\n req.payload.logger.error('Error swapping access code with access token:')\n req.payload.logger.error({ err: error, error_description })\n return Response.redirect(failedRedirect)\n }\n\n // get the payloadRedirect cookie value\n const cookies = parseCookies(req.headers)\n\n const payloadRedirect =\n 'payloadRedirect' in cookies ? (cookies.payloadRedirect as string) : ''\n\n if (!req.responseHeaders) {\n req.responseHeaders = new Headers()\n }\n\n if (payloadRedirect) {\n if (isAbsoluteURL(payloadRedirect)) {\n redirectToUse = payloadRedirect\n } else {\n redirectToUse += payloadRedirect\n }\n\n req.responseHeaders.append(\n 'Set-Cookie',\n `payloadRedirect=${redirectToUse}; Max-Age=0; Path=/;`,\n )\n }\n\n if (refresh_token && !collectionOptions.usePayloadJWT) {\n debugLogger.info('Setting refresh token cookie')\n const refreshCookie = generateCookie({\n returnCookieAsObject: false,\n ...cookieOptions,\n name: `${strategy.cookieName}-refresh`,\n value: refresh_token,\n // Default to 1 year if no expiration\n expires: getCookieExpiration(cookieOptions?.expires ?? refreshTokenExpires ?? 31_556_952),\n }) as string\n\n req.responseHeaders.append('Set-Cookie', refreshCookie)\n }\n\n const tokenExpires = cookieOptions?.expires\n ? getCookieExpiration(cookieOptions.expires)\n : new Date(expiresIn) // Project token uses epoch time\n const tokenCookie = generateCookie({\n ...cookieOptions,\n name: strategy.cookieName,\n expires: tokenExpires,\n returnCookieAsObject: false,\n value: token,\n }) as string\n\n req.responseHeaders.append('Set-Cookie', tokenCookie)\n\n return Response.redirect(redirectToUse)\n } catch (err: unknown) {\n req.payload.logger.error({ err, msg: 'Error while attempting to login', path: req.pathname })\n\n return Response.json({ error: 'Error while attempting to login' }, { status: 500 })\n }\n },\n method: collectionOptions.authorizationURLParams?.response_mode === 'query' ? 'get' : 'post',\n path: `/${endpointSlug}/login`,\n})\n"],"names":["APIError","generateCookie","parseCookies","getSafeRedirect","getProjectToken","createCookieOptions","createDebugLogger","extractOrigin","getAdminPath","getCookieExpiration","isAbsoluteURL","url","test","getLoginEndpoint","collection","collectionOptions","endpointSlug","pluginOptions","strategy","handler","req","config","payload","adminPath","ensureMeta","path","pathname","debugLogger","debug","jsonBody","contentType","headers","get","json","formData","info","msg","Response","redirect","redirectServerURL","serverURL","authorizationURLParams","response_mode","Object","keys","query","length","fromEntries","entries","stateRaw","state","JSON","parse","Buffer","from","toString","redirectDestination","failedRedirect","redirectToUse","allowAbsoluteUrls","redirectTo","error","status","Array","isArray","csrf","failedRedirectOrigin","redirectToUseOrigin","includes","logger","name","decrypt","sig","meta","token_endpoint","body","code","client_id","clientID","code_verifier","verifier","grant_type","redirect_uri","routes","api","slug","requestBody","clientSecret","client_secret","tokenRes","fetch","URLSearchParams","method","then","r","access_token","error_description","expires_in","refreshTokenExpires","project_token","custom","figma","tenantId","refresh_token","token","expiresIn","expiresAt","errMsg","cookieOptions","err","cookies","payloadRedirect","responseHeaders","Headers","append","usePayloadJWT","refreshCookie","returnCookieAsObject","cookieName","value","expires","tokenExpires","Date","tokenCookie"],"mappings":"AAGA,SAASA,QAAQ,EAAEC,cAAc,EAAEC,YAAY,QAAQ,UAAS;AAChE,SAASC,eAAe,QAAQ,iBAAgB;AAUhD,SAASC,eAAe,QAAQ,yBAAwB;AAIxD,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,aAAa,QAAQ,gCAA+B;AAC7D,SAASC,YAAY,QAAQ,+BAA8B;AAC3D,SAASC,mBAAmB,QAAQ,sCAAqC;AAYzE,MAAMC,gBAAgB,CAACC,MAAgB,qBAAqBC,IAAI,CAACD;AAEjE,OAAO,MAAME,mBAAmB,CAAC,EAC/BC,UAAU,EACVC,iBAAiB,EACjBC,YAAY,EACZC,aAAa,EACbC,QAAQ,EACH,GAAgB,CAAA;QACrBC,SAAS,OAAOC;YACd,MAAM,EAAEC,MAAM,EAAE,GAAGD,IAAIE,OAAO;YAC9B,MAAMC,YAAYf,aAAaa;YAC/B,IAAI;gBACF,MAAMH,SAASM,UAAU;gBAEz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,CAAC;oBAAEgD;oBAAKzE,KAAK;oBAAmCX,MAAML,IAAIM,QAAQ;gBAAC;gBAE3F,OAAOW,SAASJ,IAAI,CAAC;oBAAE4B,OAAO;gBAAkC,GAAG;oBAAEC,QAAQ;gBAAI;YACnF;QACF;QACA8B,QAAQ7E,kBAAkB0B,sBAAsB,EAAEC,kBAAkB,UAAU,QAAQ;QACtFjB,MAAM,CAAC,CAAC,EAAET,aAAa,MAAM,CAAC;IAChC,CAAA,EAAE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CollectionConfig, Endpoint } from 'payload';
|
|
2
|
+
import type { Strategy } from '../strategy/index.js';
|
|
3
|
+
import type { PluginOptions } from '../types.js';
|
|
4
|
+
interface Args {
|
|
5
|
+
collection: CollectionConfig;
|
|
6
|
+
endpointSlug: string;
|
|
7
|
+
pluginOptions: PluginOptions;
|
|
8
|
+
strategy: Strategy;
|
|
9
|
+
}
|
|
10
|
+
export declare const getLogoutEndpoint: ({ collection, endpointSlug, pluginOptions, strategy, }: Args) => Endpoint;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=getLogoutEndpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLogoutEndpoint.d.ts","sourceRoot":"","sources":["../../../src/oauth/endpoints/getLogoutEndpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAKzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAOhD,UAAU,IAAI;IACZ,UAAU,EAAE,gBAAgB,CAAA;IAC5B,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,aAAa,CAAA;IAC5B,QAAQ,EAAE,QAAQ,CAAA;CACnB;AAED,eAAO,MAAM,iBAAiB,2DAK3B,IAAI,KAAG,QA4ER,CAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import jwt from 'jsonwebtoken';
|
|
2
|
+
import { parseCookies } from 'payload';
|
|
3
|
+
import { clearCookie } from '../utilities/clearCookie.js';
|
|
4
|
+
import { createCookieOptions } from '../utilities/createCookieOptions.js';
|
|
5
|
+
import { createDebugLogger } from '../utilities/createDebugLogger.js';
|
|
6
|
+
import { getAdminPath } from '../utilities/getAdminPath.js';
|
|
7
|
+
export const getLogoutEndpoint = ({ collection, endpointSlug, pluginOptions, strategy })=>({
|
|
8
|
+
handler: async (req)=>{
|
|
9
|
+
const debugLogger = createDebugLogger(req.payload, pluginOptions.debug);
|
|
10
|
+
const { config } = req.payload;
|
|
11
|
+
if (!req) {
|
|
12
|
+
debugLogger.error({
|
|
13
|
+
msg: 'Invalid request to logout endpoint'
|
|
14
|
+
});
|
|
15
|
+
return Response.json({
|
|
16
|
+
error: 'Invalid request to logout endpoint'
|
|
17
|
+
}, {
|
|
18
|
+
status: 400
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (!req.responseHeaders) {
|
|
22
|
+
req.responseHeaders = new Headers();
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
await strategy.ensureMeta();
|
|
26
|
+
const baseRedirectDestination = pluginOptions.redirectServerURL || config.serverURL;
|
|
27
|
+
let successfulLogoutRedirectDest = `${baseRedirectDestination}${getAdminPath(config)}`;
|
|
28
|
+
if (typeof req.query.redirect === 'string') {
|
|
29
|
+
successfulLogoutRedirectDest = req.query.redirect;
|
|
30
|
+
}
|
|
31
|
+
if (!baseRedirectDestination && !req.query.redirect) {
|
|
32
|
+
debugLogger.error({
|
|
33
|
+
msg: 'No redirect URL provided',
|
|
34
|
+
path: req.pathname
|
|
35
|
+
});
|
|
36
|
+
return Response.json({
|
|
37
|
+
error: 'No redirect URL provided'
|
|
38
|
+
}, {
|
|
39
|
+
status: 400
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const cookieOptions = createCookieOptions({
|
|
43
|
+
collection,
|
|
44
|
+
headers: req.headers,
|
|
45
|
+
pluginOptions
|
|
46
|
+
});
|
|
47
|
+
let redirectDestination = successfulLogoutRedirectDest;
|
|
48
|
+
if (strategy.meta?.end_session_endpoint) {
|
|
49
|
+
const cookies = parseCookies(req.headers);
|
|
50
|
+
const token = cookies.get(strategy.cookieName);
|
|
51
|
+
if (!token) {
|
|
52
|
+
debugLogger.error({
|
|
53
|
+
msg: 'Unable to parse token from cookie.'
|
|
54
|
+
});
|
|
55
|
+
return Response.json({
|
|
56
|
+
error: 'Unable to parse token from cookie.'
|
|
57
|
+
}, {
|
|
58
|
+
status: 400
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const decodedToken = jwt.decode(token);
|
|
62
|
+
const sid = typeof decodedToken === 'object' && decodedToken ? decodedToken.sid : undefined;
|
|
63
|
+
const body = {
|
|
64
|
+
client_id: strategy.clientID,
|
|
65
|
+
logout_hint: sid,
|
|
66
|
+
post_logout_redirect_uri: successfulLogoutRedirectDest
|
|
67
|
+
};
|
|
68
|
+
const qs = new URLSearchParams(body).toString();
|
|
69
|
+
redirectDestination = `${strategy.meta.end_session_endpoint}?${qs}`;
|
|
70
|
+
}
|
|
71
|
+
clearCookie({
|
|
72
|
+
cookieName: strategy.cookieName,
|
|
73
|
+
cookieOptions,
|
|
74
|
+
req
|
|
75
|
+
});
|
|
76
|
+
clearCookie({
|
|
77
|
+
cookieName: `${strategy.cookieName}-refresh`,
|
|
78
|
+
cookieOptions,
|
|
79
|
+
req
|
|
80
|
+
});
|
|
81
|
+
return Response.redirect(redirectDestination);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
req.payload.logger.error({
|
|
84
|
+
err,
|
|
85
|
+
msg: 'Error while attempting to logout',
|
|
86
|
+
path: req.pathname
|
|
87
|
+
});
|
|
88
|
+
return Response.json({
|
|
89
|
+
error: 'Error while attempting to logout'
|
|
90
|
+
}, {
|
|
91
|
+
status: 500
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
method: 'get',
|
|
96
|
+
path: `/${endpointSlug}/logout`
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=getLogoutEndpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/oauth/endpoints/getLogoutEndpoint.ts"],"sourcesContent":["import type { CollectionConfig, Endpoint } from 'payload'\n\nimport jwt from 'jsonwebtoken'\nimport { parseCookies } from 'payload'\n\nimport type { Strategy } from '../strategy/index.js'\nimport type { PluginOptions } from '../types.js'\n\nimport { clearCookie } from '../utilities/clearCookie.js'\nimport { createCookieOptions } from '../utilities/createCookieOptions.js'\nimport { createDebugLogger } from '../utilities/createDebugLogger.js'\nimport { getAdminPath } from '../utilities/getAdminPath.js'\n\ninterface Args {\n collection: CollectionConfig\n endpointSlug: string\n pluginOptions: PluginOptions\n strategy: Strategy\n}\n\nexport const getLogoutEndpoint = ({\n collection,\n endpointSlug,\n pluginOptions,\n strategy,\n}: Args): Endpoint => ({\n handler: async (req) => {\n const debugLogger = createDebugLogger(req.payload, pluginOptions.debug)\n const { config } = req.payload\n\n if (!req) {\n debugLogger.error({ msg: 'Invalid request to logout endpoint' })\n return Response.json({ error: 'Invalid request to logout endpoint' }, { status: 400 })\n }\n\n if (!req.responseHeaders) {\n req.responseHeaders = new Headers()\n }\n\n try {\n await strategy.ensureMeta()\n\n const baseRedirectDestination = pluginOptions.redirectServerURL || config.serverURL\n\n let successfulLogoutRedirectDest = `${baseRedirectDestination}${getAdminPath(config)}`\n\n if (typeof req.query.redirect === 'string') {\n successfulLogoutRedirectDest = req.query.redirect\n }\n\n if (!baseRedirectDestination && !req.query.redirect) {\n debugLogger.error({ msg: 'No redirect URL provided', path: req.pathname })\n return Response.json({ error: 'No redirect URL provided' }, { status: 400 })\n }\n\n const cookieOptions = createCookieOptions({ collection, headers: req.headers, pluginOptions })\n\n let redirectDestination = successfulLogoutRedirectDest\n if (strategy.meta?.end_session_endpoint) {\n const cookies = parseCookies(req.headers)\n\n const token = cookies.get(strategy.cookieName)\n if (!token) {\n debugLogger.error({ msg: 'Unable to parse token from cookie.' })\n return Response.json({ error: 'Unable to parse token from cookie.' }, { status: 400 })\n }\n\n const decodedToken = jwt.decode(token)\n const sid = typeof decodedToken === 'object' && decodedToken ? decodedToken.sid : undefined\n\n const body = {\n client_id: strategy.clientID,\n logout_hint: sid,\n post_logout_redirect_uri: successfulLogoutRedirectDest,\n }\n\n const qs = new URLSearchParams(body).toString()\n redirectDestination = `${strategy.meta.end_session_endpoint}?${qs}`\n }\n\n clearCookie({\n cookieName: strategy.cookieName,\n cookieOptions,\n req,\n })\n\n clearCookie({\n cookieName: `${strategy.cookieName}-refresh`,\n cookieOptions,\n req,\n })\n\n return Response.redirect(redirectDestination)\n } catch (err: unknown) {\n req.payload.logger.error({ err, msg: 'Error while attempting to logout', path: req.pathname })\n\n return Response.json({ error: 'Error while attempting to logout' }, { status: 500 })\n }\n },\n method: 'get',\n path: `/${endpointSlug}/logout`,\n})\n"],"names":["jwt","parseCookies","clearCookie","createCookieOptions","createDebugLogger","getAdminPath","getLogoutEndpoint","collection","endpointSlug","pluginOptions","strategy","handler","req","debugLogger","payload","debug","config","error","msg","Response","json","status","responseHeaders","Headers","ensureMeta","baseRedirectDestination","redirectServerURL","serverURL","successfulLogoutRedirectDest","query","redirect","path","pathname","cookieOptions","headers","redirectDestination","meta","end_session_endpoint","cookies","token","get","cookieName","decodedToken","decode","sid","undefined","body","client_id","clientID","logout_hint","post_logout_redirect_uri","qs","URLSearchParams","toString","err","logger","method"],"mappings":"AAEA,OAAOA,SAAS,eAAc;AAC9B,SAASC,YAAY,QAAQ,UAAS;AAKtC,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,YAAY,QAAQ,+BAA8B;AAS3D,OAAO,MAA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AAC9B,SAAS+B,UAAU;oBAC7C,IAAI,CAACF,OAAO;wBACV1B,YAAYI,KAAK,CAAC;4BAAEC,KAAK;wBAAqC;wBAC9D,OAAOC,SAASC,IAAI,CAAC;4BAAEH,OAAO;wBAAqC,GAAG;4BAAEI,QAAQ;wBAAI;oBACtF;oBAEA,MAAMqB,eAAe1C,IAAI2C,MAAM,CAACJ;oBAChC,MAAMK,MAAM,OAAOF,iBAAiB,YAAYA,eAAeA,aAAaE,GAAG,GAAGC;oBAElF,MAAMC,OAAO;wBACXC,WAAWrC,SAASsC,QAAQ;wBAC5BC,aAAaL;wBACbM,0BAA0BtB;oBAC5B;oBAEA,MAAMuB,KAAK,IAAIC,gBAAgBN,MAAMO,QAAQ;oBAC7ClB,sBAAsB,GAAGzB,SAAS0B,IAAI,CAACC,oBAAoB,CAAC,CAAC,EAAEc,IAAI;gBACrE;gBAEAjD,YAAY;oBACVuC,YAAY/B,SAAS+B,UAAU;oBAC/BR;oBACArB;gBACF;gBAEAV,YAAY;oBACVuC,YAAY,GAAG/B,SAAS+B,UAAU,CAAC,QAAQ,CAAC;oBAC5CR;oBACArB;gBACF;gBAEA,OAAOO,SAASW,QAAQ,CAACK;YAC3B,EAAE,OAAOmB,KAAc;gBACrB1C,IAAIE,OAAO,CAACyC,MAAM,CAACtC,KAAK,CAAC;oBAAEqC;oBAAKpC,KAAK;oBAAoCa,MAAMnB,IAAIoB,QAAQ;gBAAC;gBAE5F,OAAOb,SAASC,IAAI,CAAC;oBAAEH,OAAO;gBAAmC,GAAG;oBAAEI,QAAQ;gBAAI;YACpF;QACF;QACAmC,QAAQ;QACRzB,MAAM,CAAC,CAAC,EAAEvB,aAAa,OAAO,CAAC;IACjC,CAAA,EAAE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CollectionConfig, Endpoint } from 'payload';
|
|
2
|
+
import type { Strategy } from '../strategy/index.js';
|
|
3
|
+
import type { CollectionOptions, PluginOptions } from '../types.js';
|
|
4
|
+
interface Args {
|
|
5
|
+
collection: CollectionConfig;
|
|
6
|
+
collectionOptions: CollectionOptions;
|
|
7
|
+
endpointSlug: string;
|
|
8
|
+
pluginOptions: PluginOptions;
|
|
9
|
+
strategy: Strategy;
|
|
10
|
+
}
|
|
11
|
+
export declare const getMetaEndpoint: ({ collection, collectionOptions, endpointSlug, pluginOptions, strategy, }: Args) => Endpoint;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=getMetaEndpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMetaEndpoint.d.ts","sourceRoot":"","sources":["../../../src/oauth/endpoints/getMetaEndpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAInE,UAAU,IAAI;IACZ,UAAU,EAAE,gBAAgB,CAAA;IAC5B,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,aAAa,CAAA;IAC5B,QAAQ,EAAE,QAAQ,CAAA;CACnB;AAED,eAAO,MAAM,eAAe,8EAMzB,IAAI,KAAG,QAkBR,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getAuthorizeURL } from '../utilities/getAuthorizeURL.js';
|
|
2
|
+
export const getMetaEndpoint = ({ collection, collectionOptions, endpointSlug, pluginOptions, strategy })=>({
|
|
3
|
+
handler: async (req)=>{
|
|
4
|
+
const authorizeURL = await getAuthorizeURL({
|
|
5
|
+
collection,
|
|
6
|
+
collectionOptions,
|
|
7
|
+
endpointSlug,
|
|
8
|
+
failedRedirect: req.query.failedRedirect,
|
|
9
|
+
payload: req.payload,
|
|
10
|
+
pluginOptions,
|
|
11
|
+
redirect: req.query.redirect,
|
|
12
|
+
serverURLOverride: req.query.serverURL,
|
|
13
|
+
strategy
|
|
14
|
+
});
|
|
15
|
+
return Response.json({
|
|
16
|
+
authorizeURL
|
|
17
|
+
}, {
|
|
18
|
+
status: 200
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
method: 'get',
|
|
22
|
+
path: `/${endpointSlug}/meta`
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=getMetaEndpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/oauth/endpoints/getMetaEndpoint.ts"],"sourcesContent":["import type { CollectionConfig, Endpoint } from 'payload'\n\nimport type { Strategy } from '../strategy/index.js'\nimport type { CollectionOptions, PluginOptions } from '../types.js'\n\nimport { getAuthorizeURL } from '../utilities/getAuthorizeURL.js'\n\ninterface Args {\n collection: CollectionConfig\n collectionOptions: CollectionOptions\n endpointSlug: string\n pluginOptions: PluginOptions\n strategy: Strategy\n}\n\nexport const getMetaEndpoint = ({\n collection,\n collectionOptions,\n endpointSlug,\n pluginOptions,\n strategy,\n}: Args): Endpoint => ({\n handler: async (req) => {\n const authorizeURL = await getAuthorizeURL({\n collection,\n collectionOptions,\n endpointSlug,\n failedRedirect: req.query.failedRedirect,\n payload: req.payload,\n pluginOptions,\n redirect: req.query.redirect as string,\n serverURLOverride: req.query.serverURL as string,\n strategy,\n })\n\n return Response.json({ authorizeURL }, { status: 200 })\n },\n method: 'get',\n path: `/${endpointSlug}/meta`,\n})\n"],"names":["getAuthorizeURL","getMetaEndpoint","collection","collectionOptions","endpointSlug","pluginOptions","strategy","handler","req","authorizeURL","failedRedirect","query","payload","redirect","serverURLOverride","serverURL","Response","json","status","method","path"],"mappings":"AAKA,SAASA,eAAe,QAAQ,kCAAiC;AAUjE,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,UAAU,EACVC,iBAAiB,EACjBC,YAAY,EACZC,aAAa,EACbC,QAAQ,EACH,GAAgB,CAAA;QACrBC,SAAS,OAAOC;YACd,MAAMC,eAAe,MAAMT,gBAAgB;gBACzCE;gBACAC;gBACAC;gBACAM,gBAAgBF,IAAIG,KAAK,CAACD,cAAc;gBACxCE,SAASJ,IAAII,OAAO;gBACpBP;gBACAQ,UAAUL,IAAIG,KAAK,CAACE,QAAQ;gBAC5BC,mBAAmBN,IAAIG,KAAK,CAACI,SAAS;gBACtCT;YACF;YAEA,OAAOU,SAASC,IAAI,CAAC;gBAAER;YAAa,GAAG;gBAAES,QAAQ;YAAI;QACvD;QACAC,QAAQ;QACRC,MAAM,CAAC,CAAC,EAAEhB,aAAa,KAAK,CAAC;IAC/B,CAAA,EAAE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CollectionConfig, Endpoint } from 'payload';
|
|
2
|
+
import type { Strategy } from '../strategy/index.js';
|
|
3
|
+
import type { CollectionOptions, PluginOptions } from '../types.js';
|
|
4
|
+
interface Args {
|
|
5
|
+
collection: CollectionConfig;
|
|
6
|
+
collectionOptions: CollectionOptions;
|
|
7
|
+
endpointSlug: string;
|
|
8
|
+
pluginOptions: PluginOptions;
|
|
9
|
+
strategy: Strategy;
|
|
10
|
+
}
|
|
11
|
+
export declare const getRedirectToLoginEndpoint: ({ collection, collectionOptions, endpointSlug, pluginOptions, strategy, }: Args) => Endpoint;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=getRedirectToLoginEndpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRedirectToLoginEndpoint.d.ts","sourceRoot":"","sources":["../../../src/oauth/endpoints/getRedirectToLoginEndpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAInE,UAAU,IAAI;IACZ,UAAU,EAAE,gBAAgB,CAAA;IAC5B,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,aAAa,CAAA;IAC5B,QAAQ,EAAE,QAAQ,CAAA;CACnB;AAED,eAAO,MAAM,0BAA0B,8EAMpC,IAAI,KAAG,QAkBR,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getAuthorizeURL } from '../utilities/getAuthorizeURL.js';
|
|
2
|
+
export const getRedirectToLoginEndpoint = ({ collection, collectionOptions, endpointSlug, pluginOptions, strategy })=>({
|
|
3
|
+
handler: async (req)=>{
|
|
4
|
+
const authorizeURL = await getAuthorizeURL({
|
|
5
|
+
collection,
|
|
6
|
+
collectionOptions,
|
|
7
|
+
endpointSlug,
|
|
8
|
+
failedRedirect: req.query.failedRedirect,
|
|
9
|
+
payload: req.payload,
|
|
10
|
+
pluginOptions,
|
|
11
|
+
redirect: req.query.redirect,
|
|
12
|
+
serverURLOverride: req.query.serverURL,
|
|
13
|
+
strategy
|
|
14
|
+
});
|
|
15
|
+
return Response.redirect(authorizeURL);
|
|
16
|
+
},
|
|
17
|
+
method: 'get',
|
|
18
|
+
path: `/${endpointSlug}/login`
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=getRedirectToLoginEndpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/oauth/endpoints/getRedirectToLoginEndpoint.ts"],"sourcesContent":["import type { CollectionConfig, Endpoint } from 'payload'\n\nimport type { Strategy } from '../strategy/index.js'\nimport type { CollectionOptions, PluginOptions } from '../types.js'\n\nimport { getAuthorizeURL } from '../utilities/getAuthorizeURL.js'\n\ninterface Args {\n collection: CollectionConfig\n collectionOptions: CollectionOptions\n endpointSlug: string\n pluginOptions: PluginOptions\n strategy: Strategy\n}\n\nexport const getRedirectToLoginEndpoint = ({\n collection,\n collectionOptions,\n endpointSlug,\n pluginOptions,\n strategy,\n}: Args): Endpoint => ({\n handler: async (req) => {\n const authorizeURL = await getAuthorizeURL({\n collection,\n collectionOptions,\n endpointSlug,\n failedRedirect: req.query.failedRedirect,\n payload: req.payload,\n pluginOptions,\n redirect: req.query.redirect as string,\n serverURLOverride: req.query.serverURL as string,\n strategy,\n })\n\n return Response.redirect(authorizeURL)\n },\n method: 'get',\n path: `/${endpointSlug}/login`,\n})\n"],"names":["getAuthorizeURL","getRedirectToLoginEndpoint","collection","collectionOptions","endpointSlug","pluginOptions","strategy","handler","req","authorizeURL","failedRedirect","query","payload","redirect","serverURLOverride","serverURL","Response","method","path"],"mappings":"AAKA,SAASA,eAAe,QAAQ,kCAAiC;AAUjE,OAAO,MAAMC,6BAA6B,CAAC,EACzCC,UAAU,EACVC,iBAAiB,EACjBC,YAAY,EACZC,aAAa,EACbC,QAAQ,EACH,GAAgB,CAAA;QACrBC,SAAS,OAAOC;YACd,MAAMC,eAAe,MAAMT,gBAAgB;gBACzCE;gBACAC;gBACAC;gBACAM,gBAAgBF,IAAIG,KAAK,CAACD,cAAc;gBACxCE,SAASJ,IAAII,OAAO;gBACpBP;gBACAQ,UAAUL,IAAIG,KAAK,CAACE,QAAQ;gBAC5BC,mBAAmBN,IAAIG,KAAK,CAACI,SAAS;gBACtCT;YACF;YAEA,OAAOU,SAASH,QAAQ,CAACJ;QAC3B;QACAQ,QAAQ;QACRC,MAAM,CAAC,CAAC,EAAEd,aAAa,MAAM,CAAC;IAChC,CAAA,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/oauth/exports/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/oauth/exports/client.ts"],"sourcesContent":["export { DefaultLoginButton } from '../components/LoginButton/index.jsx'\nexport { LogoutButton } from '../components/LogoutButton/index.jsx'\n"],"names":["DefaultLoginButton","LogoutButton"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,sCAAqC;AACxE,SAASC,YAAY,QAAQ,uCAAsC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CollectionAfterLogoutHook, CollectionConfig } from 'payload';
|
|
2
|
+
import type { PluginOptions } from '../types.js';
|
|
3
|
+
export declare const getAfterLogout: ({ collection, cookieName, pluginOptions, }: {
|
|
4
|
+
collection: CollectionConfig;
|
|
5
|
+
cookieName: string;
|
|
6
|
+
pluginOptions: PluginOptions;
|
|
7
|
+
}) => CollectionAfterLogoutHook;
|
|
8
|
+
//# sourceMappingURL=afterLogout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"afterLogout.d.ts","sourceRoot":"","sources":["../../../src/oauth/hooks/afterLogout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAKhD,eAAO,MAAM,cAAc,+CAKtB;IACD,UAAU,EAAE,gBAAgB,CAAA;IAC5B,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,aAAa,CAAA;CAC7B,KAAG,yBAuBH,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { clearCookie } from '../utilities/clearCookie.js';
|
|
2
|
+
import { createCookieOptions } from '../utilities/createCookieOptions.js';
|
|
3
|
+
export const getAfterLogout = ({ collection, cookieName, pluginOptions })=>({ req })=>{
|
|
4
|
+
if (!req) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if (!req.responseHeaders) {
|
|
8
|
+
req.responseHeaders = new Headers();
|
|
9
|
+
}
|
|
10
|
+
const cookieOptions = createCookieOptions({
|
|
11
|
+
collection,
|
|
12
|
+
headers: req.headers,
|
|
13
|
+
pluginOptions
|
|
14
|
+
});
|
|
15
|
+
clearCookie({
|
|
16
|
+
cookieName,
|
|
17
|
+
cookieOptions,
|
|
18
|
+
req
|
|
19
|
+
});
|
|
20
|
+
clearCookie({
|
|
21
|
+
cookieName: `${cookieName}-refresh`,
|
|
22
|
+
cookieOptions,
|
|
23
|
+
req
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=afterLogout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/oauth/hooks/afterLogout.ts"],"sourcesContent":["import type { CollectionAfterLogoutHook, CollectionConfig } from 'payload'\n\nimport type { PluginOptions } from '../types.js'\n\nimport { clearCookie } from '../utilities/clearCookie.js'\nimport { createCookieOptions } from '../utilities/createCookieOptions.js'\n\nexport const getAfterLogout =\n ({\n collection,\n cookieName,\n pluginOptions,\n }: {\n collection: CollectionConfig\n cookieName: string\n pluginOptions: PluginOptions\n }): CollectionAfterLogoutHook =>\n ({ req }) => {\n if (!req) {\n return\n }\n\n if (!req.responseHeaders) {\n req.responseHeaders = new Headers()\n }\n\n const cookieOptions = createCookieOptions({ collection, headers: req.headers, pluginOptions })\n\n clearCookie({\n cookieName,\n cookieOptions,\n req,\n })\n\n clearCookie({\n cookieName: `${cookieName}-refresh`,\n cookieOptions,\n req,\n })\n }\n"],"names":["clearCookie","createCookieOptions","getAfterLogout","collection","cookieName","pluginOptions","req","responseHeaders","Headers","cookieOptions","headers"],"mappings":"AAIA,SAASA,WAAW,QAAQ,8BAA6B;AACzD,SAASC,mBAAmB,QAAQ,sCAAqC;AAEzE,OAAO,MAAMC,iBACX,CAAC,EACCC,UAAU,EACVC,UAAU,EACVC,aAAa,EAKd,GACD,CAAC,EAAEC,GAAG,EAAE;QACN,IAAI,CAACA,KAAK;YACR;QACF;QAEA,IAAI,CAACA,IAAIC,eAAe,EAAE;YACxBD,IAAIC,eAAe,GAAG,IAAIC;QAC5B;QAEA,MAAMC,gBAAgBR,oBAAoB;YAAEE;YAAYO,SAASJ,IAAII,OAAO;YAAEL;QAAc;QAE5FL,YAAY;YACVI;YACAK;YACAH;QACF;QAEAN,YAAY;YACVI,YAAY,GAAGA,WAAW,QAAQ,CAAC;YACnCK;YACAH;QACF;IACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"me.d.ts","sourceRoot":"","sources":["../../../src/oauth/hooks/me.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAgB,MAAM,SAAS,CAAA;AAK7D,eAAO,MAAM,SAAS,mBACH;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,KAAG,gBAgDzC,CAAA"}
|