passageidentity 0.1.1 → 0.2.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: 3b98a47138ae131d490133febfdfb84b901e3c204dab4dc77a89b58e7dddc2cb
4
- data.tar.gz: a8727e11cfedcbc82b36bfc4c2983ec48d7f0932edb8235325727482a32f7190
3
+ metadata.gz: 10dbb3b156d4428c588e7aae5bb1d10f0430c5d7275417ac76b825207a51ea3f
4
+ data.tar.gz: 9b11bbdc0e13d5369829cf74b51e73e8d220587b19b45e18f454c7e69837cff9
5
5
  SHA512:
6
- metadata.gz: 23e4ca4713b66cc334b2fe31a24e0d7b010eea080afbfb783ea4aeee5e62e74c309a422fb35ec95ed6f532c93dc596d1472c77cf599f4d26d763df80090ba29d
7
- data.tar.gz: bb1e666a5a6baf4ffabfdfd9165e7a679f8174ad312fd6e050b9367b1538ce9b5d4359b56df930ad181865af7198c23d15a6fb76423eade0ec0169d95ce96227
6
+ metadata.gz: 9a7ef97b70cc9da490c8d8e00c3befb8d222ec101819e9277be0b53da30181904eda00f1e9c73c4368d6cd5447a8c42918c919d9078cfd70a3933cfe7959969d
7
+ data.tar.gz: b38620497b8b0adbf2c8fc8409cfeab86694721dde532e05b34246d4c1050774d0d038ecd661fd1aacfa65890ad5b3839224be59359b47e627eb1f9c14b507b3
@@ -19,8 +19,11 @@ module Passage
19
19
  response = @connection.get("/v1/apps/#{@app_id}")
20
20
  return response.body["app"]
21
21
  rescue Faraday::Error => e
22
- raise PassageError,
23
- "failed to get Passage App. Http Status: #{e.response[:status]}. Response: #{e.response[:body]["error"]}"
22
+ raise PassageError.new(
23
+ message: "failed to fetch passage app",
24
+ status_code: e.response[:status],
25
+ body: e.response[:body]
26
+ )
24
27
  end
25
28
  end
26
29
 
@@ -52,14 +55,16 @@ module Passage
52
55
  # Get the token based on the strategy
53
56
  if @auth_strategy === Passage::COOKIE_STRATEGY
54
57
  unless request.cookies["psg_auth_token"].present?
55
- raise PassageError,
56
- `missing authentication token: expected "psg_auth_token" cookie`
58
+ raise PassageError.new(
59
+ message:
60
+ `missing authentication token: expected "psg_auth_token" cookie`
61
+ )
57
62
  end
58
63
  @token = request.cookies["psg_auth_token"]
59
64
  else
60
65
  headers = request.headers
61
66
  unless headers["Authorization"].present?
62
- raise PassageError, "no authentication token in header"
67
+ raise PassageError.new(message: "no authentication token in header")
63
68
  end
64
69
  @token = headers["Authorization"].split(" ").last
65
70
  end
@@ -68,7 +73,7 @@ module Passage
68
73
  if @token
69
74
  return authenticate_token(@token)
70
75
  else
71
- raise PassageError, "no authentication token"
76
+ raise PassageError.new(message: "no authentication token")
72
77
  end
73
78
  nil
74
79
  end
@@ -98,15 +103,15 @@ module Passage
98
103
  )
99
104
  return claims[0]["sub"]
100
105
  rescue JWT::InvalidIssuerError => e
101
- raise Passage::PassageError, e.message
106
+ raise PassageError.new(message: e.message)
102
107
  rescue JWT::InvalidAudError => e
103
- raise Passage::PassageError, e.message
108
+ raise PassageError.new(e.message)
104
109
  rescue JWT::ExpiredSignature => e
105
- raise Passage::PassageError, e.message
110
+ raise PassageError.new(e.message)
106
111
  rescue JWT::IncorrectAlgorithm => e
107
- raise Passage::PassageError, e.message
112
+ raise PassageError.new(e.message)
108
113
  rescue JWT::DecodeError => e
109
- raise Passage::PassageError, e.message
114
+ raise PassageError.new(e.message)
110
115
  end
111
116
  end
112
117
  end
@@ -20,6 +20,7 @@ module Passage
20
20
  :refresh_inactivity_lifetime,
21
21
  :user_metadata_schema,
22
22
  :layouts,
23
+ :default_language,
23
24
  keyword_init: true
24
25
  User =
25
26
  Struct.new :id,
@@ -76,7 +77,7 @@ module Passage
76
77
 
77
78
  # check for valid auth strategy
78
79
  unless [COOKIE_STRATEGY, HEADER_STRATEGY].include? auth_strategy
