Sha256: c3868f6d0ee47e236a62889d22d6b253e5ce9de7eceb972506c7b768f476c674

Contents?: true

Size: 906 Bytes

Versions: 2

Compression:

Stored size: 906 Bytes

Contents

require 'digest/md5'

module Ipizza::Provider
  class Nordea::AuthenticationResponse < Ipizza::AuthenticationResponse
    
    def initialize(params)
      @params = params
    end

    def verify(key_path)
      key = File.read(key_path).strip
      @valid = @params['B02K_MAC'] == Digest::MD5.hexdigest(mac_data_string(key)).upcase
    end
    
    def success?
      @valid && @params['B02K_CUSTID'].present?
    end
    
    def valid?
      @valid
    end
    
    def user_info
      valid? ? {'name' => @params['B02K_CUSTNAME'], 'custid' => @params['B02K_CUSTID']} : {}
    end
    
    private
    
    def mac_data_string(key)
      order = ['VERS', 'TIMESTMP', 'IDNBR', 'STAMP', 'CUSTNAME', 'KEYVERS', 'ALG', 'CUSTID', 'CUSTTYPE']
      
      datastr = order.inject('') do |memo, param|
        memo << @params["B02K_#{param}"].to_s << '&'
      end
      datastr << key << '&'
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ipizza-0.4.1 lib/ipizza/provider/nordea/authentication_response.rb
ipizza-0.4.0 lib/ipizza/provider/nordea/authentication_response.rb