File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change 1
1
import crypto from "crypto" ;
2
- import type { Endpoint } from "payload" ;
2
+ import type { Endpoint , PayloadRequest } from "payload" ;
3
3
import type { PluginOptions } from "./types" ;
4
4
5
5
export const createAuthorizeEndpoint = (
6
6
pluginOptions : PluginOptions ,
7
7
) : Endpoint => ( {
8
8
method : "get" ,
9
9
path : pluginOptions . authorizePath || "/oauth/authorize" ,
10
- handler : async ( ) => {
10
+ handler : async ( req : PayloadRequest ) => {
11
11
const clientId = pluginOptions . clientId ;
12
12
const authCollection = pluginOptions . authCollection || "users" ;
13
13
const callbackPath = pluginOptions . callbackPath || "/oauth/callback" ;
@@ -35,6 +35,10 @@ export const createAuthorizeEndpoint = (
35
35
url . searchParams . append ( "auth_type" , pluginOptions . authType ) ;
36
36
}
37
37
38
+ // Forward state from request query if available
39
+ const state = req . searchParams . get ( "state" ) ;
40
+ if ( state ) url . searchParams . append ( "state" , state ) ;
41
+
38
42
url . searchParams . append ( "nonce" , crypto . randomBytes ( 16 ) . toString ( "hex" ) ) ;
39
43
40
44
return Response . redirect ( url . toString ( ) ) ;
You can’t perform that action at this time.
0 commit comments