Skip to content

Commit

Permalink
Aut-1323 use named arguments for validate challenge input (#12)
Browse files Browse the repository at this point in the history
* AUT-1323 use named arguments for validate_challenge input

* Bump version

* Update Gemfile.lock
  • Loading branch information
stevenclouston committed Aug 24, 2023
1 parent 71173f4 commit 33ca3d9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
authsignal-ruby (0.1.5)
authsignal-ruby (0.1.6)
httparty (~> 0.21.0)

GEM
Expand Down
16 changes: 7 additions & 9 deletions lib/authsignal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,35 +69,33 @@ def track_action(event, options={})
false
end

def validate_challenge(request)
token = request[:token]

def validate_challenge(user_id:, token:)
begin
decoded_token = JWT.decode(token, Authsignal.configuration.api_secret_key)[0]
rescue JWT::DecodeError
puts 'Token verification failed'
end

user_id = decoded_token["other"]["userId"]
decoded_user_id = decoded_token["other"]["userId"]
action_code = decoded_token["other"]["actionCode"]
idempotency_key = decoded_token["other"]["idempotencyKey"]

if request[:userId] && request[:userId] != user_id
return { user_id: user_id, success: false, state: nil }
if user_id != decoded_user_id
return { user_id: decoded_user_id, success: false, state: nil }
end

if action_code && idempotency_key
action_result = get_action(user_id: user_id, action_code: action_code, idempotency_key: idempotency_key)
action_result = get_action(user_id: decoded_user_id, action_code: action_code, idempotency_key: idempotency_key)

if action_result
state = action_result[:state]
success = state == "CHALLENGE_SUCCEEDED"

return { user_id: user_id, success: success, state: state, action: action_code }
return { user_id: decoded_user_id, success: success, state: state, action: action_code }
end
end

{ user_id: user_id, success: false, state: nil }
{ user_id: decoded_user_id, success: false, state: nil }
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/authsignal/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Authsignal
VERSION = "0.1.5"
VERSION = "0.1.6"
end

0 comments on commit 33ca3d9

Please sign in to comment.