79
- raise PassageError, "invalid auth strategy."
80
+ raise PassageError.new(message: "invalid auth strategy.")
80
81
  end
81
82
  @auth_strategy = auth_strategy
82
83
 
@@ -137,7 +138,8 @@ module Passage
137
138
  refresh_inactivity_lifetime:
138
139
  app_info["refresh_inactivity_lifetime"],
139
140
  user_metadata_schema: app_info["user_metadata_schema"],
140
- layouts: app_info["layouts"]
141
+ layouts: app_info["layouts"],
142
+ default_language: app_info["default_language"]
141
143
  )
142
144
  )
143
145
  rescue => e
@@ -153,6 +155,7 @@ module Passage
153
155
  send: false,
154
156
  magic_link_path: "",
155
157
  redirect_url: "",
158
+ language: "",
156
159
  ttl: 60
157
160
  )
158
161
  magic_link_req = {}
@@ -162,8 +165,10 @@ module Passage
162
165
 
163
166
  # check to see if the channel specified is valid before sending it off to the server
164
167
  unless [PHONE_CHANNEL, EMAIL_CHANNEL].include? channel
165
- raise PassageError,
166
- "channel: must be either Passage::EMAIL_CHANNEL or Passage::PHONE_CHANNEL"
168
+ raise PassageError.new(
169
+ message:
170
+ "channel: must be either Passage::EMAIL_CHANNEL or Passage::PHONE_CHANNEL"
171
+ )
167
172
  end
168
173
  magic_link_req["channel"] = channel unless channel.empty?
169
174
  magic_link_req["send"] = send
@@ -192,8 +197,11 @@ module Passage
192
197
  )
193
198
  )
194
199
  rescue Faraday::Error => e
195
- raise PassageError,
196
- "failed to create Passage Magic Link. Http Status: #{e.response[:status]}. Response: #{e.response[:body]["error"]}"
200
+ raise PassageError.new(
201
+ message: "failed to create Passage Magic Link",
202
+ status_code: e.response[:status],
203
+ body: e.response[:body]
204
+ )
197
205
  end
198
206
  end
199
207
  end
@@ -1,4 +1,24 @@
1
+ require "net/http"
2
+
1
3
  module Passage
2
4
  class PassageError < StandardError
5
+ attr_reader :status_code
6
+ attr_reader :status_text
7
+ attr_reader :message
8
+ attr_reader :error
9
+
10
+ def initialize(message:, status_code: nil, body: nil)
11
+ @message = message
12
+ @status_code = status_code
13
+ @status_text =
14
+ (
15
+ if status_code.nil?
16
+ nil
17
+ else
18
+ Net::HTTPResponse::CODE_TO_OBJ[status_code.to_s]
19
+ end
20
+ )
21
+ @error = body.nil? ? nil : body["error"]
22
+ end
3
23
  end
4
24
  end
@@ -10,7 +10,8 @@ module Passage
10
10
  end
11
11
 
12
12
  def get(user_id:)
13
- raise PassageError, "must supply a valid user_id" if user_id.to_s.empty?
13
+ user_exists?(user_id)
14
+
14
15
  begin
15
16
  response = @connection.get("/v1/apps/#{@app_id}/users/#{user_id}")
16
17
  user = response.body["user"]
@@ -35,17 +36,24 @@ module Passage
35
36
  )
36
37
  rescue Faraday::Error => e
37
38
  if e.is_a? Faraday::ResourceNotFound
38
- raise PassageError,
39
- "passage User with ID \"#{user_id}\" does not exist"
39
+ raise PassageError.new(
40
+ message: "Passage User with ID \"#{user_id}\" does not exist",
41
+ status_code: e.response[:status],
42
+ body: e.response[:body]
43
+ )
40
44
  else
41
- raise PassageError,
42
- "failed to get Passage User. Http Status: #{e.response[:status]}. Response: #{e.response[:body]["error"]}"
45
+ raise PassageError.new(
46
+ message: "failed to get Passage User.",
47
+ status_code: e.response[:status],
48
+ body: e.response[:body]
49
+ )
43
50
  end
44
51
  end
45
52
  end
46
53
 
47
54
  def activate(user_id:)
48
- raise PassageError, "must supply a valid user_id" if user_id.to_s.empty?
55
+ user_exists?(user_id)
56
+
49
57
  begin
50
58
  response =
51
59
  @connection.patch("/v1/apps/#{@app_id}/users/#{user_id}/activate")
@@ -70,17 +78,24 @@ module Passage
70
78
  )
71
79
  rescue Faraday::Error => e
72
80
  if e.is_a? Faraday::ResourceNotFound
