Skip to content

Commit

Permalink
fixed jwt validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 7, 2021
1 parent 35f0462 commit 68a9ae3
Show file tree
Hide file tree
Showing 15 changed files with 7,277 additions and 73 deletions.
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ GEM
colorize (0.8.1)
commonmarker (0.21.2)
ruby-enum (~> 0.5)
concurrent-ruby (1.1.8)
concurrent-ruby (1.1.9)
config (2.2.3)
deep_merge (~> 1.2, >= 1.2.1)
dry-validation (~> 1.0, >= 1.0.0)
Expand Down Expand Up @@ -206,7 +206,7 @@ GEM
dry-configurable (0.12.1)
concurrent-ruby (~> 1.0)
dry-core (~> 0.5, >= 0.5.0)
dry-container (0.7.2)
dry-container (0.8.0)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (0.6.0)
Expand Down Expand Up @@ -331,7 +331,7 @@ GEM
hashie (4.1.0)
htmlentities (4.3.4)
http-accept (1.7.0)
http-cookie (1.0.3)
http-cookie (1.0.4)
domain_name (~> 0.5)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -384,15 +384,15 @@ GEM
logstash-event (1.2.02)
logstash-logger (0.26.1)
logstash-event (~> 1.2)
loofah (2.9.1)
loofah (2.10.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
mailgun-ruby (1.2.4)
rest-client (>= 2.0.2)
marcel (1.0.1)
maremma (4.7.4)
maremma (4.9.2)
activesupport (>= 4.2.5)
addressable (>= 2.3.6)
builder (~> 3.2, >= 3.2.2)
Expand Down
1 change: 0 additions & 1 deletion app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def github
end

def globus
puts request.env["omniauth.auth"]
auth = request.env["omniauth.auth"]

if current_user.present?
Expand Down
8 changes: 4 additions & 4 deletions app/models/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def process_data(options = {})

def collect_data(options = {})
# already claimed
return OpenStruct.new(body: { "skip" => true, "reason" => "already claimed." }) if to_be_created? && put_code.present?
# return OpenStruct.new(body: { "skip" => true, "reason" => "already claimed." }) if to_be_created? && put_code.present?

# user has not signed up yet or orcid_token is missing
if user.blank? || orcid_token.blank?
Expand All @@ -258,16 +258,16 @@ def collect_data(options = {})
return OpenStruct.new(body: { "skip" => true, "reason" => "Too many claims. Only 10,000 claims allowed." }) if user.claims.total_count > 10000

# missing data raise errors
return OpenStruct.new(body: { "errors" => [{ "title" => "Missing data" }] }) if work.data.nil?
# return OpenStruct.new(body: { "errors" => [{ "title" => "Missing data" }] }) if work.data.nil?

# validate data
return OpenStruct.new(body: { "errors" => work.validation_errors.map { |error| { "title" => error } } }) if work.validation_errors.present?

options[:sandbox] = (ENV["ORCID_URL"] == "https://sandbox.orcid.org")

# create or delete entry in ORCID record
# create or delete entry in ORCID record. If put_code exists, update entry
if to_be_created?
work.create_work(options)
put_code.present? ? work.update_work(options) : work.create_work(options)
elsif to_be_deleted?
work.delete_work(options)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/authenticable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def decode_token(token)
payload = (JWT.decode token, public_key, true, algorithm: "RS256").first

# check whether token has expired
return {} unless Time.now.to_i < payload["exp"]
return {} unless Time.now.to_i < payload["exp"].to_i

payload
rescue JWT::DecodeError => e
Expand Down
195 changes: 195 additions & 0 deletions spec/fixtures/vcr_cassettes/Claim/collect_data/already_exists.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 68a9ae3

Please sign in to comment.