-
Notifications
You must be signed in to change notification settings - Fork 1
/
configuration.rb
64 lines (53 loc) · 1.86 KB
/
configuration.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true
module Tikkie
module Api
module V1
# Tikkie API Configuration. An API Key and private key are mandatory.
# see https://developer.abnamro.com/get-started
class Configuration
SANDBOX_API_URL = "https://api-sandbox.abnamro.com/v1/"
PRODUCTION_API_URL = "https://api.abnamro.com/v1/"
SANDBOX_OAUTH_TOKEN_URL = "https://auth-sandbox.abnamro.com/oauth/token"
PRODUCTION_OAUTH_TOKEN_URL = "https://auth.abnamro.com/oauth/token"
DEFAULT_HASHING_ALGORITHM = "RS256"
VALID_HASHING_ALGORITHMS = %w[RS256 RS384 RS512].freeze
attr_reader :api_key, :private_key, :options
def initialize(api_key, private_key, options = {})
@api_key = api_key
@private_key = private_key
@options = options
end
def private_data
unless File.exist?(@private_key)
raise Tikkie::Api::V1::Exception, "Private key does not exist: #{@private_key}"
end
OpenSSL::PKey::RSA.new(File.read(@private_key))
end
def jwt_hashing_algorithm
if @options[:hashing_algorithm]
unless VALID_HASHING_ALGORITHMS.include?(@options[:hashing_algorithm])
raise Tikkie::Api::V1::Exception, "Invalid hashing algorithm provided: #{@options[:hashing_algorithm]} (expected: #{VALID_HASHING_ALGORITHMS.join(', ')})"
end
@options[:hashing_algorithm]
else
DEFAULT_HASHING_ALGORITHM
end
end
def api_url
if @options[:test]
SANDBOX_API_URL
else
PRODUCTION_API_URL
end
end
def oauth_token_url
if @options[:test]
SANDBOX_OAUTH_TOKEN_URL
else
PRODUCTION_OAUTH_TOKEN_URL
end
end
end
end
end
end