73
- raise PassageError,
74
- "passage User with ID \"#{user_id}\" does not exist"
81
+ raise PassageError.new(
82
+ message: "Passage User with ID \"#{user_id}\" does not exist",
83
+ status_code: e.response[:status],
84
+ body: e.response[:body]
85
+ )
75
86
  else
76
- raise PassageError,
77
- "failed to activate Passage User. Http Status: #{e.response[:status]}. Response: #{e.response[:body]["error"]}"
87
+ raise PassageError.new(
88
+ message: "failed to activate Passage User.",
89
+ status_code: e.response[:status],
90
+ body: e.response[:body]
91
+ )
78
92
  end
79
93
  end
80
94
  end
81
95
 
82
96
  def deactivate(user_id:)
83
- raise PassageError, "must supply a valid user_id" if user_id.to_s.empty?
97
+ user_exists?(user_id)
98
+
84
99
  begin
85
100
  response =
86
101
  @connection.patch("/v1/apps/#{@app_id}/users/#{user_id}/deactivate")
@@ -105,17 +120,24 @@ module Passage
105
120
  )
106
121
  rescue Faraday::Error => e
107
122
  if e.is_a? Faraday::ResourceNotFound
108
- raise PassageError,
109
- "passage User with ID \"#{user_id}\" does not exist"
123
+ raise PassageError.new(
124
+ message: "Passage User with ID \"#{user_id}\" does not exist",
125
+ status_code: e.response[:status],
126
+ body: e.response[:body]
127
+ )
110
128
  else
111
- raise PassageError,
112
- "failed to deactivate Passage User. Http Status: #{e.response[:status]}. Response: #{e.response[:body]["error"]}"
129
+ raise PassageError.new(
130
+ message: "failed to deactivate Passage User.",
131
+ status_code: e.response[:status],
132
+ body: e.response[:body]
133
+ )
113
134
  end
114
135
  end
115
136
  end
116
137
 
117
138
  def update(user_id:, email: "", phone: "", user_metadata: {})
118
- raise PassageError, "must supply a valid user_id" if user_id.to_s.empty?
139
+ user_exists?(user_id)
140
+
119
141
  updates = {}
120
142
  updates["email"] = email unless email.empty?
121
143
  updates["phone"] = phone unless phone.empty?
@@ -144,11 +166,17 @@ module Passage
144
166
  )
145
167
  rescue Faraday::Error => e
146
168
  if e.is_a? Faraday::ResourceNotFound
147
- raise PassageError,
148
- "passage User with ID \"#{user_id}\" does not exist"
169
+ raise PassageError.new(
170
+ message: "Passage User with ID \"#{user_id}\" does not exist",
171
+ status_code: e.response[:status],
172
+ body: e.response[:body]
173
+ )
149
174
  else
150
- raise PassageError,
151
- "failed to update Passage User. Http Status: #{e.response[:status]}. Response: #{e.response[:body]["error"]}"
175
+ raise PassageError.new(
176
+ "failed to update Passage User",
177
+ status_code: e.response[:status],
178
+ body: e.response[:body]
179
+ )
152
180
  end
153
181
  end
154
182
  end
@@ -180,32 +208,41 @@ module Passage
180
208
  )
181
209
  )
182
210
  rescue Faraday::Error => e
183
- raise PassageError,
184
- "failed to create Passage User. Http Status: #{e.response[:status]}. Response: #{e.response[:body]["error"]}"
211
+ raise PassageError.new(
212
+ "failed to create Passage User",
213
+ status_code: e.response[:status],
214
+ body: e.response[:body]
215
+ )
185
216
  end
186
217
  end
187
218
 
188
219
  def delete(user_id:)
189
- raise PassageError, "must supply a valid user_id" if user_id.to_s.empty?
220
+ user_exists?(user_id)
221
+
190
222
  begin
191
223
  response = @connection.delete("/v1/apps/#{@app_id}/users/#{user_id}")
192
224
  return true
193
225
  rescue Faraday::Error => e
194
226
  if e.is_a? Faraday::ResourceNotFound
195
- raise PassageError,
196
- "passage User with ID \"#{user_id}\" does not exist"
227
+ raise PassageError.new(
228
+ "passage User with ID \"#{user_id}\" does not exist",
229
+ status_code: e.response[:status],
230
+ body: e.response[:body]
231
+ )
197
232
  else
198
- raise PassageError,
199
- "failed to delete Passage User. Http Status: #{e.response[:status]}. Response: #{e.response[:body]["error"]}"
233
+ raise PassageError.new(
234
+ "failed to delete Passage User",
235
+ status_code: e.response[:status],
236
+ body: e.response[:body]
237
+ )
200
238
  end
201
239
  end
