authsignal-ruby 1.0.1 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a28bb75e7f376bd32e42089da85e158e837557c0c491e93bc3f3403efb8c49c
4
- data.tar.gz: 401254646dabee360ca33d7ced34e2b19a6806d908dadc495c3308aabeaed7b9
3
+ metadata.gz: 5ca1d4818fc1ff9c662b04b0fce7b3ad532b081826d8418ea6d359e681bcd0cc
4
+ data.tar.gz: de37f34d38fc6e63ef6011c86f363b05f60121ddb9fb4ed65401578ef189b55f
5
5
  SHA512:
6
- metadata.gz: b2e8ecf5359161a227b47c86a17f73816b51617a48dc56d60879cecdbd0962245c176700b1f1005080ad68de4b991b194175ad781679f0b373ebb43853c27af3
7
- data.tar.gz: af15344d7b5d3769e86ac9c0087e1e777d84683f96ff107ebf612dbe39c46147e20f6c9e260bf6977e233d8a5fe20de30cc4eed5038c9659094ad6db7abd7b92
6
+ metadata.gz: 5b4b25771cbe3d0ed5a7614a72822dd8dc4b63c1919bfed01fe63c2771b107b552c637aceee4a4c0253b6cf7f4cea1be18243843297e8909e907ab7d9d3931e7
7
+ data.tar.gz: fc07cba6d3564da885b71b4883df830fb08c91cba961b0d07d76a71d513e6c5175514ba5f0a749cb65a971b9a3606a7f63dadd437628d0a795ebf98428a02a12
data/Gemfile CHANGED
@@ -4,5 +4,3 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in authsignal-ruby.gemspec
6
6
  gemspec
7
-
8
- gem 'jwt'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authsignal-ruby (1.0.1)
4
+ authsignal-ruby (2.1.1)
5
5
  httparty (~> 0.21.0)
6
6
 
7
7
  GEM
@@ -16,7 +16,6 @@ GEM
16
16
  httparty (0.21.0)
17
17
  mini_mime (>= 1.0.0)
18
18
  multi_xml (>= 0.5.2)
19
- jwt (2.7.1)
20
19
  mini_mime (1.1.5)
21
20
  multi_xml (0.6.0)
22
21
  public_suffix (4.0.7)
@@ -45,7 +44,6 @@ PLATFORMS
45
44
 
46
45
  DEPENDENCIES
47
46
  authsignal-ruby!
48
- jwt
49
47
  rake (~> 13.0)
50
48
  rspec (~> 3.2)
51
49
  webmock (~> 3.14.0)
@@ -4,6 +4,13 @@ module Authsignal
4
4
  NO_API_KEY_MESSAGE = "No Authsignal API Secret Key Set"
5
5
  include HTTParty
6
6
 
7
+ def handle_response(response)
8
+ unless response.success?
9
+ raise HTTParty::ResponseError, "Failed with status code #{response.code}"
10
+ end
11
+ response
12
+ end
13
+
7
14
  def initialize
8
15
  self.class.base_uri Authsignal.configuration.base_uri
9
16
  @api_key = require_api_key
@@ -37,8 +44,20 @@ module Authsignal
37
44
  get(path)
38
45
  end
39
46
 
40
- def get_action(user_id, action_code, idempotency_key)
41
- get("/users/#{ERB::Util.url_encode(user_id)}/actions/#{action_code}/#{ERB::Util.url_encode(idempotency_key)}")
47
+ def update_user(user_id:, user:)
48
+ post("/users/#{ERB::Util.url_encode(user_id)}", body: JSON.generate(user))
49
+ end
50
+
51
+ def validate_challenge(user_id: nil, token:)
52
+ path = "/validate"
53
+
54
+ response = post(path, query: {}, body: { userId: user_id, token: token }.to_json)
55
+
56
+ handle_response(response)
57
+ end
58
+
59
+ def get_action(user_id, action, idempotency_key)
60
+ get("/users/#{ERB::Util.url_encode(user_id)}/actions/#{action}/#{ERB::Util.url_encode(idempotency_key)}")
42
61
  end
43
62
 
44
63
  def identify(user_id, user_payload)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Authsignal
4
- VERSION = "1.0.1"
4
+ VERSION = "2.1.1"
5
5
  end
data/lib/authsignal.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "httparty"
2
- require 'jwt'
3
2
 
4
3
  require "authsignal/version"
5
4
  require "authsignal/client"
@@ -27,8 +26,13 @@ module Authsignal
27
26
  response.transform_keys { |key| underscore(key) }.transform_keys(&:to_sym)
28
27
  end
29
28
 
30
- def get_action(user_id:, action_code:, idempotency_key:)
31
- response = Client.new.get_action(user_id, action_code, idempotency_key)
29
+ def update_user(user_id:, user:)
30
+ response = Client.new.update_user(user_id: user_id, user: user)
31
+ response.transform_keys { |key| underscore(key) }.transform_keys(&:to_sym)
32
+ end
33
+
34
+ def get_action(user_id:, action:, idempotency_key:)
35
+ response = Client.new.get_action(user_id, action, idempotency_key)
32
36
  response.transform_keys { |key| underscore(key) }.transform_keys(&:to_sym)
33
37
  end
34
38
 
@@ -66,33 +70,10 @@ module Authsignal
66
70
  end
67
71
 
68
72
  def validate_challenge(token:, user_id: nil)
69
- begin
70
- decoded_token = JWT.decode(token, Authsignal.configuration.api_secret_key)[0]
71
- rescue JWT::DecodeError
72
- puts 'Token verification failed'
73
- end
74
-
75
- decoded_user_id = decoded_token["other"]["userId"]
76
- action_code = decoded_token["other"]["actionCode"]
77
- idempotency_key = decoded_token["other"]["idempotencyKey"]
78
-
79
- if user_id && user_id != decoded_user_id
80
- return { user_id: decoded_user_id, success: false, state: nil }
81
- end
82
-
83
- if action_code && idempotency_key
84
- action_result = get_action(user_id: decoded_user_id, action_code: action_code, idempotency_key: idempotency_key)
85
-
86
- if action_result
87
- state = action_result[:state]
88
- success = state == "CHALLENGE_SUCCEEDED"
89
-
90
- return { user_id: decoded_user_id, success: success, state: state, action: action_code }
91
- end
92
- end
93
-
94
- { user_id: decoded_user_id, success: false, state: nil }
95
- end
73
+ response = Client.new.validate_challenge(user_id: user_id, token: token)
74
+
75
+ return { user_id: response["userId"], is_valid: response["isValid"], state: response["state"], action: response["actionCode"] }
76
+ end
96
77
 
97
78
  private
98
79
  def underscore(string)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authsignal-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - justinsoong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-30 00:00:00.000000000 Z
11
+ date: 2024-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.14.0
69
69
  description: Authsignal is a passwordless authentication/multifactor authentication
70
- step up service with a FraudOps rules engine
70
+ with modern factors like passkeys
71
71
  email:
72
72
  - justin@authsignal.com
73
73
  executables: []
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
- rubygems_version: 3.4.10
112
+ rubygems_version: 3.5.11
113
113
  signing_key:
114
114
  specification_version: 4
115
115
  summary: The Authsignal ruby server side signal API.