@@ -12,12 +12,16 @@ export type { Decoded }
1212// This is shared by `@redwoodjs/web`
1313const AUTH_PROVIDER_HEADER = 'auth-provider'
1414
15- export const getAuthProviderHeader = ( event : APIGatewayProxyEvent ) => {
15+ export const getAuthProviderHeader = (
16+ event : APIGatewayProxyEvent | Request
17+ ) => {
1618 const authProviderKey = Object . keys ( event ?. headers ?? { } ) . find (
1719 ( key ) => key . toLowerCase ( ) === AUTH_PROVIDER_HEADER
1820 )
1921 if ( authProviderKey ) {
20- return event ?. headers [ authProviderKey ]
22+ return isFetchApiRequest ( event )
23+ ? event ?. headers . get ( authProviderKey )
24+ : event ?. headers [ authProviderKey ]
2125 }
2226 return undefined
2327}
@@ -44,7 +48,7 @@ export const parseAuthorizationCookie = (
4448 return {
4549 parsedCookie,
4650 rawCookie : cookie ,
47- type : parsedCookie . authProvider ,
51+ type : parsedCookie [ 'auth-provider' ] ,
4852 }
4953}
5054
@@ -89,11 +93,11 @@ export const getAuthenticationContext = async ({
8993 context,
9094} : {
9195 authDecoder ?: Decoder | Decoder [ ]
92- event : APIGatewayProxyEvent
96+ event : APIGatewayProxyEvent | Request
9397 context : LambdaContext
9498} ) : Promise < undefined | AuthContextPayload > => {
9599 const typeFromHeader = getAuthProviderHeader ( event )
96- const cookieHeader = parseAuthorizationCookie ( event )
100+ const cookieHeader = parseAuthorizationCookie ( event ) //?
97101
98102 // Shortcircuit - if no auth-provider or cookie header, its
99103 // an unauthenticated request
@@ -107,7 +111,7 @@ export const getAuthenticationContext = async ({
107111
108112 // If type is set in the header, use Bearer token auth
109113 if ( typeFromHeader ) {
110- const parsedAuthHeader = parseAuthorizationHeader ( event )
114+ const parsedAuthHeader = parseAuthorizationHeader ( event as any )
111115 token = parsedAuthHeader . token
112116 type = typeFromHeader
113117 schema = parsedAuthHeader . schema
@@ -136,9 +140,15 @@ export const getAuthenticationContext = async ({
136140
137141 let i = 0
138142 while ( ! decoded && i < authDecoders . length ) {
139- decoded = await authDecoders [ i ] ( token , type , { event, context } )
143+ decoded = await authDecoders [ i ] ( token , type , {
144+ // @TODO We will need to make a breaking change to auth decoders maybe
145+ event : event as any ,
146+ context,
147+ } )
140148 i ++
141149 }
142150
143- return [ decoded , { type, schema, token } , { event, context } ]
151+ // @TODO we need to rename this. It's not actually the token, because
152+ // some auth providers will have a cookie where we don't know the key
153+ return [ decoded , { type, schema, token } , { event : event as any , context } ]
144154}
0 commit comments