From fcd3293d3bd5235ae86dc5e2be420e32b786b461 Mon Sep 17 00:00:00 2001 From: Yann Guillon Date: Thu, 11 Aug 2022 14:22:48 +0200 Subject: [PATCH] add events --- app.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app.rb b/app.rb index 5e0ce18..d12d494 100644 --- a/app.rb +++ b/app.rb @@ -61,6 +61,31 @@ wallets_response.body.to_json end +get '/wallets/:id/events' do + conn = Faraday.new( + url: ENV['VUE_APP_VENLY_LOGIN_URL'], + headers: {'Content-Type' => 'application/x-www-form-urlencoded'} + ) + + response = conn.post('/auth/realms/Arkane/protocol/openid-connect/token') do |req| + req.body = URI.encode_www_form({ + grant_type: 'client_credentials', + client_id: ENV['VUE_APP_VENLY_CLIENT_ID'], + client_secret: ENV['VUE_APP_SECRET_ID'] + }) + end + token = JSON.parse(response.body)['access_token'] + pp token + content_type :json + conn = Faraday.new( + url: ENV['VUE_APP_VENLY_API_URL'], + headers: {'Content-Type' => 'application/json', 'Authorization' => "Bearer #{token}" } + ) + wallets_response = conn.get("/api/wallets/#{params['id']}/events") + content_type :json + wallets_response.body.to_json +end + options "*" do response.headers["Allow"] = "GET, PUT, POST, DELETE, OPTIONS" response.headers["Access-Control-Allow-Headers"] = "Authorization, Content-Type, Accept, X-User-Email, X-Auth-Token"