Sha256: 6cd7c162a6f62b4732369e022952d19ac4248edfbef923141194638265846722

Contents?: true

Size: 544 Bytes

Versions: 5

Compression:

Stored size: 544 Bytes

Contents

module GovFakeNotify
  module CurrentService
    def current_service(store: Store.instance)
      header = request.headers['Authorization'].gsub(/^Bearer /, '')
      store.transaction do
        store.roots.each do |root|
          next unless root.start_with?('apikey')

          return store[root].dup if validate_jwt(header, store[root]['secret_token'])
        end
      end
      nil
    end

    def validate_jwt(token, secret)
      JWT.decode token, secret, 'HS256'
      true
    rescue JWT::DecodeError
      false
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gov_fake_notify-2.0.0 lib/gov_fake_notify/current_service.rb
gov_fake_notify-1.2.0 lib/gov_fake_notify/current_service.rb
gov_fake_notify-1.1.3 lib/gov_fake_notify/current_service.rb
gov_fake_notify-1.1.2 lib/gov_fake_notify/current_service.rb
gov_fake_notify-1.1.1 lib/gov_fake_notify/current_service.rb