Class: LogStash::Filters::JWTDecode

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/filters/jwt-decode.rb

Overview

This filter will decode the jwt token in your message event and retrievs the values as specified in ‘extract_fields` and adds the extracted values to the event.

It is only intended to be used as an .

Instance Method Summary collapse

Instance Method Details

#filter(event) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/logstash/filters/jwt-decode.rb', line 40

def filter(event)
  if not @key
    decoded_token = JWT.decode event.get(@match), nil, false
  else
    decoded_token = JWT.decode event.get(@match), @key, true, {algorithm: @signature_alg}    
  end

  @extract_fields.each do |k, v| 
    event.set(k , getValueFromDecodedToken(v, decoded_token[0]))
  end
  # filter_matched should go in the last line of our successful code
  filter_matched(event)
end

#registerObject



32
33
34
35
36
37
# File 'lib/logstash/filters/jwt-decode.rb', line 32

def register
  # Add instance variables
  if @key && !@signature_alg
    raise LogStash::ConfigurationError, "signature_alg has to be specified if key is present "
  end  
end