@payloadcms/figma 0.0.1-alpha.1 → 0.0.1-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/dist/api/control-plane.d.ts.map +1 -1
  2. package/dist/api/control-plane.js +2 -7
  3. package/dist/api/control-plane.js.map +1 -1
  4. package/dist/api/figma-api.js +3 -3
  5. package/dist/api/figma-api.js.map +1 -1
  6. package/dist/auth/jwt-validator.js.map +1 -1
  7. package/dist/auth/oauth-flow.d.ts.map +1 -1
  8. package/dist/auth/oauth-flow.js +3 -6
  9. package/dist/auth/oauth-flow.js.map +1 -1
  10. package/dist/auth/project-token.d.ts.map +1 -1
  11. package/dist/auth/project-token.js +1 -4
  12. package/dist/auth/project-token.js.map +1 -1
  13. package/dist/auth/refresh.d.ts.map +1 -1
  14. package/dist/auth/refresh.js +19 -28
  15. package/dist/auth/refresh.js.map +1 -1
  16. package/dist/auth/types.d.ts +1 -1
  17. package/dist/auth/types.d.ts.map +1 -1
  18. package/dist/auth/types.js.map +1 -1
  19. package/dist/cli.js +1 -3
  20. package/dist/cli.js.map +1 -1
  21. package/dist/commands/deploy.d.ts.map +1 -1
  22. package/dist/commands/deploy.js +17 -10
  23. package/dist/commands/deploy.js.map +1 -1
  24. package/dist/commands/init.d.ts +4 -0
  25. package/dist/commands/init.d.ts.map +1 -1
  26. package/dist/commands/init.js +21 -85
  27. package/dist/commands/init.js.map +1 -1
  28. package/dist/commands/list-tokens.d.ts +1 -1
  29. package/dist/commands/list-tokens.d.ts.map +1 -1
  30. package/dist/commands/list-tokens.js +6 -5
  31. package/dist/commands/list-tokens.js.map +1 -1
  32. package/dist/commands/login.d.ts +2 -11
  33. package/dist/commands/login.d.ts.map +1 -1
  34. package/dist/commands/login.js +4 -7
  35. package/dist/commands/login.js.map +1 -1
  36. package/dist/commands/logout.d.ts +1 -1
  37. package/dist/commands/logout.js +1 -1
  38. package/dist/commands/logout.js.map +1 -1
  39. package/dist/exports/client.d.ts +3 -0
  40. package/dist/exports/client.d.ts.map +1 -0
  41. package/dist/exports/client.js +4 -0
  42. package/dist/exports/client.js.map +1 -0
  43. package/dist/oauth/components/LoginButton/index.d.ts +9 -0
  44. package/dist/oauth/components/LoginButton/index.d.ts.map +1 -0
  45. package/dist/oauth/components/LoginButton/index.js +52 -0
  46. package/dist/oauth/components/LoginButton/index.js.map +1 -0
  47. package/dist/oauth/components/LoginButton/index.scss +10 -0
  48. package/dist/oauth/components/LogoutButton/index.d.ts +7 -0
  49. package/dist/oauth/components/LogoutButton/index.d.ts.map +1 -0
  50. package/dist/oauth/components/LogoutButton/index.js +67 -0
  51. package/dist/oauth/components/LogoutButton/index.js.map +1 -0
  52. package/dist/oauth/components/LogoutButton/index.scss +10 -0
  53. package/dist/oauth/defaults.d.ts +10 -0
  54. package/dist/oauth/defaults.d.ts.map +1 -0
  55. package/dist/oauth/defaults.js +91 -0
  56. package/dist/oauth/defaults.js.map +1 -0
  57. package/dist/oauth/endpoints/getLoginEndpoint.d.ts +13 -0
  58. package/dist/oauth/endpoints/getLoginEndpoint.d.ts.map +1 -0
  59. package/dist/oauth/endpoints/getLoginEndpoint.js +237 -0
  60. package/dist/oauth/endpoints/getLoginEndpoint.js.map +1 -0
  61. package/dist/oauth/endpoints/getLogoutEndpoint.d.ts +12 -0
  62. package/dist/oauth/endpoints/getLogoutEndpoint.d.ts.map +1 -0
  63. package/dist/oauth/endpoints/getLogoutEndpoint.js +99 -0
  64. package/dist/oauth/endpoints/getLogoutEndpoint.js.map +1 -0
  65. package/dist/oauth/endpoints/getMetaEndpoint.d.ts +13 -0
  66. package/dist/oauth/endpoints/getMetaEndpoint.d.ts.map +1 -0
  67. package/dist/oauth/endpoints/getMetaEndpoint.js +25 -0
  68. package/dist/oauth/endpoints/getMetaEndpoint.js.map +1 -0
  69. package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts +13 -0
  70. package/dist/oauth/endpoints/getRedirectToLoginEndpoint.d.ts.map +1 -0
  71. package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js +21 -0
  72. package/dist/oauth/endpoints/getRedirectToLoginEndpoint.js.map +1 -0
  73. package/dist/oauth/exports/client.d.ts +3 -0
  74. package/dist/oauth/exports/client.d.ts.map +1 -0
  75. package/dist/oauth/exports/client.js +4 -0
  76. package/dist/oauth/exports/client.js.map +1 -0
  77. package/dist/oauth/hooks/afterLogout.d.ts +8 -0
  78. package/dist/oauth/hooks/afterLogout.d.ts.map +1 -0
  79. package/dist/oauth/hooks/afterLogout.js +27 -0
  80. package/dist/oauth/hooks/afterLogout.js.map +1 -0
  81. package/dist/oauth/hooks/me.d.ts +5 -0
  82. package/dist/oauth/hooks/me.d.ts.map +1 -0
  83. package/dist/oauth/hooks/me.js +55 -0
  84. package/dist/oauth/hooks/me.js.map +1 -0
  85. package/dist/oauth/hooks/refresh.d.ts +8 -0
  86. package/dist/oauth/hooks/refresh.d.ts.map +1 -0
  87. package/dist/oauth/hooks/refresh.js +91 -0
  88. package/dist/oauth/hooks/refresh.js.map +1 -0
  89. package/dist/oauth/index.d.ts +4 -0
  90. package/dist/oauth/index.d.ts.map +1 -0
  91. package/dist/oauth/index.js +222 -0
  92. package/dist/oauth/index.js.map +1 -0
  93. package/dist/oauth/strategy/index.d.ts +54 -0
  94. package/dist/oauth/strategy/index.d.ts.map +1 -0
  95. package/dist/oauth/strategy/index.js +280 -0
  96. package/dist/oauth/strategy/index.js.map +1 -0
  97. package/dist/oauth/types.d.ts +192 -0
  98. package/dist/oauth/types.d.ts.map +1 -0
  99. package/dist/oauth/types.js +3 -0
  100. package/dist/oauth/types.js.map +1 -0
  101. package/dist/oauth/utilities/clearCookie.d.ts +9 -0
  102. package/dist/oauth/utilities/clearCookie.d.ts.map +1 -0
  103. package/dist/oauth/utilities/clearCookie.js +21 -0
  104. package/dist/oauth/utilities/clearCookie.js.map +1 -0
  105. package/dist/oauth/utilities/createCookieOptions.d.ts +10 -0
  106. package/dist/oauth/utilities/createCookieOptions.d.ts.map +1 -0
  107. package/dist/oauth/utilities/createCookieOptions.js +42 -0
  108. package/dist/oauth/utilities/createCookieOptions.js.map +1 -0
  109. package/dist/oauth/utilities/createDebugLogger.d.ts +4 -0
  110. package/dist/oauth/utilities/createDebugLogger.d.ts.map +1 -0
  111. package/dist/oauth/utilities/createDebugLogger.js +16 -0
  112. package/dist/oauth/utilities/createDebugLogger.js.map +1 -0
  113. package/dist/oauth/utilities/extractOrigin.d.ts +2 -0
  114. package/dist/oauth/utilities/extractOrigin.d.ts.map +1 -0
  115. package/dist/oauth/utilities/extractOrigin.js +12 -0
  116. package/dist/oauth/utilities/extractOrigin.js.map +1 -0
  117. package/dist/oauth/utilities/getAdminCollectionSlug.d.ts +3 -0
  118. package/dist/oauth/utilities/getAdminCollectionSlug.d.ts.map +1 -0
  119. package/dist/oauth/utilities/getAdminCollectionSlug.js +18 -0
  120. package/dist/oauth/utilities/getAdminCollectionSlug.js.map +1 -0
  121. package/dist/oauth/utilities/getAdminPath.d.ts +8 -0
  122. package/dist/oauth/utilities/getAdminPath.d.ts.map +1 -0
  123. package/dist/oauth/utilities/getAdminPath.js +9 -0
  124. package/dist/oauth/utilities/getAdminPath.js.map +1 -0
  125. package/dist/oauth/utilities/getAuthorizeURL.d.ts +17 -0
  126. package/dist/oauth/utilities/getAuthorizeURL.d.ts.map +1 -0
  127. package/dist/oauth/utilities/getAuthorizeURL.js +45 -0
  128. package/dist/oauth/utilities/getAuthorizeURL.js.map +1 -0
  129. package/dist/oauth/utilities/getCookieExpiration.d.ts +4 -0
  130. package/dist/oauth/utilities/getCookieExpiration.d.ts.map +1 -0
  131. package/dist/oauth/utilities/getCookieExpiration.js +11 -0
  132. package/dist/oauth/utilities/getCookieExpiration.js.map +1 -0
  133. package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts +2 -0
  134. package/dist/oauth/utilities/getSecondsFromTokenExp.d.ts.map +1 -0
  135. package/dist/oauth/utilities/getSecondsFromTokenExp.js +7 -0
  136. package/dist/oauth/utilities/getSecondsFromTokenExp.js.map +1 -0
  137. package/dist/oauth/utilities/getTokenExp.d.ts +6 -0
  138. package/dist/oauth/utilities/getTokenExp.d.ts.map +1 -0
  139. package/dist/oauth/utilities/getTokenExp.js +20 -0
  140. package/dist/oauth/utilities/getTokenExp.js.map +1 -0
  141. package/dist/oauth/utilities/getUsernameField.d.ts +9 -0
  142. package/dist/oauth/utilities/getUsernameField.d.ts.map +1 -0
  143. package/dist/oauth/utilities/getUsernameField.js +20 -0
  144. package/dist/oauth/utilities/getUsernameField.js.map +1 -0
  145. package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts +8 -0
  146. package/dist/oauth/utilities/hasUserTokenPropsChanged.d.ts.map +1 -0
  147. package/dist/oauth/utilities/hasUserTokenPropsChanged.js +25 -0
  148. package/dist/oauth/utilities/hasUserTokenPropsChanged.js.map +1 -0
  149. package/dist/oauth/utilities/mergeHeaders.d.ts +2 -0
  150. package/dist/oauth/utilities/mergeHeaders.d.ts.map +1 -0
  151. package/dist/oauth/utilities/mergeHeaders.js +37 -0
  152. package/dist/oauth/utilities/mergeHeaders.js.map +1 -0
  153. package/dist/oauth/utilities/refreshTokens.d.ts +16 -0
  154. package/dist/oauth/utilities/refreshTokens.d.ts.map +1 -0
  155. package/dist/oauth/utilities/refreshTokens.js +67 -0
  156. package/dist/oauth/utilities/refreshTokens.js.map +1 -0
  157. package/dist/plugin/build-config.d.ts +7 -1
  158. package/dist/plugin/build-config.d.ts.map +1 -1
  159. package/dist/plugin/build-config.js +29 -2
  160. package/dist/plugin/build-config.js.map +1 -1
  161. package/dist/types/config.d.ts +0 -11
  162. package/dist/types/config.d.ts.map +1 -1
  163. package/dist/types/config.js +1 -1
  164. package/dist/types/config.js.map +1 -1
  165. package/dist/utils/config.d.ts +0 -22
  166. package/dist/utils/config.d.ts.map +1 -1
  167. package/dist/utils/config.js +0 -46
  168. package/dist/utils/config.js.map +1 -1
  169. package/dist/utils/messages.js +11 -11
  170. package/dist/utils/messages.js.map +1 -1
  171. package/dist/utils/payload-config-ast.d.ts +17 -1
  172. package/dist/utils/payload-config-ast.d.ts.map +1 -1
  173. package/dist/utils/payload-config-ast.js +166 -14
  174. package/dist/utils/payload-config-ast.js.map +1 -1
  175. package/dist/utils/payload-config-modifier.d.ts +2 -1
  176. package/dist/utils/payload-config-modifier.d.ts.map +1 -1
  177. package/dist/utils/payload-config-modifier.js +50 -79
  178. package/dist/utils/payload-config-modifier.js.map +1 -1
  179. package/dist/utils/payload-package-check.d.ts.map +1 -1
  180. package/dist/utils/payload-package-check.js +14 -33
  181. package/dist/utils/payload-package-check.js.map +1 -1
  182. package/dist/utils/project.d.ts +1 -1
  183. package/dist/utils/project.d.ts.map +1 -1
  184. package/dist/utils/project.js +3 -5
  185. package/dist/utils/project.js.map +1 -1
  186. package/dist/utils/s3-upload.d.ts.map +1 -1
  187. package/dist/utils/s3-upload.js +3 -8
  188. package/dist/utils/s3-upload.js.map +1 -1
  189. package/dist/utils/token-display.d.ts.map +1 -1
  190. package/dist/utils/token-display.js +3 -2
  191. package/dist/utils/token-display.js.map +1 -1
  192. package/package.json +9 -3
  193. package/dist/api/control-plane.spec.d.ts +0 -2
  194. package/dist/api/control-plane.spec.d.ts.map +0 -1
  195. package/dist/api/control-plane.spec.js +0 -296
  196. package/dist/api/control-plane.spec.js.map +0 -1
  197. package/dist/api/figma-api.spec.d.ts +0 -14
  198. package/dist/api/figma-api.spec.d.ts.map +0 -1
  199. package/dist/api/figma-api.spec.js +0 -201
  200. package/dist/api/figma-api.spec.js.map +0 -1
  201. package/dist/auth/__tests__/fixtures.d.ts +0 -26
  202. package/dist/auth/__tests__/fixtures.d.ts.map +0 -1
  203. package/dist/auth/__tests__/fixtures.js +0 -67
  204. package/dist/auth/__tests__/fixtures.js.map +0 -1
  205. package/dist/auth/__tests__/mocks.d.ts +0 -33
  206. package/dist/auth/__tests__/mocks.d.ts.map +0 -1
  207. package/dist/auth/__tests__/mocks.js +0 -63
  208. package/dist/auth/__tests__/mocks.js.map +0 -1
  209. package/dist/auth/callback-server.spec.d.ts +0 -2
  210. package/dist/auth/callback-server.spec.d.ts.map +0 -1
  211. package/dist/auth/callback-server.spec.js +0 -85
  212. package/dist/auth/callback-server.spec.js.map +0 -1
  213. package/dist/auth/crypto-utils.spec.d.ts +0 -2
  214. package/dist/auth/crypto-utils.spec.d.ts.map +0 -1
  215. package/dist/auth/crypto-utils.spec.js +0 -36
  216. package/dist/auth/crypto-utils.spec.js.map +0 -1
  217. package/dist/auth/jwt-validator.spec.d.ts +0 -10
  218. package/dist/auth/jwt-validator.spec.d.ts.map +0 -1
  219. package/dist/auth/jwt-validator.spec.js +0 -236
  220. package/dist/auth/jwt-validator.spec.js.map +0 -1
  221. package/dist/auth/oauth-flow.spec.d.ts +0 -2
  222. package/dist/auth/oauth-flow.spec.d.ts.map +0 -1
  223. package/dist/auth/oauth-flow.spec.js +0 -134
  224. package/dist/auth/oauth-flow.spec.js.map +0 -1
  225. package/dist/auth/pkce.spec.d.ts +0 -2
  226. package/dist/auth/pkce.spec.d.ts.map +0 -1
  227. package/dist/auth/pkce.spec.js +0 -32
  228. package/dist/auth/pkce.spec.js.map +0 -1
  229. package/dist/auth/project-token.spec.d.ts +0 -2
  230. package/dist/auth/project-token.spec.d.ts.map +0 -1
  231. package/dist/auth/project-token.spec.js +0 -332
  232. package/dist/auth/project-token.spec.js.map +0 -1
  233. package/dist/auth/refresh.spec.d.ts +0 -2
  234. package/dist/auth/refresh.spec.d.ts.map +0 -1
  235. package/dist/auth/refresh.spec.js +0 -105
  236. package/dist/auth/refresh.spec.js.map +0 -1
  237. package/dist/auth/token-store.spec.d.ts +0 -2
  238. package/dist/auth/token-store.spec.d.ts.map +0 -1
  239. package/dist/auth/token-store.spec.js +0 -276
  240. package/dist/auth/token-store.spec.js.map +0 -1
  241. package/dist/commands/__tests__/test-utils.d.ts +0 -28
  242. package/dist/commands/__tests__/test-utils.d.ts.map +0 -1
  243. package/dist/commands/__tests__/test-utils.js +0 -34
  244. package/dist/commands/__tests__/test-utils.js.map +0 -1
  245. package/dist/commands/deploy.spec.d.ts +0 -2
  246. package/dist/commands/deploy.spec.d.ts.map +0 -1
  247. package/dist/commands/deploy.spec.js +0 -18
  248. package/dist/commands/deploy.spec.js.map +0 -1
  249. package/dist/commands/init.spec.d.ts +0 -2
  250. package/dist/commands/init.spec.d.ts.map +0 -1
  251. package/dist/commands/init.spec.js +0 -283
  252. package/dist/commands/init.spec.js.map +0 -1
  253. package/dist/plugin/build-config.spec.d.ts +0 -2
  254. package/dist/plugin/build-config.spec.d.ts.map +0 -1
  255. package/dist/plugin/build-config.spec.js +0 -72
  256. package/dist/plugin/build-config.spec.js.map +0 -1
  257. package/dist/utils/asset-collection.spec.d.ts +0 -2
  258. package/dist/utils/asset-collection.spec.d.ts.map +0 -1
  259. package/dist/utils/asset-collection.spec.js +0 -155
  260. package/dist/utils/asset-collection.spec.js.map +0 -1
  261. package/dist/utils/build-detection.spec.d.ts +0 -2
  262. package/dist/utils/build-detection.spec.d.ts.map +0 -1
  263. package/dist/utils/build-detection.spec.js +0 -110
  264. package/dist/utils/build-detection.spec.js.map +0 -1
  265. package/dist/utils/config.spec.d.ts +0 -2
  266. package/dist/utils/config.spec.d.ts.map +0 -1
  267. package/dist/utils/config.spec.js +0 -167
  268. package/dist/utils/config.spec.js.map +0 -1
  269. package/dist/utils/download-template.spec.d.ts +0 -2
  270. package/dist/utils/download-template.spec.d.ts.map +0 -1
  271. package/dist/utils/download-template.spec.js +0 -76
  272. package/dist/utils/download-template.spec.js.map +0 -1
  273. package/dist/utils/env-management.spec.d.ts +0 -2
  274. package/dist/utils/env-management.spec.d.ts.map +0 -1
  275. package/dist/utils/env-management.spec.js +0 -123
  276. package/dist/utils/env-management.spec.js.map +0 -1
  277. package/dist/utils/git.spec.d.ts +0 -2
  278. package/dist/utils/git.spec.d.ts.map +0 -1
  279. package/dist/utils/git.spec.js +0 -99
  280. package/dist/utils/git.spec.js.map +0 -1
  281. package/dist/utils/lambda-config.spec.d.ts +0 -2
  282. package/dist/utils/lambda-config.spec.d.ts.map +0 -1
  283. package/dist/utils/lambda-config.spec.js +0 -141
  284. package/dist/utils/lambda-config.spec.js.map +0 -1
  285. package/dist/utils/payload-config-ast.spec.d.ts +0 -2
  286. package/dist/utils/payload-config-ast.spec.d.ts.map +0 -1
  287. package/dist/utils/payload-config-ast.spec.js +0 -303
  288. package/dist/utils/payload-config-ast.spec.js.map +0 -1
  289. package/dist/utils/payload-config-modifier.int.spec.d.ts +0 -2
  290. package/dist/utils/payload-config-modifier.int.spec.d.ts.map +0 -1
  291. package/dist/utils/payload-config-modifier.int.spec.js +0 -116
  292. package/dist/utils/payload-config-modifier.int.spec.js.map +0 -1
  293. package/dist/utils/payload-config-modifier.spec.d.ts +0 -2
  294. package/dist/utils/payload-config-modifier.spec.d.ts.map +0 -1
  295. package/dist/utils/payload-config-modifier.spec.js +0 -162
  296. package/dist/utils/payload-config-modifier.spec.js.map +0 -1
  297. package/dist/utils/payload-package-check.spec.d.ts +0 -2
  298. package/dist/utils/payload-package-check.spec.d.ts.map +0 -1
  299. package/dist/utils/payload-package-check.spec.js +0 -148
  300. package/dist/utils/payload-package-check.spec.js.map +0 -1
  301. package/dist/utils/project.spec.d.ts +0 -2
  302. package/dist/utils/project.spec.d.ts.map +0 -1
  303. package/dist/utils/project.spec.js +0 -222
  304. package/dist/utils/project.spec.js.map +0 -1
  305. package/dist/utils/s3-upload.spec.d.ts +0 -2
  306. package/dist/utils/s3-upload.spec.d.ts.map +0 -1
  307. package/dist/utils/s3-upload.spec.js +0 -140
  308. package/dist/utils/s3-upload.spec.js.map +0 -1
