Class: Truelayer::AuthenticationRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/truelayer/authentication_repository.rb

Instance Method Summary collapse

Instance Method Details

#exchange_code(code, redirect_uri) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/truelayer/authentication_repository.rb', line 36

def exchange_code(code, redirect_uri)
  params = {
    grant_type: 'authorization_code',
    client_id: Truelayer.configuration.client_id,
    client_secret: Truelayer.configuration.client_secret,
    redirect_uri: redirect_uri,
    code: code
  }

  result = post('/connect/token', params: params)

  Token.build(json: result.body)
end


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/truelayer/authentication_repository.rb', line 14

def generate_direct_bank_link(provider_id:, consent_id:, redirect_uri:, scopes:, state: nil, tracking_id: nil, data_use_description: nil)
  params = {
    response_type: 'code',
    client_id: Truelayer.configuration.client_id,
    provider_id: provider_id,
    redirect_uri: redirect_uri,
    scope: scopes,
    consent_id: consent_id
  }

  params[:state] = state if state
  params[:tracking_id] = tracking_id if tracking_id
  params[:data_use_description] = data_use_description if data_use_description

  result = post('/v1/authuri', params: nil) do |req|
    req.headers[:content_type] = 'application/json'
    req.body = MultiJson.dump(params)
  end

  AuthLink.build(json: result.body)
end

#providersObject



63
64
65
66
67
68
69
# File 'lib/truelayer/authentication_repository.rb', line 63

def providers
  response = get('/api/providers', params: { clientId: Truelayer.configuration.client_id })

  (response.body || []).map do |result|
    Provider.build(json: result)
  end
end

#refresh_token(refresh_token) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/truelayer/authentication_repository.rb', line 50

def refresh_token(refresh_token)
  params = {
    grant_type: 'refresh_token',
    client_id: Truelayer.configuration.client_id,
    client_secret: Truelayer.configuration.client_secret,
    refresh_token: refresh_token
  }

  result = post('/connect/token', params: params)

  Token.build(json: result.body)
end