Class: ServerlessHub::AuthorizerTokenDecoder

Inherits:
Object
  • Object
show all
Defined in:
lib/serverless_hub/authorizer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ AuthorizerTokenDecoder

Returns a new instance of AuthorizerTokenDecoder.



7
8
9
# File 'lib/serverless_hub/authorizer.rb', line 7

def initialize(app)
  @app = app
end

Class Method Details

.jwksObject



28
29
30
# File 'lib/serverless_hub/authorizer.rb', line 28

def self.jwks
  RestClient.get(ENV["JWKS_URL"] || "")
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/serverless_hub/authorizer.rb', line 11

def call(env)
  if env["HTTP_AUTHORIZATION"]
    tokens = decoded_token(env["HTTP_AUTHORIZATION"])

    if tokens.present?
      claims = tokens[0]

      env["lambda.event"]["requestContext"]["authorizer"] = {
        "principalId" => claims["sub"],
        "claims" => claims,
      }
    end
  end

  return @app.call(env)
end