202
240
  end
203
241
 
204
242
  def delete_device(user_id:, device_id:)
205
- raise PassageError, "must supply a valid user_id" if user_id.to_s.empty?
206
- if device_id.to_s.empty?
207
- raise PassageError, "must supply a valid device_id"
208
- end
243
+ user_exists?(user_id)
244
+ device_exists?(device_id)
245
+
209
246
  begin
210
247
  response =
211
248
  @connection.delete(
@@ -213,13 +250,17 @@ module Passage
213
250
  )
214
251
  return true
215
252
  rescue Faraday::Error => e
216
- raise PassageError,
217
- "failed to delete Passage User Device. Http Status: #{e.response[:status]}. Response: #{e.response[:body]["error"]}"
253
+ raise PassageError.new(
254
+ "failed to delete Passage User Device",
255
+ status_code: e.response[:status],
256
+ body: e.response[:body]
257
+ )
218
258
  end
219
259
  end
220
260
 
221
261
  def list_devices(user_id:)
222
- raise PassageError, "must supply a valid user_id" if user_id.to_s.empty?
262
+ user_exists?(user_id)
263
+
223
264
  begin
224
265
  response =
225
266
  @connection.get("/v1/apps/#{@app_id}/users/#{user_id}/devices")
@@ -240,20 +281,40 @@ module Passage
240
281
  end
241
282
  return devices
242
283
  rescue Faraday::Error => e
243
- raise PassageError,
244
- "failed to delete Passage User Device. Http Status: #{e.response[:status]}. Response: #{e.response[:body]["error"]}"
284
+ raise PassageError.new(
285
+ "failed to delete Passage User Device",
286
+ status_code: e.response[:status],
287
+ body: e.response[:body]
288
+ )
245
289
  end
246
290
  end
247
291
 
248
292
  def signout(user_id:)
249
- raise PassageError, "must supply a valid user_id" if user_id.to_s.empty?
293
+ user_exists?(user_id)
250
294
  begin
251
295
  response =
252
296
  @connection.delete("/v1/apps/#{@app_id}/users/#{user_id}/tokens/")
253
297
  return true
254
298
  rescue Faraday::Error => e
255
- raise PassageError,
256
- "failed to revoke user's refresh tokens. Http Status: #{e.response[:status]}. Response: #{e.response[:body]["error"]}"
299
+ raise PassageError.new(
300
+ "failed to revoke user's refresh tokens",
301
+ status_code: e.response[:status],
302
+ body: e.response[:body]
303
+ )
304
+ end
305
+ end
306
+
307
+ private
308
+
309
+ def user_exists?(user_id)
310
+ if user_id.to_s.empty?
311
+ raise PassageError.new(message: "must supply a valid user_id")
312
+ end
313
+ end
314
+
315
+ def device_exists?(device_id)
316
+ if device_id.to_s.empty?
317
+ raise PassageError.new(message: "must supply a valid device_id")
257
318
  end
258
319
  end
259
320
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'passageidentity'
3
- s.version = '0.1.1'
3
+ s.version = '0.2.0'
4
4
  s.summary = 'Passage SDK for biometric authentication'
5
5
  s.description =
6
6
  'Enables verification of server-side authentication and user management for applications using Passage'
@@ -0,0 +1,30 @@
1
+ require_relative "../lib/passageidentity/error"
2
+ require "test/unit"
3
+ require "net/http"
4
+
5
+ class ErrorTest < Test::Unit::TestCase
6
+ def test_initialize
7
+ body = { "error" => "some error" }
8
+
9
+ error =
10
+ Passage::PassageError.new(
11
+ message: "some message",
12
+ status_code: 400,
13
+ body: body
14
+ )
15
+
16
+ assert_equal error.message, "some message"
17
+ assert_equal error.error, "some error"
18
+ assert_equal error.status_code, 400
19
+ assert_equal error.status_text, Net::HTTPBadRequest
20
+ end
21
+
22
+ def test_initialize_message_only
23
+ error = Passage::PassageError.new(message: "some message")
24
+
25
+ assert_equal error.message, "some message"
26
+ assert_equal error.error, nil
27
+ assert_equal error.status_code, nil
28
+ assert_equal error.status_text, nil
29
+ end
30
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passageidentity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Passage Identity
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-02 00:00:00.000000000 Z
11
+ date: 2022-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -94,6 +94,7 @@ files:
94
94
  - tests/all.rb
95
95
  - tests/app_test.rb
96
96
  - tests/auth_test.rb
97
+ - tests/errors_test.rb
97
98
  - tests/magic_link_test.rb
98
99
  - tests/user_api_test.rb
99
100
  homepage: https://rubygems.org/gems/passageidentity