Skip to content

Commit

Permalink
Include useparagon/connect javascript assets
Browse files Browse the repository at this point in the history
  • Loading branch information
candanedo committed Feb 15, 2024
1 parent c2b75f1 commit 36c1f19
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions lib/use_paragon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "use_paragon/configuration"
require "use_paragon/base"
require "use_paragon/engine"
require "use_paragon/integration"
require "use_paragon/user"
require "use_paragon/version"
Expand Down
23 changes: 9 additions & 14 deletions lib/use_paragon/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

module UseParagon
# Basic logic for interacting with UseParagon platform
# Handles authentication and requests to Paragon API base on:
# https://docs.useparagon.com/getting-started/installing-the-connect-sdk#setup-with-your-own-authentication-backend
class Base
attr_reader :token, :user_id

Expand All @@ -15,6 +17,7 @@ def initialize(user_id)
end

def generate_token
# Paragon User Token for each of your authenticated user
validate_user_id!

rsa_private = OpenSSL::PKey::RSA.new(config.private_key)
Expand All @@ -33,27 +36,19 @@ def generate_token

def connection
@connection ||= Faraday.new do |conn|
conn.request :authorization, "Bearer", generate_token
conn.response :logger, Rails.logger, { errors: true, bodies: true }

conn.url_prefix = config.base_url
conn.request :authorization, "Bearer", generate_token
conn.request :json

if config.logger_enabled
conn.response :logger, Rails.logger, { errors: true, bodies: true }
end

conn.response :json, content_type: "application/json"
conn.response :raise_error
end
end

def logger(conn)
conn.response :logger, Rails.logger, { errors: true, bodies: true } do |logger|
logger.filter(/(Authorization:)([^&]+)/, '\1[REMOVED]')
logger.filter(/("code":)([^&]+)/, '\1[REMOVED]')
end
end

def logger_enabled?
ENV.fetch("USEPARAGON_API_LOGGER", "false") == "true"
end

def path(endpoint)
"/projects/#{config.project_id}/#{endpoint}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/use_paragon/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module UseParagon
# Allows configuration using an initializer
class Configuration
attr_accessor :private_key, :project_id, :base_url
attr_accessor :private_key, :project_id, :base_url, :logger_enabled

def initialize
@base_url = "https://zeus.useparagon.com"
Expand Down
7 changes: 7 additions & 0 deletions lib/use_paragon/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module UseParagon
class Engine < ::Rails::Engine
initializer "use_paragon.assets.precompile" do |app|
app.config.assets.precompile += %w( useparagon/connect.js )
end
end
end
3 changes: 0 additions & 3 deletions use_paragon.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,4 @@ Gem::Specification.new do |spec|

spec.add_dependency "faraday"
spec.add_dependency "jwt"

# For more information and examples about making a new gem, checkout our
# guide at: https://bundler.io/guides/creating_gem.html
end
2 changes: 2 additions & 0 deletions vendor/assets/javascripts/useparagon/connect.js

Large diffs are not rendered by default.

0 comments on commit 36c1f19

Please sign in to comment.