@payloadcms/figma 1.0.0-beta.0 → 1.0.0-internal.d040868
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/adapters/build-lambda-zip.d.ts +2 -1
- package/dist/adapters/build-lambda-zip.js +4 -1
- package/dist/adapters/deploy-output/assertDeployableServerActionsKey.d.ts +14 -0
- package/dist/adapters/deploy-output/assertDeployableServerActionsKey.js +33 -0
- package/dist/commands/upload-schema.js +23 -9
- package/dist/content-api/auth.d.ts +34 -0
- package/dist/content-api/auth.js +70 -0
- package/dist/content-api/awaitWithSignal.d.ts +2 -0
- package/dist/content-api/awaitWithSignal.js +27 -0
- package/dist/content-api/createContentApiClient.d.ts +18 -0
- package/dist/content-api/createContentApiClient.js +90 -0
- package/dist/content-api/withRateLimitRetries.d.ts +7 -0
- package/dist/content-api/withRateLimitRetries.js +45 -0
- package/dist/db-content-api/index.d.ts +5 -5
- package/dist/db-content-api/index.js +43 -13
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/oauth/components/FigmaAvatar/index.js +3 -2
- package/dist/oauth/components/FigmaAvatarCell/index.js +3 -1
- package/dist/oauth/components/LoginButton/index.js +8 -4
- package/dist/oauth/components/LogoutButton/index.js +3 -2
- package/dist/oauth/endpoints/getLoginEndpoint.js +2 -5
- package/dist/oauth/hooks/me.d.ts +4 -3
- package/dist/oauth/hooks/me.js +6 -52
- package/dist/oauth/hooks/refresh.js +9 -1
- package/dist/oauth/index.js +3 -3
- package/dist/oauth/strategy/index.d.ts +3 -0
- package/dist/oauth/strategy/index.js +49 -3
- package/dist/oauth/utilities/clearCookie.d.ts +1 -0
- package/dist/oauth/utilities/clearCookie.js +13 -9
- package/dist/oauth/utilities/clearSessionCookies.d.ts +5 -0
- package/dist/oauth/utilities/clearSessionCookies.js +17 -0
- package/dist/oauth/utilities/mergeHeaders.js +11 -23
- package/dist/oauth/utilities/refreshTokens.d.ts +9 -3
- package/dist/oauth/utilities/refreshTokens.js +45 -34
- package/dist/oauth/utilities/resolvePayloadRedirect.d.ts +13 -0
- package/dist/oauth/utilities/resolvePayloadRedirect.js +30 -0
- package/dist/plugin/build-config.js +14 -13
- package/dist/plugin/cloud-limits/CloudLimitModal/index.js +1 -1
- package/dist/plugin/cloud-limits/shared.d.ts +5 -1
- package/dist/plugin/cloud-limits/utilities/toasts.d.ts +2 -1
- package/dist/plugin/dev-cookie-names.d.ts +4 -1
- package/dist/plugin/dev-cookie-names.js +6 -3
- package/dist/plugin/environment-error.d.ts +4 -0
- package/dist/plugin/environment-error.js +22 -0
- package/dist/plugin/sandbox-upload-fetch.d.ts +5 -6
- package/dist/plugin/sandbox-upload-fetch.js +22 -14
- package/dist/storage-content-api/client.d.ts +3 -3
- package/dist/storage-content-api/client.js +13 -35
- package/dist/storage-content-api/index.js +20 -21
- package/dist/storage-content-api/staticHandler.js +4 -1
- package/dist/storage-content-api/types.d.ts +2 -2
- package/dist/translations/ar.d.ts +9 -0
- package/dist/translations/ar.js +10 -1
- package/dist/translations/az.d.ts +9 -0
- package/dist/translations/az.js +10 -1
- package/dist/translations/bg.d.ts +9 -0
- package/dist/translations/bg.js +10 -1
- package/dist/translations/bnBd.d.ts +9 -0
- package/dist/translations/bnBd.js +10 -1
- package/dist/translations/bnIn.d.ts +9 -0
- package/dist/translations/bnIn.js +10 -1
- package/dist/translations/ca.d.ts +9 -0
- package/dist/translations/ca.js +10 -1
- package/dist/translations/cs.d.ts +9 -0
- package/dist/translations/cs.js +10 -1
- package/dist/translations/da.d.ts +9 -0
- package/dist/translations/da.js +10 -1
- package/dist/translations/de.d.ts +9 -0
- package/dist/translations/de.js +10 -1
- package/dist/translations/en.d.ts +9 -0
- package/dist/translations/en.js +10 -1
- package/dist/translations/es.d.ts +9 -0
- package/dist/translations/es.js +15 -6
- package/dist/translations/et.d.ts +9 -0
- package/dist/translations/et.js +10 -1
- package/dist/translations/fa.d.ts +9 -0
- package/dist/translations/fa.js +10 -1
- package/dist/translations/fr.d.ts +9 -0
- package/dist/translations/fr.js +10 -1
- package/dist/translations/he.d.ts +9 -0
- package/dist/translations/he.js +10 -1
- package/dist/translations/hr.d.ts +9 -0
- package/dist/translations/hr.js +10 -1
- package/dist/translations/hu.d.ts +9 -0
- package/dist/translations/hu.js +10 -1
- package/dist/translations/hy.d.ts +9 -0
- package/dist/translations/hy.js +10 -1
- package/dist/translations/id.d.ts +9 -0
- package/dist/translations/id.js +10 -1
- package/dist/translations/index.d.ts +400 -3
- package/dist/translations/is.d.ts +9 -0
- package/dist/translations/is.js +10 -1
- package/dist/translations/it.d.ts +9 -0
- package/dist/translations/it.js +10 -1
- package/dist/translations/ja.d.ts +9 -0
- package/dist/translations/ja.js +14 -5
- package/dist/translations/ko.d.ts +9 -0
- package/dist/translations/ko.js +16 -7
- package/dist/translations/lt.d.ts +9 -0
- package/dist/translations/lt.js +10 -1
- package/dist/translations/lv.d.ts +9 -0
- package/dist/translations/lv.js +10 -1
- package/dist/translations/my.d.ts +9 -0
- package/dist/translations/my.js +10 -1
- package/dist/translations/nb.d.ts +9 -0
- package/dist/translations/nb.js +10 -1
- package/dist/translations/nl.d.ts +9 -0
- package/dist/translations/nl.js +10 -1
- package/dist/translations/pl.d.ts +9 -0
- package/dist/translations/pl.js +10 -1
- package/dist/translations/pt.d.ts +9 -0
- package/dist/translations/pt.js +15 -6
- package/dist/translations/ro.d.ts +9 -0
- package/dist/translations/ro.js +10 -1
- package/dist/translations/rs.d.ts +9 -0
- package/dist/translations/rs.js +10 -1
- package/dist/translations/rsLatin.d.ts +9 -0
- package/dist/translations/rsLatin.js +10 -1
- package/dist/translations/ru.d.ts +9 -0
- package/dist/translations/ru.js +10 -1
- package/dist/translations/sk.d.ts +9 -0
- package/dist/translations/sk.js +10 -1
- package/dist/translations/sl.d.ts +9 -0
- package/dist/translations/sl.js +10 -1
- package/dist/translations/sv.d.ts +9 -0
- package/dist/translations/sv.js +10 -1
- package/dist/translations/ta.d.ts +9 -0
- package/dist/translations/ta.js +10 -1
- package/dist/translations/th.d.ts +9 -0
- package/dist/translations/th.js +10 -1
- package/dist/translations/tr.d.ts +9 -0
- package/dist/translations/tr.js +10 -1
- package/dist/translations/uk.d.ts +9 -0
- package/dist/translations/uk.js +10 -1
- package/dist/translations/vi.d.ts +9 -0
- package/dist/translations/vi.js +10 -1
- package/dist/translations/zh.d.ts +9 -0
- package/dist/translations/zh.js +10 -1
- package/dist/translations/zhTw.d.ts +9 -0
- package/dist/translations/zhTw.js +10 -1
- package/dist/utils/env-management.js +7 -0
- package/package.json +1 -1
- package/dist/db-content-api/utilities/auth.d.ts +0 -29
- package/dist/db-content-api/utilities/auth.js +0 -82
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useConfig, useSearchParams } from '@payloadcms/ui';
|
|
3
|
+
import { useConfig, useSearchParams, useTranslation } from '@payloadcms/ui';
|
|
4
4
|
import React, { useEffect, useState } from 'react';
|
|
5
5
|
import { getSearchParam } from '../../utils/getSearchParam.js';
|
|
6
6
|
import { resolveParentTargetOrigin, setupIframeAutoLogin } from './iframeAutoLogin.js';
|
|
@@ -60,8 +60,10 @@ const FigmaIcon = ()=>/*#__PURE__*/ _jsx("svg", {
|
|
|
60
60
|
fillRule: "evenodd"
|
|
61
61
|
})
|
|
62
62
|
});
|
|
63
|
-
const PayloadAdminLoadingShimmer = ()
|
|
64
|
-
|
|
63
|
+
const PayloadAdminLoadingShimmer = ()=>{
|
|
64
|
+
const { t } = useTranslation();
|
|
65
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
66
|
+
"aria-label": t('figma:signingIn'),
|
|
65
67
|
"aria-live": "polite",
|
|
66
68
|
className: `${baseClass}__admin-shimmer`,
|
|
67
69
|
role: "status",
|
|
@@ -111,8 +113,10 @@ const PayloadAdminLoadingShimmer = ()=>/*#__PURE__*/ _jsx("div", {
|
|
|
111
113
|
]
|
|
112
114
|
})
|
|
113
115
|
});
|
|
116
|
+
};
|
|
114
117
|
export const DefaultLoginButton = ({ disabled, endpointSlug })=>{
|
|
115
118
|
const { config: { admin: { user: userSlug }, routes: { api }, serverURL } } = useConfig();
|
|
119
|
+
const { t } = useTranslation();
|
|
116
120
|
const [authorizeURL, setAuthorizeURL] = useState('');
|
|
117
121
|
const [isInIframe, setIsInIframe] = useState(null);
|
|
118
122
|
const [autoLoginFailed, setAutoLoginFailed] = useState(false);
|
|
@@ -229,7 +233,7 @@ export const DefaultLoginButton = ({ disabled, endpointSlug })=>{
|
|
|
229
233
|
/*#__PURE__*/ _jsx(FigmaIcon, {}),
|
|
230
234
|
/*#__PURE__*/ _jsx("span", {
|
|
231
235
|
className: `${baseClass}__text`,
|
|
232
|
-
children:
|
|
236
|
+
children: t('figma:logInWithFigma')
|
|
233
237
|
})
|
|
234
238
|
]
|
|
235
239
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { Logout, useConfig } from '@payloadcms/ui';
|
|
3
|
+
import { Logout, useConfig, useTranslation } from '@payloadcms/ui';
|
|
4
4
|
import { formatAdminURL } from 'payload/shared';
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import './index.scss';
|
|
@@ -12,6 +12,7 @@ export const LogoutButton = ({ disabled, endpointSlug })=>{
|
|
|
12
12
|
// logout. Redirect to the site root instead so the user actually stays
|
|
13
13
|
// logged out. Outside an iframe, keep the original behavior of redirecting
|
|
14
14
|
// back to /admin.
|
|
15
|
+
const { t } = useTranslation();
|
|
15
16
|
const [redirect, setRedirect] = React.useState('');
|
|
16
17
|
React.useEffect(()=>{
|
|
17
18
|
const protocol = window.location.protocol;
|
|
@@ -44,7 +45,7 @@ export const LogoutButton = ({ disabled, endpointSlug })=>{
|
|
|
44
45
|
return /*#__PURE__*/ _jsx("div", {
|
|
45
46
|
className: baseClass,
|
|
46
47
|
children: /*#__PURE__*/ _jsx("a", {
|
|
47
|
-
"aria-label":
|
|
48
|
+
"aria-label": t('authentication:logout'),
|
|
48
49
|
href: `${serverURL}${api}/${userSlug}/${endpointSlug}/logout?redirect=${encodeURIComponent(redirect)}`,
|
|
49
50
|
children: /*#__PURE__*/ _jsxs("svg", {
|
|
50
51
|
className: "icon icon--logout",
|
|
@@ -8,6 +8,7 @@ import { exchangeCodeForAccessToken } from '../utilities/exchangeCodeForAccessTo
|
|
|
8
8
|
import { extractOrigin } from '../utilities/extractOrigin.js';
|
|
9
9
|
import { buildCsrfCookieClearHeader, getOAuthCallbackPath, OAUTH_STATE_CSRF_COOKIE_NAME } from '../utilities/getAuthorizeURL.js';
|
|
10
10
|
import { isAbsoluteURL } from '../utilities/isAbsoluteURL.js';
|
|
11
|
+
import { resolvePayloadRedirect } from '../utilities/resolvePayloadRedirect.js';
|
|
11
12
|
export const getLoginEndpoint = ({ collection, collectionOptions, endpointSlug, pluginOptions, strategy })=>({
|
|
12
13
|
handler: async (req)=>{
|
|
13
14
|
const { config } = req.payload;
|
|
@@ -196,11 +197,7 @@ export const getLoginEndpoint = ({ collection, collectionOptions, endpointSlug,
|
|
|
196
197
|
// is single-use; leaving it around lets a replay try again.
|
|
197
198
|
req.responseHeaders.append('Set-Cookie', buildCsrfCookieClearHeader());
|
|
198
199
|
if (payloadRedirect) {
|
|
199
|
-
|
|
200
|
-
redirectToUse = payloadRedirect;
|
|
201
|
-
} else {
|
|
202
|
-
redirectToUse += payloadRedirect;
|
|
203
|
-
}
|
|
200
|
+
redirectToUse = resolvePayloadRedirect(payloadRedirect, redirectToUse);
|
|
204
201
|
req.responseHeaders.append('Set-Cookie', // Match the attributes the cookie was set with so the clear removes it
|
|
205
202
|
// in the cross-site Make iframe.
|
|
206
203
|
`payloadRedirect=${redirectToUse}; Max-Age=0; Path=/; Secure; SameSite=None; Partitioned`);
|
package/dist/oauth/hooks/me.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { CollectionMeHook } from 'payload';
|
|
2
|
+
import type { Strategy } from '../strategy/index.js';
|
|
3
|
+
export declare const getMeHook: ({ strategy }: {
|
|
4
|
+
strategy: Strategy;
|
|
4
5
|
}) => CollectionMeHook;
|
package/dist/oauth/hooks/me.js
CHANGED
|
@@ -1,53 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const cookies = parseCookies(args.req.headers);
|
|
8
|
-
const refreshToken = cookies.get(`${cookieName}-refresh`);
|
|
9
|
-
let token = cookies.get(cookieName);
|
|
10
|
-
let exp;
|
|
11
|
-
if (refreshToken) {
|
|
12
|
-
exp = getTokenExp({
|
|
13
|
-
debugLogger,
|
|
14
|
-
token: refreshToken
|
|
15
|
-
});
|
|
16
|
-
if (exp) {
|
|
17
|
-
return {
|
|
18
|
-
exp,
|
|
19
|
-
user
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (!token) {
|
|
24
|
-
// Parse Authorization header if exists
|
|
25
|
-
const jwtFromHeader = args.req.headers.get('authorization');
|
|
26
|
-
if (typeof jwtFromHeader === 'string' && jwtFromHeader.startsWith('Bearer ')) {
|
|
27
|
-
token = jwtFromHeader.replace('Bearer ', '');
|
|
28
|
-
exp = getTokenExp({
|
|
29
|
-
debugLogger,
|
|
30
|
-
token
|
|
31
|
-
});
|
|
32
|
-
if (exp) {
|
|
33
|
-
return {
|
|
34
|
-
exp,
|
|
35
|
-
user
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (token) {
|
|
41
|
-
exp = getTokenExp({
|
|
42
|
-
debugLogger,
|
|
43
|
-
token
|
|
44
|
-
});
|
|
45
|
-
if (exp) {
|
|
46
|
-
return {
|
|
47
|
-
exp,
|
|
48
|
-
user
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return undefined;
|
|
1
|
+
export const getMeHook = ({ strategy })=>({ args, user })=>{
|
|
2
|
+
const exp = strategy.authenticatedTokenExpirations.get(args.req.headers);
|
|
3
|
+
return exp === undefined ? undefined : {
|
|
4
|
+
exp,
|
|
5
|
+
user
|
|
6
|
+
};
|
|
53
7
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
2
|
import { generateCookie, parseCookies } from 'payload';
|
|
3
|
+
import { clearSessionCookies } from '../utilities/clearSessionCookies.js';
|
|
3
4
|
import { createCookieOptions } from '../utilities/createCookieOptions.js';
|
|
4
5
|
import { createDebugLogger } from '../utilities/createDebugLogger.js';
|
|
5
6
|
import { getCookieExpiration } from '../utilities/getCookieExpiration.js';
|
|
@@ -69,11 +70,18 @@ export const getRefreshHook = ({ pluginOptions, strategy })=>async ({ args, user
|
|
|
69
70
|
return undefined;
|
|
70
71
|
}
|
|
71
72
|
const result = await refreshTokens({
|
|
73
|
+
headers: args.req.headers,
|
|
72
74
|
payload: args.req.payload,
|
|
73
75
|
refreshToken,
|
|
74
76
|
strategy
|
|
75
77
|
});
|
|
76
|
-
if (
|
|
78
|
+
if (result.status !== 'success') {
|
|
79
|
+
if (result.status === 'rejected') {
|
|
80
|
+
mergeHeaders(clearSessionCookies({
|
|
81
|
+
headers: args.req.headers,
|
|
82
|
+
strategy
|
|
83
|
+
}), args.req.responseHeaders);
|
|
84
|
+
}
|
|
77
85
|
return undefined;
|
|
78
86
|
}
|
|
79
87
|
mergeHeaders(result.headers, args.req.responseHeaders);
|
package/dist/oauth/index.js
CHANGED
|
@@ -97,7 +97,7 @@ export const oAuth2Plugin = (pluginOptions)=>(config)=>{
|
|
|
97
97
|
name: 'email',
|
|
98
98
|
type: 'email',
|
|
99
99
|
admin: {
|
|
100
|
-
description:
|
|
100
|
+
description: ({ t })=>t('figma:managedByFigma'),
|
|
101
101
|
readOnly: true
|
|
102
102
|
},
|
|
103
103
|
unique: true
|
|
@@ -114,7 +114,7 @@ export const oAuth2Plugin = (pluginOptions)=>(config)=>{
|
|
|
114
114
|
admin: {
|
|
115
115
|
...usernameField.admin || {},
|
|
116
116
|
...usernameField.name === 'email' ? {
|
|
117
|
-
description:
|
|
117
|
+
description: ({ t })=>t('figma:managedByFigma')
|
|
118
118
|
} : {},
|
|
119
119
|
readOnly: true
|
|
120
120
|
}
|
|
@@ -225,7 +225,7 @@ export const oAuth2Plugin = (pluginOptions)=>(config)=>{
|
|
|
225
225
|
// Do not inject the me hook if the usePayloadJWT option is enabled
|
|
226
226
|
...!collectionOptions.usePayloadJWT ? [
|
|
227
227
|
getMeHook({
|
|
228
|
-
|
|
228
|
+
strategy
|
|
229
229
|
})
|
|
230
230
|
] : []
|
|
231
231
|
],
|
|
@@ -14,6 +14,8 @@ export interface Options {
|
|
|
14
14
|
verify: VerifyFunction;
|
|
15
15
|
}
|
|
16
16
|
export declare class Strategy {
|
|
17
|
+
/** Keeps /me aligned with authentication-time renewal without changing request cookies. */
|
|
18
|
+
authenticatedTokenExpirations: WeakMap<Headers, number | undefined>;
|
|
17
19
|
clientID: string;
|
|
18
20
|
collection: CollectionConfig;
|
|
19
21
|
collectionOptions: CollectionOptions;
|
|
@@ -38,6 +40,7 @@ export declare class Strategy {
|
|
|
38
40
|
pluginOptions: PluginOptions;
|
|
39
41
|
verify: VerifyFunction;
|
|
40
42
|
constructor(options: Options);
|
|
43
|
+
private setTokenExpiration;
|
|
41
44
|
authenticate({ canSetHeaders, headers, payload, }: AuthStrategyFunctionArgs): Promise<AuthStrategyResult>;
|
|
42
45
|
ensureMeta(): Promise<void>;
|
|
43
46
|
fetchMeta(): Promise<void>;
|
|
@@ -2,11 +2,13 @@ import * as jose from 'jose';
|
|
|
2
2
|
import { APIError, parseCookies } from 'payload';
|
|
3
3
|
import { JWTValidationError, validatePayloadAdminToken } from '../../auth/jwt-validator.js';
|
|
4
4
|
import { getInfraEnvironment } from '../../constants.js';
|
|
5
|
+
import { clearSessionCookies } from '../utilities/clearSessionCookies.js';
|
|
5
6
|
import { createDebugLogger } from '../utilities/createDebugLogger.js';
|
|
6
7
|
import { getTokenExp } from '../utilities/getTokenExp.js';
|
|
7
8
|
import { mergeHeaders } from '../utilities/mergeHeaders.js';
|
|
8
9
|
import { refreshTokens } from '../utilities/refreshTokens.js';
|
|
9
10
|
export class Strategy {
|
|
11
|
+
/** Keeps /me aligned with authentication-time renewal without changing request cookies. */ authenticatedTokenExpirations = new WeakMap();
|
|
10
12
|
clientID;
|
|
11
13
|
collection;
|
|
12
14
|
collectionOptions;
|
|
@@ -38,6 +40,11 @@ export class Strategy {
|
|
|
38
40
|
// Prevent wokiness with `this`
|
|
39
41
|
this.ensureMeta = this.ensureMeta.bind(this);
|
|
40
42
|
}
|
|
43
|
+
setTokenExpiration({ exp, headers, verifyResult }) {
|
|
44
|
+
if (verifyResult.user) {
|
|
45
|
+
this.authenticatedTokenExpirations.set(headers, exp);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
41
48
|
async authenticate({ canSetHeaders, headers, payload }) {
|
|
42
49
|
const debugLogger = createDebugLogger(payload, this.debug);
|
|
43
50
|
await this.ensureMeta();
|
|
@@ -69,11 +76,13 @@ export class Strategy {
|
|
|
69
76
|
msg: 'No access token found, but refresh token exists. Attempting to refresh...'
|
|
70
77
|
});
|
|
71
78
|
const refreshed = await refreshTokens({
|
|
79
|
+
headers,
|
|
72
80
|
payload,
|
|
73
81
|
refreshToken,
|
|
74
82
|
strategy: this
|
|
75
83
|
});
|
|
76
|
-
if (refreshed) {
|
|
84
|
+
if (refreshed.status === 'success') {
|
|
85
|
+
const tokenExpiration = refreshed.decodedOauthToken.exp;
|
|
77
86
|
const verifyResult = await this.verify({
|
|
78
87
|
headers,
|
|
79
88
|
payload,
|
|
@@ -83,6 +92,11 @@ export class Strategy {
|
|
|
83
92
|
msg: 'Token refreshed. Verifying...',
|
|
84
93
|
verifyResult
|
|
85
94
|
});
|
|
95
|
+
this.setTokenExpiration({
|
|
96
|
+
exp: tokenExpiration,
|
|
97
|
+
headers,
|
|
98
|
+
verifyResult
|
|
99
|
+
});
|
|
86
100
|
// Only return response headers (to set cookies) when canSetHeaders is true.
|
|
87
101
|
// During RSC navigation, canSetHeaders=false because response streaming
|
|
88
102
|
// has already started and cookies cannot be modified.
|
|
@@ -100,6 +114,15 @@ export class Strategy {
|
|
|
100
114
|
user: verifyResult.user
|
|
101
115
|
};
|
|
102
116
|
} else {
|
|
117
|
+
if (refreshed.status === 'rejected' && canSetHeaders) {
|
|
118
|
+
return {
|
|
119
|
+
responseHeaders: clearSessionCookies({
|
|
120
|
+
headers,
|
|
121
|
+
strategy: this
|
|
122
|
+
}),
|
|
123
|
+
user: null
|
|
124
|
+
};
|
|
125
|
+
}
|
|
103
126
|
debugLogger.info({
|
|
104
127
|
msg: 'Token refresh failed'
|
|
105
128
|
});
|
|
@@ -126,6 +149,7 @@ export class Strategy {
|
|
|
126
149
|
// but first set exp from refresh token
|
|
127
150
|
// because access exp is likely very short lived
|
|
128
151
|
if (typeof oauthTokenVerifyResult === 'object' && !(oauthTokenVerifyResult instanceof Error)) {
|
|
152
|
+
const tokenExpiration = oauthTokenVerifyResult.exp;
|
|
129
153
|
if (refreshToken) {
|
|
130
154
|
const refreshTokenExp = getTokenExp({
|
|
131
155
|
debugLogger,
|
|
@@ -135,11 +159,17 @@ export class Strategy {
|
|
|
135
159
|
oauthTokenVerifyResult.exp = refreshTokenExp;
|
|
136
160
|
}
|
|
137
161
|
}
|
|
138
|
-
|
|
162
|
+
const verifyResult = await this.verify({
|
|
139
163
|
headers,
|
|
140
164
|
payload,
|
|
141
165
|
token: oauthTokenVerifyResult
|
|
142
166
|
});
|
|
167
|
+
this.setTokenExpiration({
|
|
168
|
+
exp: tokenExpiration,
|
|
169
|
+
headers,
|
|
170
|
+
verifyResult
|
|
171
|
+
});
|
|
172
|
+
return verifyResult;
|
|
143
173
|
}
|
|
144
174
|
}
|
|
145
175
|
// Handle expired access token with valid refresh token.
|
|
@@ -147,6 +177,7 @@ export class Strategy {
|
|
|
147
177
|
// but only update cookies when canSetHeaders=true.
|
|
148
178
|
if (oauthTokenVerifyResult instanceof JWTValidationError && oauthTokenVerifyResult.code === 'EXPIRED' && refreshToken && !this.collectionOptions.usePayloadJWT) {
|
|
149
179
|
const refreshed = await refreshTokens({
|
|
180
|
+
headers,
|
|
150
181
|
payload,
|
|
151
182
|
refreshToken,
|
|
152
183
|
strategy: this
|
|
@@ -154,7 +185,8 @@ export class Strategy {
|
|
|
154
185
|
debugLogger.info({
|
|
155
186
|
msg: 'Token expired. Refreshing...'
|
|
156
187
|
});
|
|
157
|
-
if (refreshed) {
|
|
188
|
+
if (refreshed.status === 'success') {
|
|
189
|
+
const tokenExpiration = refreshed.decodedOauthToken.exp;
|
|
158
190
|
const verifyResult = await this.verify({
|
|
159
191
|
headers,
|
|
160
192
|
payload,
|
|
@@ -164,6 +196,11 @@ export class Strategy {
|
|
|
164
196
|
msg: 'Token refreshed. Verifying...',
|
|
165
197
|
verifyResult
|
|
166
198
|
});
|
|
199
|
+
this.setTokenExpiration({
|
|
200
|
+
exp: tokenExpiration,
|
|
201
|
+
headers,
|
|
202
|
+
verifyResult
|
|
203
|
+
});
|
|
167
204
|
if (canSetHeaders) {
|
|
168
205
|
if (verifyResult.responseHeaders) {
|
|
169
206
|
mergeHeaders(verifyResult.responseHeaders, refreshed.headers);
|
|
@@ -178,6 +215,15 @@ export class Strategy {
|
|
|
178
215
|
user: verifyResult.user
|
|
179
216
|
};
|
|
180
217
|
} else {
|
|
218
|
+
if (refreshed.status === 'rejected' && canSetHeaders) {
|
|
219
|
+
return {
|
|
220
|
+
responseHeaders: clearSessionCookies({
|
|
221
|
+
headers,
|
|
222
|
+
strategy: this
|
|
223
|
+
}),
|
|
224
|
+
user: null
|
|
225
|
+
};
|
|
226
|
+
}
|
|
181
227
|
debugLogger.info({
|
|
182
228
|
msg: 'Token refresh failed'
|
|
183
229
|
});
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
import { generateCookie } from 'payload';
|
|
2
|
-
import { getCookieExpiration } from './getCookieExpiration.js';
|
|
3
2
|
import { withPartitionedCookie } from './withPartitionedCookie.js';
|
|
4
3
|
export const clearCookie = (args)=>{
|
|
5
4
|
const options = {
|
|
6
5
|
...args.cookieOptions,
|
|
7
6
|
...args.overrides || {}
|
|
8
7
|
};
|
|
9
|
-
const clearedCookie =
|
|
10
|
-
...options,
|
|
11
|
-
name: args.cookieName,
|
|
12
|
-
expires: getCookieExpiration(options?.expires) ?? new Date(),
|
|
13
|
-
returnCookieAsObject: false,
|
|
14
|
-
value: ''
|
|
15
|
-
});
|
|
8
|
+
const clearedCookie = generateClearedCookie(args.cookieName, options);
|
|
16
9
|
if (!args.req.responseHeaders) {
|
|
17
10
|
args.req.responseHeaders = new Headers();
|
|
18
11
|
}
|
|
19
12
|
// Match the Partitioned attribute the cookie was set with — a Max-Age=0 clear
|
|
20
13
|
// without it targets the unpartitioned jar and won't delete the partitioned
|
|
21
14
|
// cookie, so logout wouldn't clear the session in the cross-site Make iframe.
|
|
22
|
-
args.req.responseHeaders.append('Set-Cookie',
|
|
15
|
+
args.req.responseHeaders.append('Set-Cookie', clearedCookie);
|
|
16
|
+
};
|
|
17
|
+
export const generateClearedCookie = (cookieName, cookieOptions)=>{
|
|
18
|
+
const cookie = generateCookie({
|
|
19
|
+
...cookieOptions,
|
|
20
|
+
name: cookieName,
|
|
21
|
+
expires: new Date(0),
|
|
22
|
+
maxAge: 0,
|
|
23
|
+
returnCookieAsObject: false,
|
|
24
|
+
value: ''
|
|
25
|
+
});
|
|
26
|
+
return withPartitionedCookie(cookie);
|
|
23
27
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { generateClearedCookie } from './clearCookie.js';
|
|
2
|
+
import { createCookieOptions } from './createCookieOptions.js';
|
|
3
|
+
export const clearSessionCookies = ({ headers, strategy })=>{
|
|
4
|
+
const cookieOptions = createCookieOptions({
|
|
5
|
+
collection: strategy.collection,
|
|
6
|
+
headers,
|
|
7
|
+
pluginOptions: strategy.pluginOptions
|
|
8
|
+
});
|
|
9
|
+
const responseHeaders = new Headers();
|
|
10
|
+
for (const name of [
|
|
11
|
+
strategy.cookieName,
|
|
12
|
+
`${strategy.cookieName}-refresh`
|
|
13
|
+
]){
|
|
14
|
+
responseHeaders.append('Set-Cookie', generateClearedCookie(name, cookieOptions));
|
|
15
|
+
}
|
|
16
|
+
return responseHeaders;
|
|
17
|
+
};
|
|
@@ -1,35 +1,23 @@
|
|
|
1
1
|
const headersToJoin = [
|
|
2
|
-
'set-cookie',
|
|
3
2
|
'warning',
|
|
4
3
|
'www-authenticate',
|
|
5
4
|
'proxy-authenticate',
|
|
6
5
|
'vary'
|
|
7
6
|
];
|
|
8
7
|
export function mergeHeaders(sourceHeaders, destinationHeaders) {
|
|
9
|
-
// Create a map to store combined headers
|
|
10
|
-
const combinedHeaders = new Headers();
|
|
11
|
-
// Add existing destination headers to the combined map
|
|
12
|
-
destinationHeaders.forEach((value, key)=>{
|
|
13
|
-
combinedHeaders.set(key, value);
|
|
14
|
-
});
|
|
15
|
-
// Add source headers to the combined map, joining specific headers
|
|
16
8
|
sourceHeaders.forEach((value, key)=>{
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
combinedHeaders.set(key, value);
|
|
23
|
-
}
|
|
9
|
+
if (key.toLowerCase() === 'set-cookie') {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (headersToJoin.includes(key.toLowerCase())) {
|
|
13
|
+
destinationHeaders.append(key, value);
|
|
24
14
|
} else {
|
|
25
|
-
|
|
15
|
+
destinationHeaders.set(key, value);
|
|
26
16
|
}
|
|
27
17
|
});
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
destinationHeaders.append(key, value);
|
|
34
|
-
});
|
|
18
|
+
// Set-Cookie cannot be comma-joined: Expires contains commas, and each
|
|
19
|
+
// cookie must remain a separate header for browsers to apply both deletions.
|
|
20
|
+
for (const cookie of sourceHeaders.getSetCookie()){
|
|
21
|
+
destinationHeaders.append('Set-Cookie', cookie);
|
|
22
|
+
}
|
|
35
23
|
}
|
|
@@ -2,14 +2,20 @@ import type jwt from 'jsonwebtoken';
|
|
|
2
2
|
import type { Payload } from 'payload';
|
|
3
3
|
import type { Strategy } from '../strategy/index.js';
|
|
4
4
|
interface Args {
|
|
5
|
+
headers: Headers;
|
|
5
6
|
payload: Payload;
|
|
6
7
|
refreshToken: string;
|
|
7
8
|
strategy: Strategy;
|
|
8
9
|
}
|
|
9
|
-
type
|
|
10
|
+
export type RefreshResult = {
|
|
10
11
|
decodedOauthToken: jwt.JwtPayload;
|
|
11
12
|
headers: Headers;
|
|
13
|
+
status: 'success';
|
|
12
14
|
token: string;
|
|
13
|
-
} |
|
|
14
|
-
|
|
15
|
+
} | {
|
|
16
|
+
status: 'rejected';
|
|
17
|
+
} | {
|
|
18
|
+
status: 'temporary_failure';
|
|
19
|
+
};
|
|
20
|
+
export declare const refreshTokens: ({ headers: requestHeaders, payload, refreshToken, strategy, }: Args) => Promise<RefreshResult>;
|
|
15
21
|
export {};
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { generateCookie } from 'payload';
|
|
2
|
-
import { getPayloadAdminToken } from '../../api/figma-api.js';
|
|
2
|
+
import { FigmaApiError, getPayloadAdminToken } from '../../api/figma-api.js';
|
|
3
3
|
import { validatePayloadAdminToken } from '../../auth/jwt-validator.js';
|
|
4
4
|
import { getInfraEnvironment } from '../../constants.js';
|
|
5
5
|
import { createCookieOptions } from './createCookieOptions.js';
|
|
6
6
|
import { createDebugLogger } from './createDebugLogger.js';
|
|
7
7
|
import { getCookieExpiration } from './getCookieExpiration.js';
|
|
8
8
|
import { withPartitionedCookie } from './withPartitionedCookie.js';
|
|
9
|
-
export const refreshTokens = async ({ payload, refreshToken, strategy })=>{
|
|
9
|
+
export const refreshTokens = async ({ headers: requestHeaders, payload, refreshToken, strategy })=>{
|
|
10
10
|
const debugLogger = createDebugLogger(payload, strategy.debug);
|
|
11
11
|
debugLogger.info({
|
|
12
12
|
msg: 'Refreshing tokens'
|
|
13
13
|
});
|
|
14
14
|
const headers = new Headers();
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
// so we will refresh both tokens
|
|
15
|
+
// The refresh cookie holds an OAuth access token. Use it to mint a new
|
|
16
|
+
// session JWT; this does not rotate an OAuth refresh token.
|
|
18
17
|
try {
|
|
19
18
|
// Get another Payload Admin token.
|
|
20
19
|
const environmentId = payload.config.custom.figma.environmentId;
|
|
@@ -34,42 +33,54 @@ export const refreshTokens = async ({ payload, refreshToken, strategy })=>{
|
|
|
34
33
|
debugLogger.error({
|
|
35
34
|
msg: 'Error refreshing tokens'
|
|
36
35
|
});
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
if (token) {
|
|
40
|
-
debugLogger.info({
|
|
41
|
-
msg: 'Successfully refreshed Payload Admin token'
|
|
42
|
-
});
|
|
43
|
-
const expires_in = new Date(expiresAt);
|
|
44
|
-
const cookieOptions = createCookieOptions({
|
|
45
|
-
collection: strategy.collection,
|
|
46
|
-
headers,
|
|
47
|
-
pluginOptions: strategy.pluginOptions
|
|
48
|
-
});
|
|
49
|
-
const tokenCookie = generateCookie({
|
|
50
|
-
...cookieOptions,
|
|
51
|
-
name: strategy.cookieName,
|
|
52
|
-
expires: getCookieExpiration(expires_in),
|
|
53
|
-
returnCookieAsObject: false,
|
|
54
|
-
value: token
|
|
55
|
-
});
|
|
56
|
-
headers.append('Set-Cookie', withPartitionedCookie(tokenCookie));
|
|
57
|
-
const decodedOauthToken = await validatePayloadAdminToken({
|
|
58
|
-
audience: environmentId,
|
|
59
|
-
environment: getInfraEnvironment(),
|
|
60
|
-
token
|
|
61
|
-
});
|
|
62
36
|
return {
|
|
63
|
-
|
|
64
|
-
headers,
|
|
65
|
-
token
|
|
37
|
+
status: 'temporary_failure'
|
|
66
38
|
};
|
|
67
39
|
}
|
|
40
|
+
debugLogger.info({
|
|
41
|
+
msg: 'Successfully refreshed Payload Admin token'
|
|
42
|
+
});
|
|
43
|
+
const decodedOauthToken = await validatePayloadAdminToken({
|
|
44
|
+
audience: environmentId,
|
|
45
|
+
environment: getInfraEnvironment(),
|
|
46
|
+
token
|
|
47
|
+
});
|
|
48
|
+
const expires_in = new Date(expiresAt);
|
|
49
|
+
const cookieOptions = createCookieOptions({
|
|
50
|
+
collection: strategy.collection,
|
|
51
|
+
headers: requestHeaders,
|
|
52
|
+
pluginOptions: strategy.pluginOptions
|
|
53
|
+
});
|
|
54
|
+
const tokenCookie = generateCookie({
|
|
55
|
+
...cookieOptions,
|
|
56
|
+
name: strategy.cookieName,
|
|
57
|
+
expires: getCookieExpiration(expires_in),
|
|
58
|
+
returnCookieAsObject: false,
|
|
59
|
+
value: token
|
|
60
|
+
});
|
|
61
|
+
headers.append('Set-Cookie', withPartitionedCookie(tokenCookie));
|
|
62
|
+
return {
|
|
63
|
+
decodedOauthToken,
|
|
64
|
+
headers,
|
|
65
|
+
status: 'success',
|
|
66
|
+
token
|
|
67
|
+
};
|
|
68
68
|
} catch (error) {
|
|
69
|
+
if (error instanceof FigmaApiError && [
|
|
70
|
+
401,
|
|
71
|
+
403,
|
|
72
|
+
404
|
|
73
|
+
].includes(error.statusCode ?? 0)) {
|
|
74
|
+
return {
|
|
75
|
+
status: 'rejected'
|
|
76
|
+
};
|
|
77
|
+
}
|
|
69
78
|
debugLogger.error({
|
|
70
79
|
err: error,
|
|
71
80
|
msg: 'Error refreshing tokens'
|
|
72
81
|
});
|
|
73
82
|
}
|
|
74
|
-
return
|
|
83
|
+
return {
|
|
84
|
+
status: 'temporary_failure'
|
|
85
|
+
};
|
|
75
86
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies the `payloadRedirect` cookie (Payload's `?redirect=` login param, saved by
|
|
3
|
+
* `LoginButton`) to the post-login redirect URL.
|
|
4
|
+
*
|
|
5
|
+
* Payload sets `?redirect=` to the full admin path, e.g. `/admin/collections/posts`, or to just a
|
|
6
|
+
* query string when login started at the admin root. Appending a path to the admin URL would
|
|
7
|
+
* double the admin route (`/admin/admin/collections/posts`), so paths are resolved from the
|
|
8
|
+
* origin instead. Unsafe values, including absolute URLs, are ignored.
|
|
9
|
+
*
|
|
10
|
+
* @example resolvePayloadRedirect('/admin/collections/posts', 'https://site/admin') // 'https://site/admin/collections/posts'
|
|
11
|
+
* @example resolvePayloadRedirect('?embed=true', 'https://site/admin') // 'https://site/admin?embed=true'
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolvePayloadRedirect(payloadRedirect: string, redirectURL: string): string;
|