Skip to content

Commit d86f836

Browse files
authored
forward state query param to authorize (#51)
* Update authorize-endpoint.ts with state parameter * fix: using typescript function
1 parent 3e6b876 commit d86f836

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/authorize-endpoint.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import crypto from "crypto";
2-
import type { Endpoint } from "payload";
2+
import type { Endpoint, PayloadRequest } from "payload";
33
import type { PluginOptions } from "./types";
44

55
export const createAuthorizeEndpoint = (
66
pluginOptions: PluginOptions,
77
): Endpoint => ({
88
method: "get",
99
path: pluginOptions.authorizePath || "/oauth/authorize",
10-
handler: async () => {
10+
handler: async (req: PayloadRequest) => {
1111
const clientId = pluginOptions.clientId;
1212
const authCollection = pluginOptions.authCollection || "users";
1313
const callbackPath = pluginOptions.callbackPath || "/oauth/callback";
@@ -35,6 +35,10 @@ export const createAuthorizeEndpoint = (
3535
url.searchParams.append("auth_type", pluginOptions.authType);
3636
}
3737

38+
// Forward state from request query if available
39+
const state = req.searchParams.get("state");
40+
if (state) url.searchParams.append("state", state);
41+
3842
url.searchParams.append("nonce", crypto.randomBytes(16).toString("hex"));
3943

4044
return Response.redirect(url.toString());

0 commit comments

Comments
 (0)