class LogStash::Filters::JWTDecode

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 .

Public Instance Methods

filter(event) click to toggle source
# 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
register() click to toggle source
# 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

Private Instance Methods

getValueFromDecodedToken(key, decoded_token) click to toggle source
# File lib/logstash/filters/jwt-decode.rb, line 55
def getValueFromDecodedToken(key, decoded_token)
  key.split(".").each do |val, index| 
        if decoded_token.nil?
          return nil 
        end 
        decoded_token = decoded_token[val]
  end
  return decoded_token;   
end