serverless-offline 10.2.0 → 10.2.1

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "dedicatedTo": "Blue, a great migrating bird.",
3
3
  "name": "serverless-offline",
4
- "version": "10.2.0",
4
+ "version": "10.2.1",
5
5
  "description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
6
6
  "license": "MIT",
7
7
  "exports": {
@@ -92,10 +92,10 @@
92
92
  "execa": "^6.1.0",
93
93
  "fs-extra": "^10.1.0",
94
94
  "java-invoke-local": "0.0.6",
95
+ "jose": "^4.9.3",
95
96
  "js-string-escape": "^1.0.1",
96
97
  "jsonpath-plus": "^7.2.0",
97
98
  "jsonschema": "^1.4.1",
98
- "jsonwebtoken": "^8.5.1",
99
99
  "jszip": "^3.10.1",
100
100
  "luxon": "^3.0.3",
101
101
  "node-fetch": "^3.2.10",
@@ -65,9 +65,9 @@ export default class ServerlessOffline {
65
65
  const { httpEvents, lambdas, scheduleEvents, webSocketEvents } =
66
66
  this.#getEvents()
67
67
 
68
- // if (lambdas.length > 0) {
69
- await this.#createLambda(lambdas)
70
- // }
68
+ if (lambdas.length > 0) {
69
+ await this.#createLambda(lambdas)
70
+ }
71
71
 
72
72
  const eventModules = []
73
73
 
@@ -440,7 +440,7 @@ export default class HttpServer {
440
440
  !this.#apiKeysValues.has(apiKey)
441
441
  ) {
442
442
  log.debug(
443
- `Method ${method} of function ${functionKey} token ${apiKey} not valid`,
443
+ `Method '${method}' of function '${functionKey}' token '${apiKey}' not valid.`,
444
444
  )
445
445
 
446
446
  return errorResponse()
@@ -452,15 +452,18 @@ export default class HttpServer {
452
452
  ) {
453
453
  const { usageIdentifierKey } = request.auth.credentials
454
454
 
455
- if (usageIdentifierKey !== this.#options.apiKey) {
455
+ if (
456
+ usageIdentifierKey !== this.#options.apiKey &&
457
+ !this.#apiKeysValues.has(usageIdentifierKey)
458
+ ) {
456
459
  log.debug(
457
- `Method ${method} of function ${functionKey} token ${usageIdentifierKey} not valid`,
460
+ `Method '${method}' of function '${functionKey}' token '${usageIdentifierKey}' not valid.`,
458
461
  )
459
462
 
460
463
  return errorResponse()
461
464
  }
462
465
  } else {
463
- log.debug(`Missing x-api-key on private function ${functionKey}`)
466
+ log.debug(`Missing 'x-api-key' on private function '${functionKey}'.`)
464
467
 
465
468
  return errorResponse()
466
469
  }
@@ -1,6 +1,6 @@
1
1
  import Boom from '@hapi/boom'
2
2
  import { log } from '@serverless/utils/log.js'
3
- import { decode } from 'jsonwebtoken'
3
+ import { decodeJwt } from 'jose'
4
4
 
5
5
  const { isArray } = Array
6
6
 
@@ -35,18 +35,14 @@ export default function createAuthScheme(jwtOptions) {
35
35
  }
36
36
 
37
37
  try {
38
- const decoded = decode(jwtToken, { complete: true })
39
- if (!decoded) {
40
- return Boom.unauthorized('JWT not decoded')
41
- }
38
+ const claims = decodeJwt(jwtToken)
42
39
 
43
- const expirationDate = new Date(decoded.payload.exp * 1000)
40
+ const expirationDate = new Date(claims.exp * 1000)
44
41
  if (expirationDate.valueOf() < Date.now()) {
45
42
  return Boom.unauthorized('JWT Token expired')
46
43
  }
47
44
 
48
- const { aud, iss, scope } = decoded.payload
49
- const clientId = decoded.payload.client_id
45
+ const { aud, iss, scope, client_id: clientId } = claims
50
46
  if (iss !== jwtOptions.issuerUrl) {
51
47
  log.notice(`JWT Token not from correct issuer url`)
52
48
 
@@ -91,7 +87,7 @@ export default function createAuthScheme(jwtOptions) {
91
87
  // return resolve(
92
88
  return h.authenticated({
93
89
  credentials: {
94
- claims: decoded.payload,
90
+ claims,
95
91
  scopes,
96
92
  },
97
93
  })
@@ -1,7 +1,7 @@
1
1
  import { Buffer } from 'node:buffer'
2
2
  import { env } from 'node:process'
3
3
  import { log } from '@serverless/utils/log.js'
4
- import { decode } from 'jsonwebtoken'
4
+ import { decodeJwt } from 'jose'
5
5
  import {
6
6
  createUniqueId,
7
7
  formatToClfTime,
@@ -122,8 +122,8 @@ export default class LambdaProxyIntegrationEvent {
122
122
 
123
123
  if (token) {
124
124
  try {
125
- claims = decode(token) || undefined
126
- if (claims && claims.scope) {
125
+ claims = decodeJwt(token)
126
+ if (claims.scope) {
127
127
  scopes = claims.scope.split(' ')
128
128
  // In AWS HTTP Api the scope property is removed from the decoded JWT
129
129
  // I'm leaving this property because I'm not sure how all of the authorizers
@@ -1,7 +1,7 @@
1
1
  import { Buffer } from 'node:buffer'
2
2
  import { env } from 'node:process'
3
3
  import { log } from '@serverless/utils/log.js'
4
- import { decode } from 'jsonwebtoken'
4
+ import { decodeJwt } from 'jose'
5
5
  import {
6
6
  formatToClfTime,
7
7
  lowerCaseKeys,
@@ -105,8 +105,8 @@ export default class LambdaProxyIntegrationEventV2 {
105
105
 
106
106
  if (token) {
107
107
  try {
108
- claims = decode(token) || undefined
109
- if (claims && claims.scope) {
108
+ claims = decodeJwt(token)
109
+ if (claims.scope) {
110
110
  scopes = claims.scope.split(' ')
111
111
  // In AWS HTTP Api the scope property is removed from the decoded JWT
112
112
  // I'm leaving this property because I'm not sure how all of the authorizers
@@ -1,7 +1,7 @@
1
1
  import { Buffer } from 'node:buffer'
2
2
  import { env } from 'node:process'
3
3
  import jsEscapeString from 'js-string-escape'
4
- import { decode } from 'jsonwebtoken'
4
+ import { decodeJwt } from 'jose'
5
5
  import {
6
6
  createUniqueId,
7
7
  isPlainObject,
@@ -83,10 +83,7 @@ export default class VelocityContext {
83
83
 
84
84
  if (token) {
85
85
  try {
86
- const claims = decode(token) || undefined
87
- if (claims) {
88
- assign(authorizer, { claims })
89
- }
86
+ assign(authorizer, { claims: decodeJwt(token) })
90
87
  } catch {
91
88
  // Nothing
92
89
  }
@@ -30,7 +30,7 @@ export default class HttpServer {
30
30
  }
31
31
 
32
32
  async createServer() {
33
- const { host, websocketPort, httpsProtocol } = this.#options
33
+ const { host, httpsProtocol, websocketPort } = this.#options
34
34
 
35
35
  const serverOptions = {
36
36
  host,