Module: GovFakeNotify::CurrentService

Included in:
NotificationsApp, RootApp, TemplatesApp
Defined in:
lib/gov_fake_notify/current_service.rb

Instance Method Summary collapse

Instance Method Details

#current_service(store: Store.instance) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/gov_fake_notify/current_service.rb', line 3

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

#validate_jwt(token, secret) ⇒ Object



15
16
17
18
19
20
# File 'lib/gov_fake_notify/current_service.rb', line 15

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