@@ -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,4 @@
1
+ export { DefaultLoginButton } from '../components/LoginButton/index.jsx';
2
+ export { LogoutButton } from '../components/LogoutButton/index.jsx';
3
+
4
+ //# sourceMappingURL=client.js.map
@@ -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,5 @@
1
+ import { type CollectionMeHook } from 'payload';
2
+ export declare const getMeHook: ({ cookieName }: {
3
+ cookieName: string;
4
+ }) => CollectionMeHook;
5
+ //# sourceMappingURL=me.d.ts.map
@@ -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"}
@@ -0,0 +1,55 @@
1
+ import { parseCookies } from 'payload';
2
+ import { createDebugLogger } from '../utilities/createDebugLogger.js';
3
+ import { getTokenExp } from '../utilities/getTokenExp.js';
4
+ export const getMeHook = ({ cookieName })=>// eslint-disable-next-line @typescript-eslint/require-await
5
+ async ({ args, user })=>{
6
+ const debugLogger = createDebugLogger(args.req.payload, false);
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;
53
+ };
54
+
55
+ //# sourceMappingURL=me.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/oauth/hooks/me.ts"],"sourcesContent":["import { type CollectionMeHook, parseCookies } from 'payload'\n\nimport { createDebugLogger } from '../utilities/createDebugLogger.js'\nimport { getTokenExp } from '../utilities/getTokenExp.js'\n\nexport const getMeHook =\n ({ cookieName }: { cookieName: string }): CollectionMeHook =>\n // eslint-disable-next-line @typescript-eslint/require-await\n async ({ args, user }) => {\n const debugLogger = createDebugLogger(args.req.payload, false)\n\n const cookies = parseCookies(args.req.headers)\n const refreshToken = cookies.get(`${cookieName}-refresh`)\n let token = cookies.get(cookieName)\n\n let exp: number | undefined\n\n if (refreshToken) {\n exp = getTokenExp({ debugLogger, token: refreshToken })\n if (exp) {\n return {\n exp,\n user,\n }\n }\n }\n\n if (!token) {\n // Parse Authorization header if exists\n const jwtFromHeader = args.req.headers.get('authorization')\n if (typeof jwtFromHeader === 'string' && jwtFromHeader.startsWith('Bearer ')) {\n token = jwtFromHeader.replace('Bearer ', '')\n exp = getTokenExp({ debugLogger, token })\n if (exp) {\n return {\n exp,\n user,\n }\n }\n }\n }\n\n if (token) {\n exp = getTokenExp({ debugLogger, token })\n\n if (exp) {\n return {\n exp,\n user,\n }\n }\n }\n\n return undefined\n }\n"],"names":["parseCookies","createDebugLogger","getTokenExp","getMeHook","cookieName","args","user","debugLogger","req","payload","cookies","headers","refreshToken","get","token","exp","jwtFromHeader","startsWith","replace","undefined"],"mappings":"AAAA,SAAgCA,YAAY,QAAQ,UAAS;AAE7D,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,WAAW,QAAQ,8BAA6B;AAEzD,OAAO,MAAMC,YACX,CAAC,EAAEC,UAAU,EAA0B,GACvC,4DAA4D;IAC5D,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAE;QACnB,MAAMC,cAAcN,kBAAkBI,KAAKG,GAAG,CAACC,OAAO,EAAE;QAExD,MAAMC,UAAUV,aAAaK,KAAKG,GAAG,CAACG,OAAO;QAC7C,MAAMC,eAAeF,QAAQG,GAAG,CAAC,GAAGT,WAAW,QAAQ,CAAC;QACxD,IAAIU,QAAQJ,QAAQG,GAAG,CAACT;QAExB,IAAIW;QAEJ,IAAIH,cAAc;YAChBG,MAAMb,YAAY;gBAAEK;gBAAaO,OAAOF;YAAa;YACrD,IAAIG,KAAK;gBACP,OAAO;oBACLA;oBACAT;gBACF;YACF;QACF;QAEA,IAAI,CAACQ,OAAO;YACV,uCAAuC;YACvC,MAAME,gBAAgBX,KAAKG,GAAG,CAACG,OAAO,CAACE,GAAG,CAAC;YAC3C,IAAI,OAAOG,kBAAkB,YAAYA,cAAcC,UAAU,CAAC,YAAY;gBAC5EH,QAAQE,cAAcE,OAAO,CAAC,WAAW;gBACzCH,MAAMb,YAAY;oBAAEK;oBAAaO;gBAAM;gBACvC,IAAIC,KAAK;oBACP,OAAO;wBACLA;wBACAT;oBACF;gBACF;YACF;QACF;QAEA,IAAIQ,OAAO;YACTC,MAAMb,YAAY;gBAAEK;gBAAaO;YAAM;YAEvC,IAAIC,KAAK;gBACP,OAAO;oBACLA;oBACAT;gBACF;YACF;QACF;QAEA,OAAOa;IACT,EAAC"}
@@ -0,0 +1,8 @@
1
+ import { type CollectionRefreshHook } from 'payload';
2
+ import type { Strategy } from '../strategy/index.js';
3
+ import type { PluginOptions } from '../types.js';
4
+ export declare const getRefreshHook: ({ pluginOptions, strategy, }: {
5
+ pluginOptions: PluginOptions;
6
+ strategy: Strategy;
7
+ }) => CollectionRefreshHook;
8
+ //# sourceMappingURL=refresh.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../src/oauth/hooks/refresh.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,qBAAqB,EAAgC,MAAM,SAAS,CAAA;AAElF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAShD,eAAO,MAAM,cAAc,iCAItB;IACD,aAAa,EAAE,aAAa,CAAA;IAC5B,QAAQ,EAAE,QAAQ,CAAA;CACnB,KAAG,qBAiGH,CAAA"}
@@ -0,0 +1,91 @@
1
+ import jwt from 'jsonwebtoken';
2
+ import { generateCookie, parseCookies } from 'payload';
3
+ import { createCookieOptions } from '../utilities/createCookieOptions.js';
4
+ import { createDebugLogger } from '../utilities/createDebugLogger.js';
5
+ import { getCookieExpiration } from '../utilities/getCookieExpiration.js';
6
+ import { getTokenExp } from '../utilities/getTokenExp.js';
7
+ import { mergeHeaders } from '../utilities/mergeHeaders.js';
8
+ import { refreshTokens } from '../utilities/refreshTokens.js';
9
+ export const getRefreshHook = ({ pluginOptions, strategy })=>async ({ args, user })=>{
10
+ if (!args.req.responseHeaders) {
11
+ args.req.responseHeaders = new Headers();
12
+ }
13
+ const debugLogger = createDebugLogger(args.req.payload, strategy.debug);
14
+ const cookies = parseCookies(args.req.headers);
15
+ if (strategy.collectionOptions.usePayloadJWT) {
16
+ const token = cookies.get(strategy.cookieName);
17
+ if (!token) {
18
+ args.req.payload.logger.error(`No token found under cookie: ${strategy.cookieName}`);
19
+ return undefined;
20
+ }
21
+ const decoded = jwt.verify(token, args.req.payload.secret);
22
+ strategy.debugLog('usePayloadJWT: true - Refreshing token', {
23
+ decoded,
24
+ [strategy.cookieName]: token
25
+ });
26
+ if (decoded && typeof decoded === 'object') {
27
+ const auth = typeof strategy.collection.auth === 'object' ? strategy.collection.auth : {};
28
+ const { tokenExpiration: authTokenExp } = auth;
29
+ const tokenExpiration = authTokenExp || 7200;
30
+ delete decoded.exp;
31
+ delete decoded.iat;
32
+ const refreshedToken = jwt.sign(decoded, args.req.payload.secret, {
33
+ expiresIn: tokenExpiration
34
+ });
35
+ const cookieOptions = createCookieOptions({
36
+ collection: strategy.collection,
37
+ headers: args.req.headers,
38
+ pluginOptions
39
+ });
40
+ const refreshCookie = generateCookie({
41
+ returnCookieAsObject: false,
42
+ ...cookieOptions,
43
+ name: `${strategy.cookieName}-refresh`,
44
+ expires: getCookieExpiration(cookieOptions?.expires ?? getTokenExp({
45
+ debugLogger,
46
+ token
47
+ }) ?? 31_556_952),
48
+ value: refreshedToken
49
+ });
50
+ args.req.responseHeaders.append('Set-Cookie', refreshCookie);
51
+ const newDecoded = jwt.decode(refreshedToken);
52
+ strategy.debugLog('usePayloadJWT: true - Received new refresh token', {
53
+ newDecoded,
54
+ refreshedToken
55
+ });
56
+ if (typeof newDecoded === 'object' && newDecoded) {
57
+ return {
58
+ exp: Number(newDecoded.exp),
59
+ refreshedToken,
60
+ strategy: strategy.name,
61
+ user
62
+ };
63
+ }
64
+ }
65
+ } else {
66
+ const refreshToken = cookies.get(`${strategy.cookieName}-refresh`);
67
+ if (!refreshToken) {
68
+ return undefined;
69
+ }
70
+ const result = await refreshTokens({
71
+ payload: args.req.payload,
72
+ refreshToken,
73
+ strategy
74
+ });
75
+ if (!result) {
76
+ return undefined;
77
+ }
78
+ mergeHeaders(result.headers, args.req.responseHeaders);
79
+ if (result.decodedOauthToken.exp) {
80
+ return {
81
+ exp: result.decodedOauthToken.exp,
82
+ refreshedToken: result.token,
83
+ strategy: strategy.name,
84
+ user
85
+ };
86
+ }
87
+ }
88
+ return undefined;
89
+ };
90
+
91
+ //# sourceMappingURL=refresh.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/oauth/hooks/refresh.ts"],"sourcesContent":["import jwt from 'jsonwebtoken'\nimport { type CollectionRefreshHook, generateCookie, parseCookies } from 'payload'\n\nimport type { Strategy } from '../strategy/index.js'\nimport type { PluginOptions } from '../types.js'\n\nimport { createCookieOptions } from '../utilities/createCookieOptions.js'\nimport { createDebugLogger } from '../utilities/createDebugLogger.js'\nimport { getCookieExpiration } from '../utilities/getCookieExpiration.js'\nimport { getTokenExp } from '../utilities/getTokenExp.js'\nimport { mergeHeaders } from '../utilities/mergeHeaders.js'\nimport { refreshTokens } from '../utilities/refreshTokens.js'\n\nexport const getRefreshHook =\n ({\n pluginOptions,\n strategy,\n }: {\n pluginOptions: PluginOptions\n strategy: Strategy\n }): CollectionRefreshHook =>\n async ({ args, user }) => {\n if (!args.req.responseHeaders) {\n args.req.responseHeaders = new Headers()\n }\n\n const debugLogger = createDebugLogger(args.req.payload, strategy.debug)\n\n const cookies = parseCookies(args.req.headers)\n\n if (strategy.collectionOptions.usePayloadJWT) {\n const token = cookies.get(strategy.cookieName)\n\n if (!token) {\n args.req.payload.logger.error(`No token found under cookie: ${strategy.cookieName}`)\n return undefined\n }\n\n const decoded = jwt.verify(token, args.req.payload.secret)\n\n strategy.debugLog('usePayloadJWT: true - Refreshing token', {\n decoded,\n [strategy.cookieName]: token,\n })\n\n if (decoded && typeof decoded === 'object') {\n const auth = typeof strategy.collection.auth === 'object' ? strategy.collection.auth : {}\n const { tokenExpiration: authTokenExp } = auth\n const tokenExpiration = authTokenExp || 7200\n\n delete decoded.exp\n delete decoded.iat\n\n const refreshedToken = jwt.sign(decoded, args.req.payload.secret, {\n expiresIn: tokenExpiration,\n })\n\n const cookieOptions = createCookieOptions({\n collection: strategy.collection,\n headers: args.req.headers,\n pluginOptions,\n })\n\n const refreshCookie = generateCookie({\n returnCookieAsObject: false,\n ...cookieOptions,\n name: `${strategy.cookieName}-refresh`,\n expires: getCookieExpiration(\n cookieOptions?.expires ?? getTokenExp({ debugLogger, token }) ?? 31_556_952,\n ),\n value: refreshedToken,\n }) as string\n\n args.req.responseHeaders.append('Set-Cookie', refreshCookie)\n\n const newDecoded = jwt.decode(refreshedToken)\n\n strategy.debugLog('usePayloadJWT: true - Received new refresh token', {\n newDecoded,\n refreshedToken,\n })\n\n if (typeof newDecoded === 'object' && newDecoded) {\n return {\n exp: Number(newDecoded.exp),\n refreshedToken,\n strategy: strategy.name,\n user,\n }\n }\n }\n } else {\n const refreshToken = cookies.get(`${strategy.cookieName}-refresh`)\n\n if (!refreshToken) {\n return undefined\n }\n\n const result = await refreshTokens({ payload: args.req.payload, refreshToken, strategy })\n\n if (!result) {\n return undefined\n }\n\n mergeHeaders(result.headers, args.req.responseHeaders)\n\n if (result.decodedOauthToken.exp) {\n return {\n exp: result.decodedOauthToken.exp,\n refreshedToken: result.token,\n strategy: strategy.name,\n user,\n }\n }\n }\n\n return undefined\n }\n"],"names":["jwt","generateCookie","parseCookies","createCookieOptions","createDebugLogger","getCookieExpiration","getTokenExp","mergeHeaders","refreshTokens","getRefreshHook","pluginOptions","strategy","args","user","req","responseHeaders","Headers","debugLogger","payload","debug","cookies","headers","collectionOptions","usePayloadJWT","token","get","cookieName","logger","error","undefined","decoded","verify","secret","debugLog","auth","collection","tokenExpiration","authTokenExp","exp","iat","refreshedToken","sign","expiresIn","cookieOptions","refreshCookie","returnCookieAsObject","name","expires","value","append","newDecoded","decode","Number","refreshToken","result","decodedOauthToken"],"mappings":"AAAA,OAAOA,SAAS,eAAc;AAC9B,SAAqCC,cAAc,EAAEC,YAAY,QAAQ,UAAS;AAKlF,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,iBAAiB,QAAQ,oCAAmC;AACrE,SAASC,mBAAmB,QAAQ,sCAAqC;AACzE,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SAASC,YAAY,QAAQ,+BAA8B;AAC3D,SAASC,aAAa,QAAQ,gCAA+B;AAE7D,OAAO,MAAMC,iBACX,CAAC,EACCC,aAAa,EACbC,QAAQ,EAIT,GACD,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAE;QACnB,IAAI,CAACD,KAAKE,GAAG,CAACC,eAAe,EAAE;YAC7BH,KAAKE,GAAG,CAACC,eAAe,GAAG,IAAIC;QACjC;QAEA,MAAMC,cAAcb,kBAAkBQ,KAAKE,GAAG,CAACI,OAAO,E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oBAEnEwB,OAAOR;gBACT;gBAEA5B,KAAKE,GAAG,CAACC,eAAe,CAACkC,MAAM,CAAC,cAAcL;gBAE9C,MAAMM,aAAalD,IAAImD,MAAM,CAACX;gBAE9B7B,SAASsB,QAAQ,CAAC,oDAAoD;oBACpEiB;oBACAV;gBACF;gBAEA,IAAI,OAAOU,eAAe,YAAYA,YAAY;oBAChD,OAAO;wBACLZ,KAAKc,OAAOF,WAAWZ,GAAG;wBAC1BE;wBACA7B,UAAUA,SAASmC,IAAI;wBACvBjC;oBACF;gBACF;YACF;QACF,OAAO;YACL,MAAMwC,eAAejC,QAAQK,GAAG,CAAC,GAAGd,SAASe,UAAU,CAAC,QAAQ,CAAC;YAEjE,IAAI,CAAC2B,cAAc;gBACjB,OAAOxB;YACT;YAEA,MAAMyB,SAAS,MAAM9C,cAAc;gBAAEU,SAASN,KAAKE,GAAG,CAACI,OAAO;gBAAEmC;gBAAc1C;YAAS;YAEvF,IAAI,CAAC2C,QAAQ;gBACX,OAAOzB;YACT;YAEAtB,aAAa+C,OAAOjC,OAAO,EAAET,KAAKE,GAAG,CAACC,eAAe;YAErD,IAAIuC,OAAOC,iBAAiB,CAACjB,GAAG,EAAE;gBAChC,OAAO;oBACLA,KAAKgB,OAAOC,iBAAiB,CAACjB,GAAG;oBACjCE,gBAAgBc,OAAO9B,KAAK;oBAC5Bb,UAAUA,SAASmC,IAAI;oBACvBjC;gBACF;YACF;QACF;QAEA,OAAOgB;IACT,EAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from 'payload';
2
+ import type { PluginOptions } from './types.js';
3
+ export declare const oAuth2Plugin: (pluginOptions: PluginOptions) => Plugin;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/oauth/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoD,MAAM,EAAE,MAAM,SAAS,CAAA;AAEvF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAc/C,eAAO,MAAM,YAAY,kBACP,aAAa,KAAG,MAwP/B,CAAA"}
@@ -0,0 +1,222 @@
1
+ import { defaultVerify } from './defaults.js';
2
+ import { getLoginEndpoint } from './endpoints/getLoginEndpoint.js';
3
+ import { getLogoutEndpoint } from './endpoints/getLogoutEndpoint.js';
4
+ import { getMetaEndpoint } from './endpoints/getMetaEndpoint.js';
5
+ import { getRedirectToLoginEndpoint } from './endpoints/getRedirectToLoginEndpoint.js';
6
+ import { getAfterLogout } from './hooks/afterLogout.js';
7
+ import { getMeHook } from './hooks/me.js';
8
+ import { getRefreshHook } from './hooks/refresh.js';
9
+ import { Strategy } from './strategy/index.js';
10
+ import { getAdminCollectionSlug } from './utilities/getAdminCollectionSlug.js';
11
+ import { getUsernameField } from './utilities/getUsernameField.js';
12
+ export const oAuth2Plugin = (pluginOptions)=>(config)=>{
13
+ const { collections: allCollectionOptions, debug, disabled } = pluginOptions;
14
+ const strategyName = pluginOptions?.strategyName || 'oauth';
15
+ // Defaults to sso, but can be overridden to accommodate multiple strategies on one collection
16
+ const endpointSlug = pluginOptions?.strategyName || 'sso';
17
+ const adminCollectionSlug = getAdminCollectionSlug(config);
18
+ const adminCollectionOptions = allCollectionOptions.find(({ slug })=>slug === adminCollectionSlug);
19
+ if (!adminCollectionOptions) {
20
+ throw new Error(`Can't find collection options for the admin collection ${adminCollectionSlug}.`);
21
+ }
22
+ let LoginButton = null;
23
+ if (adminCollectionOptions.LoginButton === false) {
24
+ LoginButton = null;
25
+ } else if (typeof adminCollectionOptions.LoginButton === 'string') {
26
+ LoginButton = {
27
+ clientProps: {
28
+ disabled,
29
+ endpointSlug
30
+ },
31
+ path: adminCollectionOptions.LoginButton
32
+ };
33
+ } else if (typeof adminCollectionOptions.LoginButton === 'object') {
34
+ LoginButton = {
35
+ ...adminCollectionOptions.LoginButton,
36
+ clientProps: {
37
+ ...adminCollectionOptions.LoginButton.clientProps,
38
+ disabled,
39
+ endpointSlug
40
+ }
41
+ };
42
+ } else {
43
+ // Default to the provided LoginButton component path
44
+ LoginButton = {
45
+ clientProps: {
46
+ disabled,
47
+ endpointSlug
48
+ },
49
+ path: '@payloadcms/figma/client#DefaultLoginButton'
50
+ };
51
+ }
52
+ return {
53
+ ...config,
54
+ admin: {
55
+ ...config.admin || {},
56
+ components: {
57
+ ...typeof config.admin === 'object' && typeof config.admin.components === 'object' ? config.admin.components : {},
58
+ ...adminCollectionOptions.endOAuthSessionOnLogout ? {
59
+ logout: {
60
+ Button: {
61
+ clientProps: {
62
+ disabled,
63
+ endpointSlug
64
+ },
65
+ path: '@payloadcms/figma/client#LogoutButton'
66
+ }
67
+ }
68
+ } : {},
69
+ beforeLogin: [
70
+ ...typeof config.admin === 'object' && typeof config.admin.components === 'object' && Array.isArray(config.admin.components.beforeLogin) ? config.admin.components.beforeLogin : [],
71
+ ...LoginButton ? [
72
+ LoginButton
73
+ ] : []
74
+ ]
75
+ }
76
+ },
77
+ collections: (config.collections || []).map((existingCollection)=>{
78
+ const collectionOptions = allCollectionOptions.find(({ slug })=>slug === existingCollection.slug);
79
+ if (!collectionOptions) {
80
+ return existingCollection;
81
+ }
82
+ let cookieName = pluginOptions?.cookieName || `payload-${strategyName}-token`;
83
+ // If the usePayloadJWT option is enabled, use the default cookie name from Payload
84
+ if (collectionOptions.usePayloadJWT) {
85
+ cookieName = `${config.cookiePrefix || 'payload'}-token`;
86
+ }
87
+ // Check if email field exists, if not add it
88
+ const hasEmailField = existingCollection.fields.some((field)=>'name' in field && field.name === 'email');
89
+ // Add email field to collection before getting username field
90
+ // This ensures getUsernameField can find the email field if it's configured as the username
91
+ const collectionWithEmail = hasEmailField ? existingCollection : {
92
+ ...existingCollection,
93
+ fields: [
94
+ ...existingCollection.fields,
95
+ {
96
+ name: 'email',
97
+ type: 'email'
98
+ }
99
+ ]
100
+ };
101
+ const usernameField = getUsernameField({
102
+ collection: collectionWithEmail,
103
+ collectionOptions
104
+ });
105
+ const fields = [
106
+ ...collectionWithEmail.fields,
107
+ ...typeof adminCollectionOptions.usernameField === 'string' ? [] : [
108
+ usernameField
109
+ ]
110
+ ];
111
+ if (disabled) {
112
+ return {
113
+ ...existingCollection,
114
+ fields
115
+ };
116
+ }
117
+ const strategy = new Strategy({
118
+ clientID: collectionOptions.clientID,
119
+ clientSecret: collectionOptions.clientSecret,
120
+ collection: existingCollection,
121
+ collectionOptions,
122
+ cookieName,
123
+ debug,
124
+ identityMetadata: collectionOptions.identityMetadata,
125
+ pluginOptions,
126
+ strategyName,
127
+ verify: collectionOptions.verify ?? defaultVerify({
128
+ collection: existingCollection,
129
+ strategyName,
130
+ usernameField
131
+ })
132
+ });
133
+ const authStrategy = {
134
+ name: `${existingCollection.slug}-${strategyName}`,
135
+ // Bind 'this' to ensure the authenticate function has the correct context
136
+ authenticate: strategy.authenticate.bind(strategy)
137
+ };
138
+ let disableLocalStrategy;
139
+ if (collectionOptions.disableLocalStrategy === false) {
140
+ // When the plugin collection option has disableLocalStrategy option set to false, do not disable the local strategy
141
+ disableLocalStrategy = undefined;
142
+ } else if (collectionOptions.disableLocalStrategy) {
143
+ // use the configured disableLocalStrategy which can include `enableFields`, etc.
144
+ disableLocalStrategy = collectionOptions.disableLocalStrategy;
145
+ } else {
146
+ // by default disableLocalStrategy
147
+ disableLocalStrategy = true;
148
+ }
149
+ return {
150
+ ...existingCollection,
151
+ auth: {
152
+ ...typeof existingCollection.auth === 'object' ? existingCollection.auth : {},
153
+ disableLocalStrategy,
154
+ strategies: [
155
+ ...typeof existingCollection.auth === 'object' && Array.isArray(existingCollection.auth.strategies) ? existingCollection.auth.strategies : [],
156
+ authStrategy
157
+ ]
158
+ },
159
+ endpoints: [
160
+ ...existingCollection.endpoints || [],
161
+ getLoginEndpoint({
162
+ collection: existingCollection,
163
+ collectionOptions,
164
+ endpointSlug,
165
+ pluginOptions,
166
+ strategy
167
+ }),
168
+ getMetaEndpoint({
169
+ collection: existingCollection,
170
+ collectionOptions,
171
+ endpointSlug,
172
+ pluginOptions,
173
+ strategy
174
+ }),
175
+ getLogoutEndpoint({
176
+ collection: existingCollection,
177
+ endpointSlug,
178
+ pluginOptions,
179
+ strategy
180
+ }),
181
+ getRedirectToLoginEndpoint({
182
+ collection: existingCollection,
183
+ collectionOptions,
184
+ endpointSlug,
185
+ pluginOptions,
186
+ strategy
187
+ })
188
+ ],
189
+ fields,
190
+ hooks: {
191
+ ...existingCollection.hooks || {},
192
+ afterLogout: [
193
+ ...typeof existingCollection.hooks === 'object' && Array.isArray(existingCollection.hooks.afterLogout) ? existingCollection.hooks.afterLogout : [],
194
+ getAfterLogout({
195
+ collection: existingCollection,
196
+ cookieName,
197
+ pluginOptions
198
+ })
199
+ ],
200
+ me: [
201
+ ...typeof existingCollection.hooks === 'object' && Array.isArray(existingCollection.hooks.me) ? existingCollection.hooks.me : [],
202
+ // Do not inject the me hook if the usePayloadJWT option is enabled
203
+ ...!collectionOptions.usePayloadJWT ? [
204
+ getMeHook({
205
+ cookieName
206
+ })
207
+ ] : []
208
+ ],
209
+ refresh: [
210
+ ...typeof existingCollection.hooks === 'object' && Array.isArray(existingCollection.hooks.refresh) ? existingCollection.hooks.refresh : [],
211
+ getRefreshHook({
212
+ pluginOptions,
213
+ strategy
214
+ })
215
+ ]
216
+ }
217
+ };
218
+ })
219
+ };
220
+ };
221
+
222
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/oauth/index.ts"],"sourcesContent":["import type { AuthStrategy, CollectionConfig, IncomingAuthType, Plugin } from 'payload'\n\nimport type { PluginOptions } from './types.js'\n\nimport { defaultVerify } from './defaults.js'\nimport { getLoginEndpoint } from './endpoints/getLoginEndpoint.js'\nimport { getLogoutEndpoint } from './endpoints/getLogoutEndpoint.js'\nimport { getMetaEndpoint } from './endpoints/getMetaEndpoint.js'\nimport { getRedirectToLoginEndpoint } from './endpoints/getRedirectToLoginEndpoint.js'\nimport { getAfterLogout } from './hooks/afterLogout.js'\nimport { getMeHook } from './hooks/me.js'\nimport { getRefreshHook } from './hooks/refresh.js'\nimport { Strategy } from './strategy/index.js'\nimport { getAdminCollectionSlug } from './utilities/getAdminCollectionSlug.js'\nimport { getUsernameField } from './utilities/getUsernameField.js'\n\nexport const oAuth2Plugin =\n (pluginOptions: PluginOptions): Plugin =>\n (config) => {\n const { collections: allCollectionOptions, debug, disabled } = pluginOptions\n\n const strategyName = pluginOptions?.strategyName || 'oauth'\n // Defaults to sso, but can be overridden to accommodate multiple strategies on one collection\n const endpointSlug = pluginOptions?.strategyName || 'sso'\n\n const adminCollectionSlug = getAdminCollectionSlug(config)\n const adminCollectionOptions = allCollectionOptions.find(\n ({ slug }) => slug === adminCollectionSlug,\n )\n\n if (!adminCollectionOptions) {\n throw new Error(\n `Can't find collection options for the admin collection ${adminCollectionSlug}.`,\n )\n }\n\n let LoginButton = null\n\n if (adminCollectionOptions.LoginButton === false) {\n LoginButton = null\n } else if (typeof adminCollectionOptions.LoginButton === 'string') {\n LoginButton = {\n clientProps: {\n disabled,\n endpointSlug,\n },\n path: adminCollectionOptions.LoginButton,\n }\n } else if (typeof adminCollectionOptions.LoginButton === 'object') {\n LoginButton = {\n ...adminCollectionOptions.LoginButton,\n clientProps: {\n ...adminCollectionOptions.LoginButton.clientProps,\n disabled,\n endpointSlug,\n },\n }\n } else {\n // Default to the provided LoginButton component path\n LoginButton = {\n clientProps: {\n disabled,\n endpointSlug,\n },\n path: '@payloadcms/figma/client#DefaultLoginButton',\n }\n }\n\n return {\n ...config,\n admin: {\n ...(config.admin || {}),\n components: {\n ...(typeof config.admin === 'object' && typeof config.admin.components === 'object'\n ? config.admin.components\n : {}),\n ...(adminCollectionOptions.endOAuthSessionOnLogout\n ? {\n logout: {\n Button: {\n clientProps: {\n disabled,\n endpointSlug,\n },\n path: '@payloadcms/figma/client#LogoutButton',\n },\n },\n }\n : {}),\n beforeLogin: [\n ...(typeof config.admin === 'object' &&\n typeof config.admin.components === 'object' &&\n Array.isArray(config.admin.components.beforeLogin)\n ? config.admin.components.beforeLogin\n : []),\n ...(LoginButton ? [LoginButton] : []),\n ],\n },\n },\n collections: (config.collections || []).map((existingCollection) => {\n const collectionOptions = allCollectionOptions.find(\n ({ slug }) => slug === existingCollection.slug,\n )\n\n if (!collectionOptions) {\n return existingCollection\n }\n\n let cookieName = pluginOptions?.cookieName || `payload-${strategyName}-token`\n // If the usePayloadJWT option is enabled, use the default cookie name from Payload\n if (collectionOptions.usePayloadJWT) {\n cookieName = `${config.cookiePrefix || 'payload'}-token`\n }\n\n // Check if email field exists, if not add it\n const hasEmailField = existingCollection.fields.some(\n (field) => 'name' in field && field.name === 'email',\n )\n\n // Add email field to collection before getting username field\n // This ensures getUsernameField can find the email field if it's configured as the username\n const collectionWithEmail: CollectionConfig = hasEmailField\n ? existingCollection\n : {\n ...existingCollection,\n fields: [\n ...existingCollection.fields,\n {\n name: 'email',\n type: 'email',\n },\n ],\n }\n\n const usernameField = getUsernameField({\n collection: collectionWithEmail,\n collectionOptions,\n })\n\n const fields = [\n ...collectionWithEmail.fields,\n ...(typeof adminCollectionOptions.usernameField === 'string' ? [] : [usernameField]),\n ]\n\n if (disabled) {\n return {\n ...existingCollection,\n fields,\n }\n }\n\n const strategy = new Strategy({\n clientID: collectionOptions.clientID,\n clientSecret: collectionOptions.clientSecret,\n collection: existingCollection,\n collectionOptions,\n cookieName,\n debug,\n identityMetadata: collectionOptions.identityMetadata,\n pluginOptions,\n strategyName,\n verify:\n collectionOptions.verify ??\n defaultVerify({\n collection: existingCollection,\n strategyName,\n usernameField,\n }),\n })\n\n const authStrategy: AuthStrategy = {\n name: `${existingCollection.slug}-${strategyName}`,\n // Bind 'this' to ensure the authenticate function has the correct context\n authenticate: strategy.authenticate.bind(strategy),\n }\n\n let disableLocalStrategy: IncomingAuthType['disableLocalStrategy']\n\n if (collectionOptions.disableLocalStrategy === false) {\n // When the plugin collection option has disableLocalStrategy option set to false, do not disable the local strategy\n disableLocalStrategy = undefined\n } else if (collectionOptions.disableLocalStrategy) {\n // use the configured disableLocalStrategy which can include `enableFields`, etc.\n disableLocalStrategy = collectionOptions.disableLocalStrategy\n } else {\n // by default disableLocalStrategy\n disableLocalStrategy = true\n }\n\n return {\n ...existingCollection,\n auth: {\n ...(typeof existingCollection.auth === 'object' ? existingCollection.auth : {}),\n disableLocalStrategy,\n strategies: [\n ...(typeof existingCollection.auth === 'object' &&\n Array.isArray(existingCollection.auth.strategies)\n ? existingCollection.auth.strategies\n : []),\n authStrategy,\n ],\n },\n endpoints: [\n ...(existingCollection.endpoints || []),\n getLoginEndpoint({\n collection: existingCollection,\n collectionOptions,\n endpointSlug,\n pluginOptions,\n strategy,\n }),\n getMetaEndpoint({\n collection: existingCollection,\n collectionOptions,\n endpointSlug,\n pluginOptions,\n strategy,\n }),\n getLogoutEndpoint({\n collection: existingCollection,\n endpointSlug,\n pluginOptions,\n strategy,\n }),\n getRedirectToLoginEndpoint({\n collection: existingCollection,\n collectionOptions,\n endpointSlug,\n pluginOptions,\n strategy,\n }),\n ],\n fields,\n hooks: {\n ...(existingCollection.hooks || {}),\n afterLogout: [\n ...(typeof existingCollection.hooks === 'object' &&\n Array.isArray(existingCollection.hooks.afterLogout)\n ? existingCollection.hooks.afterLogout\n : []),\n getAfterLogout({\n collection: existingCollection,\n cookieName,\n pluginOptions,\n }),\n ],\n me: [\n ...(typeof existingCollection.hooks === 'object' &&\n Array.isArray(existingCollection.hooks.me)\n ? existingCollection.hooks.me\n : []),\n // Do not inject the me hook if the usePayloadJWT option is enabled\n ...(!collectionOptions.usePayloadJWT ? [getMeHook({ cookieName })] : []),\n ],\n refresh: [\n ...(typeof existingCollection.hooks === 'object' &&\n Array.isArray(existingCollection.hooks.refresh)\n ? existingCollection.hooks.refresh\n : []),\n getRefreshHook({ pluginOptions, strategy }),\n ],\n },\n }\n }),\n }\n }\n"],"names":["defaultVerify","getLoginEndpoint","getLogoutEndpoint","getMetaEndpoint","getRedirectToLoginEndpoint","getAfterLogout","getMeHook","getRefreshHook","Strategy","getAdminCollectionSlug","getUsernameField","oAuth2Plugin","pluginOptions","config","collections","allCollectionOptions","debug","disabled","strategyName","endpointSlug","adminCollectionSlug","adminCollectionOptions","find","slug","Error","LoginButton","clientProps","path","admin","components","endOAuthSessionOnLogout","logout","Button","beforeLogin","Array","isArray","map","existingCollection","collectionOptions","cookieName","usePayloadJWT","cookiePrefix","hasEmailField","fields","some","field","name","collectionWithEmail","type","usernameField","collection","strategy","clientID","clientSecret","identityMetadata","verify","authStrategy","authenticate","bind","disableLocalStrategy","undefined","auth","strategies","endpoints","hooks","afterLogout","me","refresh"],"mappings":"AAIA,SAASA,aAAa,QAAQ,gBAAe;AAC7C,SAASC,gBAAgB,QAAQ,kCAAiC;AAClE,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,eAAe,QAAQ,iCAAgC;AAChE,SAASC,0BAA0B,QAAQ,4CAA2C;AACtF,SAASC,cAAc,QAAQ,yBAAwB;AACvD,SAASC,SAAS,QAAQ,gBAAe;AACzC,SAASC,cAAc,QAAQ,qBAAoB;AACnD,SAASC,QAAQ,QAAQ,sBAAqB;AAC9C,SAASC,sBAAsB,QAAQ,wCAAuC;AAC9E,SAASC,gBAAgB,QAAQ,kCAAiC;AAElE,OAAO,MAAMC,eACX,CAACC,gBACD,CAACC;QACC,MAAM,EAAEC,aAAaC,oBAAoB,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAGL;QAE/D,MAAMM,eAAeN,eAAeM,gBAAgB;QACpD,8FAA8F;QAC9F,MAAMC,eAAeP,eAAeM,gBAAgB;QAEpD,MAAME,sBAAsBX,uBAAuBI;QACnD,MAAMQ,yBAAyBN,qBAAqBO,IAAI,CACtD,CAAC,EAAEC,IAAI,EAAE,GAAKA,SAASH;QAGzB,IAAI,CAACC,wBAAwB;YAC3B,MAAM,IAAIG,MACR,CAAC,uDAAuD,EAAEJ,oBAAoB,CAAC,CAAC;QAEpF;QAEA,IAAIK,cAAc;QAElB,IAAIJ,u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pC,EAAE;4BACN5D,eAAe;gCACb6C,YAAYb;gCACZE;gCACA3B;4BACF;yBACD;wBACDsD,IAAI;+BACE,OAAO7B,mBAAmB2B,KAAK,KAAK,YACxC9B,MAAMC,OAAO,CAACE,mBAAmB2B,KAAK,CAACE,EAAE,IACrC7B,mBAAmB2B,KAAK,CAACE,EAAE,GAC3B,EAAE;4BACN,mEAAmE;+BAC/D,CAAC5B,kBAAkBE,aAAa,GAAG;gCAAClC,UAAU;oCAAEiC;gCAAW;6BAAG,GAAG,EAAE;yBACxE;wBACD4B,SAAS;+BACH,OAAO9B,mBAAmB2B,KAAK,KAAK,YACxC9B,MAAMC,OAAO,CAACE,mBAAmB2B,KAAK,CAACG,OAAO,IAC1C9B,mBAAmB2B,KAAK,CAACG,OAAO,GAChC,EAAE;4BACN5D,eAAe;gCAAEK;gCAAeuC;4BAAS;yBAC1C;oBACH;gBACF;YACF;QACF;IACF,EAAC"}
@@ -0,0 +1,54 @@
1
+ import type jwt from 'jsonwebtoken';
2
+ import type { AuthStrategyFunctionArgs, AuthStrategyResult, CollectionConfig, Payload } from 'payload';
3
+ import * as jose from 'jose';
4
+ import type { CollectionOptions, PluginOptions, VerifyFunction } from '../types.js';
5
+ export interface Options {
6
+ clientID: string;
7
+ clientSecret?: string;
8
+ collection: CollectionConfig;
9
+ collectionOptions: CollectionOptions;
10
+ cookieName: string;
11
+ debug?: boolean;
12
+ identityMetadata: string;
13
+ pluginOptions: PluginOptions;
14
+ strategyName: string;
15
+ verify: VerifyFunction;
16
+ }
17
+ export declare class Strategy {
18
+ clientID: string;
19
+ clientSecret?: string;
20
+ collection: CollectionConfig;
21
+ collectionOptions: CollectionOptions;
22
+ cookieName: string;
23
+ debug: boolean;
24
+ debugLog: (...args: any[]) => void;
25
+ identityMetadataURL: string;
26
+ jwks?: {
27
+ keys: jose.JWK[];
28
+ };
29
+ meta?: {
30
+ authorization_endpoint: string;
31
+ end_session_endpoint: string;
32
+ jwks_uri: string;
33
+ token_endpoint: string;
34
+ userinfo_endpoint: string;
35
+ };
36
+ metaLastFetchedTime?: Date;
37
+ metaPromise?: Promise<void>;
38
+ metaPromiseResolve?: () => void;
39
+ name: string;
40
+ pluginOptions: PluginOptions;
41
+ verify: VerifyFunction;
42
+ constructor(options: Options);
43
+ authenticate({ canSetHeaders, headers, payload, }: AuthStrategyFunctionArgs): Promise<AuthStrategyResult>;
44
+ ensureMeta(): Promise<void>;
45
+ fetchMeta(): Promise<void>;
46
+ generateOidcPEM(kid: string, alg: string): Promise<string>;
47
+ jwtVerify({ payload, token }: JwtVerifyArgs): Promise<Error | jwt.JwtPayload | null>;
48
+ }
49
+ type JwtVerifyArgs = {
50
+ payload: Payload;
51
+ token: string;
52
+ };
53
+ export {};
54
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/oauth/strategy/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAEnC,OAAO,KAAK,EACV,wBAAwB,EACxB,kBAAkB,EAClB,gBAAgB,EAChB,OAAO,EACR,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAG5B,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAUnF,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,MAAM,CAAA;IAChB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,gBAAgB,CAAA;IAC5B,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,gBAAgB,EAAE,MAAM,CAAA;IACxB,aAAa,EAAE,aAAa,CAAA;IAC5B,YAAY,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,cAAc,CAAA;CACvB;AAED,qBAAa,QAAQ;IACnB,QAAQ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