authsignal-ruby 0.1.5 → 1.0.0

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: f77d1646d619436a3c5e25b76be690252c3f4bf2dcb7588ea09cae4c11283017
4
- data.tar.gz: 67ad78b10cb51e07b2f2726a4a8ad74ba094eacd37b0acd6436a4e89f9b7d306
3
+ metadata.gz: 561440221a5ef9e66e1b0094958c6ea9b74e6299579bdcf3d38882de19f40f9c
4
+ data.tar.gz: c364e721d2726a9f59fa3e2fb807bd14e4397c73664a73acd4929edcb693e3fd
5
5
  SHA512:
6
- metadata.gz: a02302caa711e51e25877b73e2b83c074ebd868e9f43eec42d0b29046f0f62a99ec07a930e73eb4204cffab72992831395e36b8f6d6a6a01e010536e2c550286
7
- data.tar.gz: 5791b35e320bc81ca7f7137f736f847f7b2eae79073afe9eed0c91376e557dd63c2e0d952bf42d2d15dd04eac3c6827e003283e63e0f95f3cb681d4d3714ee3e
6
+ metadata.gz: 0af6f0ee6b672e2694fb3fcb4d26084c160d34a25a279b8ac3e4272d207f63f75bf5f1a9e5a9990921ee853813bc738cc5e53620cf34413088fbb2f9734e6948
7
+ data.tar.gz: b069887fc72d20b96ccc369a50749dac540ffebfbf03bf5e104132def1a99cdf78ed7172d0e2f4b6289752ce1db664c77d0548432e44d0203dfd71c37547f0ac
data/Gemfile CHANGED
@@ -4,3 +4,5 @@ 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 (0.1.5)
4
+ authsignal-ruby (1.0.0)
5
5
  httparty (~> 0.21.0)
6
6
 
7
7
  GEM
@@ -16,6 +16,7 @@ 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)
19
20
  mini_mime (1.1.5)
20
21
  multi_xml (0.6.0)
21
22
  public_suffix (4.0.7)
@@ -44,6 +45,7 @@ PLATFORMS
44
45
 
45
46
  DEPENDENCIES
46
47
  authsignal-ruby!
48
+ jwt
47
49
  rake (~> 13.0)
48
50
  rspec (~> 3.2)
49
51
  webmock (~> 3.14.0)
data/README.md CHANGED
@@ -53,13 +53,13 @@ end
53
53
 
54
54
  ## Usage
55
55
 
56
- Authsignal's server side signal API has four main api calls `track_action`, `get_action`, `get_user`, `enrol_authenticator`.
56
+ Authsignal's server side signal API has four main api calls `track`, `get_action`, `get_user`, `enroll_verified_authenticator`.
57
57
 
58
- For more details on these api calls, refer to our [official Ruby SDK docs](https://docs.authsignal.com/sdks/server/ruby#track_action).
58
+ For more details on these api calls, refer to our [official Ruby SDK docs](https://docs.authsignal.com/sdks/server/ruby#track).
59
59
 
60
60
  ## Development
61
61
 
62
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` or `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
63
 
64
64
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
65
 
@@ -19,7 +19,7 @@ module Authsignal
19
19
  end
20
20
 
21
21
  def track(action, options = {})
22
- actionCode = action[:actionCode]
22
+ actionCode = action[:action]
23
23
  idempotencyKey = ERB::Util.url_encode(action[:idempotencyKey])
24
24
  userId = ERB::Util.url_encode(action[:userId])
25
25
  body = action.except(:userId, :actionCode)
@@ -45,7 +45,7 @@ module Authsignal
45
45
  post("/users/#{ERB::Util.url_encode(user_id)}", body: JSON.generate(user_payload))
46
46
  end
47
47
 
48
- def enrol_authenticator(user_id, authenticator)
48
+ def enroll_verified_authenticator(user_id, authenticator)
49
49
  post("/users/#{ERB::Util.url_encode(user_id)}/authenticators", body: JSON.generate(authenticator))
50
50
  end
51
51
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Authsignal
4
- VERSION = "0.1.5"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/authsignal.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "httparty"
2
+ require 'jwt'
2
3
 
3
4
  require "authsignal/version"
4
5
  require "authsignal/client"
@@ -31,14 +32,9 @@ module Authsignal
31
32
  response.transform_keys { |key| underscore(key) }.transform_keys(&:to_sym)
32
33
  end
33
34
 
34
- def identify(user_id:, user:)
35
- response = Client.new.identify(user_id, user)
36
- response.transform_keys { |key| underscore(key) }.transform_keys(&:to_sym)
37
- end
38
-
39
- def enrol_authenticator(user_id:, authenticator:)
35
+ def enroll_verified_authenticator(user_id:, authenticator:)
40
36
  authenticator = authenticator.transform_keys { |key| camelize(key) }
41
- response = Client.new.enrol_authenticator(user_id, authenticator)
37
+ response = Client.new.enroll_verified_authenticator(user_id, authenticator)
42
38
 
43
39
  if response["authenticator"]
44
40
  response["authenticator"] = response["authenticator"].transform_keys { |key| underscore(key) }.transform_keys(&:to_sym)
@@ -49,8 +45,8 @@ module Authsignal
49
45
  response
50
46
  end
51
47
 
52
- def track_action(event, options={})
53
- raise ArgumentError, "Action Code is required" unless event[:action_code].to_s.length > 0
48
+ def track(event, options={})
49
+ raise ArgumentError, "Action Code is required" unless event[:action].to_s.length > 0
54
50
  raise ArgumentError, "User ID value" unless event[:user_id].to_s.length > 0
55
51
 
56
52
  event = event.transform_keys { |key| camelize(key) }
@@ -69,35 +65,33 @@ module Authsignal
69
65
  false
70
66
  end
71
67
 
72
- def validate_challenge(request)
73
- token = request[:token]
74
-
68
+ def validate_challenge(user_id:, token:)
75
69
  begin
76
70
  decoded_token = JWT.decode(token, Authsignal.configuration.api_secret_key)[0]
77
71
  rescue JWT::DecodeError
78
72
  puts 'Token verification failed'
79
73
  end
80
74
 
81
- user_id = decoded_token["other"]["userId"]
75
+ decoded_user_id = decoded_token["other"]["userId"]
82
76
  action_code = decoded_token["other"]["actionCode"]
83
77
  idempotency_key = decoded_token["other"]["idempotencyKey"]
84
78
 
85
- if request[:userId] && request[:userId] != user_id
86
- return { user_id: user_id, success: false, state: nil }
79
+ if user_id && user_id != decoded_user_id
80
+ return { user_id: decoded_user_id, success: false, state: nil }
87
81
  end
88
82
 
89
83
  if action_code && idempotency_key
90
- action_result = get_action(user_id: user_id, action_code: action_code, idempotency_key: idempotency_key)
84
+ action_result = get_action(user_id: decoded_user_id, action_code: action_code, idempotency_key: idempotency_key)
91
85
 
92
86
  if action_result
93
87
  state = action_result[:state]
94
88
  success = state == "CHALLENGE_SUCCEEDED"
95
89
 
96
- return { user_id: user_id, success: success, state: state, action: action_code }
90
+ return { user_id: decoded_user_id, success: success, state: state, action: action_code }
97
91
  end
98
92
  end
99
93
 
100
- { user_id: user_id, success: false, state: nil }
94
+ { user_id: decoded_user_id, success: false, state: nil }
101
95
  end
102
96
 
103
97
  private
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: 0.1.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - justinsoong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-24 00:00:00.000000000 Z
11
+ date: 2023-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty