@@ -11,12 +11,16 @@ const _ = require('lodash');
11
11
module . exports = function createAuthScheme ( authFun , authorizerOptions , funName , endpointPath , options , serverlessLog , servicePath , serverless ) {
12
12
const authFunName = authorizerOptions . name ;
13
13
14
- const identitySourceMatch = / ^ m e t h o d .r e q u e s t .h e a d e r .( (?: \w + - ? ) + \w + ) $ / . exec ( authorizerOptions . identitySource ) ;
15
- if ( ! identitySourceMatch || identitySourceMatch . length !== 2 ) {
16
- throw new Error ( `Serverless Offline only supports retrieving tokens from the headers (λ: ${ authFunName } )` ) ;
14
+ let identityHeader = 'authorization' ;
15
+
16
+ if ( authorizerOptions . type !== 'request' ) {
17
+ const identitySourceMatch = / ^ m e t h o d .r e q u e s t .h e a d e r .( (?: \w + - ? ) + \w + ) $ / . exec ( authorizerOptions . identitySource ) ;
18
+ if ( ! identitySourceMatch || identitySourceMatch . length !== 2 ) {
19
+ throw new Error ( `Serverless Offline only supports retrieving tokens from the headers (λ: ${ authFunName } )` ) ;
20
+ }
21
+ identityHeader = identitySourceMatch [ 1 ] . toLowerCase ( ) ;
17
22
}
18
-
19
- const identityHeader = identitySourceMatch [ 1 ] . toLowerCase ( ) ;
23
+
20
24
const funOptions = functionHelper . getFunctionOptions ( authFun , funName , servicePath ) ;
21
25
22
26
// Create Auth Scheme
@@ -28,9 +32,6 @@ module.exports = function createAuthScheme(authFun, authorizerOptions, funName,
28
32
29
33
// Get Authorization header
30
34
const req = request . raw . req ;
31
- const authorization = req . headers [ identityHeader ] ;
32
-
33
- debugLog ( `Retrieved ${ identityHeader } header ${ authorization } ` ) ;
34
35
35
36
// Get path params
36
37
const pathParams = { } ;
@@ -49,12 +50,14 @@ module.exports = function createAuthScheme(authFun, authorizerOptions, funName,
49
50
type : 'REQUEST' ,
50
51
path : request . path ,
51
52
httpMethod : request . method . toUpperCase ( ) ,
52
- headers : request . headers ,
53
+ headers : Object . assign ( request . headers , utils . capitalizeKeys ( request . headers ) ) ,
53
54
pathParameters : utils . nullIfEmpty ( pathParams ) ,
54
55
queryStringParameters : utils . nullIfEmpty ( request . query ) ,
55
56
} ;
56
57
}
57
58
else {
59
+ const authorization = req . headers [ identityHeader ] ;
60
+ debugLog ( `Retrieved ${ identityHeader } header ${ authorization } ` ) ;
58
61
event = {
59
62
type : 'TOKEN' ,
60
63
authorizationToken : authorization ,
0 commit comments