passageidentity 0.7.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/lib/openapi_client/api/users_api.rb +18 -18
  3. data/lib/openapi_client/models/create_magic_link_request.rb +21 -2
  4. data/lib/openapi_client/models/{create_user_request.rb → create_user_args.rb} +3 -3
  5. data/lib/openapi_client/models/magic_link.rb +1 -0
  6. data/lib/openapi_client/models/{theme_type.rb → magic_link_language.rb} +11 -7
  7. data/lib/openapi_client/models/{user_info.rb → passage_user.rb} +3 -3
  8. data/lib/openapi_client/models/{update_user_request.rb → update_user_args.rb} +3 -3
  9. data/lib/openapi_client/models/user_response.rb +1 -1
  10. data/lib/openapi_client.rb +4 -19
  11. data/lib/passageidentity/auth.rb +43 -156
  12. data/lib/passageidentity/client.rb +16 -96
  13. data/lib/passageidentity/user.rb +246 -0
  14. data/lib/passageidentity/version.rb +1 -1
  15. metadata +38 -36
  16. data/lib/models/update_magic_link_auth_method.rb +0 -276
  17. data/lib/models/update_otp_auth_method.rb +0 -276
  18. data/lib/models/update_passkeys_auth_method.rb +0 -216
  19. data/lib/openapi_client/api/apps_api.rb +0 -85
  20. data/lib/openapi_client/models/app_info.rb +0 -886
  21. data/lib/openapi_client/models/app_response.rb +0 -221
  22. data/lib/openapi_client/models/auth_methods.rb +0 -254
  23. data/lib/openapi_client/models/element_customization.rb +0 -457
  24. data/lib/openapi_client/models/font_family.rb +0 -58
  25. data/lib/openapi_client/models/layout_config.rb +0 -285
  26. data/lib/openapi_client/models/layouts.rb +0 -241
  27. data/lib/openapi_client/models/magic_link_auth_method.rb +0 -295
  28. data/lib/openapi_client/models/otp_auth_method.rb +0 -295
  29. data/lib/openapi_client/models/passkeys_auth_method.rb +0 -221
  30. data/lib/openapi_client/models/technologies.rb +0 -46
  31. data/lib/openapi_client/models/ttl_display_unit.rb +0 -42
  32. data/lib/openapi_client/models/user_metadata_field.rb +0 -323
  33. data/lib/openapi_client/models/user_metadata_field_type.rb +0 -44
  34. data/lib/passageidentity/user_api.rb +0 -218
@@ -1,113 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rubygems'
4
3
  require_relative 'auth'
5
- require_relative 'user_api'
6
- require_relative 'error'
4
+ require_relative 'user'
7
5
  require_relative 'version'
8
- require_relative '../openapi_client'
9
6
 
10
7
  module Passage
11
- COOKIE_STRATEGY = 0
12
- HEADER_STRATEGY = 1
13
-
14
- EMAIL_CHANNEL = 'email'
15
- PHONE_CHANNEL = 'phone'
16
-
17
8
  # The Passage::Client class provides methods for interacting with Passage
18
9
  class Client
19
10
  attr_reader :auth, :user
20
11
 
21
- extend Gem::Deprecate
22
-
23
- def initialize(app_id:, api_key: '', auth_strategy: COOKIE_STRATEGY)
24
- @app_id = app_id
25
- @api_key = api_key
26
-
27
- # check for valid auth strategy
28
- unless [COOKIE_STRATEGY, HEADER_STRATEGY].include? auth_strategy
29
- raise PassageError.new(
30
- status_code: 400,
31
- body: {
32
- error: 'Invalid auth strategy',
33
- code: 'invalid_argument'
34
- }
35
- )
12
+ def initialize(app_id:, api_key:)
13
+ unless app_id && !app_id.empty?
14
+ raise ArgumentError,
15
+ 'A Passage App ID is required. Please include (app_id: YOUR_APP_ID, api_key: YOUR_API_KEY).'
36
16
  end
37
-
38
- @auth_strategy = auth_strategy
39
-
40
- header_params = { 'Passage-Version' => "passage-ruby #{Passage::VERSION}" }
41
- header_params['Authorization'] = "Bearer #{@api_key}" if @api_key != ''
42
-
43
- @req_opts = {}
44
- @req_opts[:header_params] = header_params
45
- @req_opts[:debug_auth_names] = ['header']
46
-
47
- # initialize auth class
48
- @auth = Passage::Auth.new(@app_id, @api_key, @auth_strategy)
49
-
50
- # initialize user class
51
- @user = Passage::UserAPI.new(@app_id, @api_key)
52
-
53
- @magic_links_client = OpenapiClient::MagicLinksApi.new
54
- end
55
-
56
- # rubocop:disable Naming/AccessorMethodName
57
- def get_app
58
- client = OpenapiClient::AppsApi.new
59
- client.get_app(@app_id).app
60
- rescue StandardError => e
61
- raise e
62
- end
63
- # rubocop:enable Naming/AccessorMethodName
64
-
65
- # rubocop:disable Metrics/ParameterLists, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
66
- def create_magic_link(
67
- user_id: '',
68
- email: '',
69
- phone: '',
70
- channel: '',
71
- send: false,
72
- magic_link_path: '',
73
- redirect_url: '',
74
- language: '',
75
- ttl: 60,
76
- type: 'login'
77
- )
78
- args = {}
79
- args['user_id'] = user_id unless user_id.empty?
80
- args['email'] = email unless email.empty?
81
- args['phone'] = phone unless phone.empty?
82
-
83
- unless [PHONE_CHANNEL, EMAIL_CHANNEL].include? channel
84
- raise PassageError.new(
85
- message:
86
- 'channel: must be either Passage::EMAIL_CHANNEL or Passage::PHONE_CHANNEL'
87
- )
17
+ unless api_key && !api_key.empty?
18
+ raise ArgumentError,
19
+ 'A Passage API key is required. Please include (app_id: YOUR_APP_ID, api_key: YOUR_API_KEY).'
88
20
  end
89
21
 
90
- args['channel'] = channel unless channel.empty?
91
- args['type'] = type
92
- args['send'] = send
93
-
94
- args['language'] = language unless language.empty?
95
- args['magic_link_path'] = magic_link_path unless magic_link_path.empty?
96
- args['redirect_url'] = redirect_url unless redirect_url.empty?
97
- args['ttl'] = ttl unless ttl.zero?
22
+ req_opts = {}
23
+ req_opts[:header_params] = {
24
+ 'Passage-Version' => "passage-ruby #{Passage::VERSION}",
25
+ 'Authorization' => "Bearer #{api_key}"
26
+ }
27
+ req_opts[:debug_auth_names] = ['header']
98
28
 
99
- begin
100
- @magic_links_client.create_magic_link(@app_id, args, @req_opts).magic_link
101
- rescue Faraday::Error => e
102
- raise PassageError.new(
103
- status_code: e.response[:status],
104
- body: e.response[:body]
105
- )
106
- end
29
+ @auth = Passage::Auth.new(app_id: app_id, req_opts: req_opts)
30
+ @user = Passage::User.new(app_id: app_id, req_opts: req_opts)
107
31
  end
108
- # rubocop:enable Metrics/ParameterLists, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
109
-
110
- deprecate(:create_magic_link, 'Passage::Auth.create_magic_link', 2025, 1)
111
- deprecate(:get_app, :none, 2025, 1)
112
32
  end
113
33
  end
@@ -0,0 +1,246 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../openapi_client'
4
+
5
+ module Passage
6
+ # The User class provides methods for interacting with Passage Users
7
+ class User
8
+ def initialize(app_id:, req_opts:)
9
+ @app_id = app_id
10
+ @req_opts = req_opts
11
+
12
+ @user_client = OpenapiClient::UsersApi.new
13
+ @user_device_client = OpenapiClient::UserDevicesApi.new
14
+ @tokens_client = OpenapiClient::TokensApi.new
15
+ end
16
+
17
+ def get(user_id:)
18
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
19
+
20
+ begin
21
+ response = @user_client.get_user(@app_id, user_id, @req_opts)
22
+ response.user
23
+ rescue OpenapiClient::ApiError => e
24
+ raise PassageError.new(
25
+ status_code: e.code,
26
+ body: try_parse_json_string(e.response_body)
27
+ )
28
+ rescue Faraday::Error => e
29
+ raise PassageError.new(
30
+ status_code: e.response[:status],
31
+ body: e.response[:body]
32
+ )
33
+ end
34
+ end
35
+
36
+ def get_by_identifier(identifier:)
37
+ raise ArgumentError, 'identifier is required.' if blank_str?(identifier)
38
+
39
+ begin
40
+ req_opts = set_get_by_identifier_query_params(identifier: identifier)
41
+ response = @user_client.list_paginated_users(@app_id, req_opts)
42
+ rescue OpenapiClient::ApiError => e
43
+ raise PassageError.new(
44
+ status_code: e.code,
45
+ body: try_parse_json_string(e.response_body)
46
+ )
47
+ rescue Faraday::Error => e
48
+ raise PassageError.new(
49
+ status_code: e.response[:status],
50
+ body: e.response[:body]
51
+ )
52
+ end
53
+
54
+ handle_get_by_identifier(users: response.users)
55
+ end
56
+
57
+ def activate(user_id:)
58
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
59
+
60
+ begin
61
+ response = @user_client.activate_user(@app_id, user_id, @req_opts)
62
+ response.user
63
+ rescue OpenapiClient::ApiError => e
64
+ raise PassageError.new(
65
+ status_code: e.code,
66
+ body: try_parse_json_string(e.response_body)
67
+ )
68
+ rescue Faraday::Error => e
69
+ raise PassageError.new(
70
+ status_code: e.response[:status],
71
+ body: e.response[:body]
72
+ )
73
+ end
74
+ end
75
+
76
+ def deactivate(user_id:)
77
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
78
+
79
+ begin
80
+ response = @user_client.deactivate_user(@app_id, user_id, @req_opts)
81
+ response.user
82
+ rescue OpenapiClient::ApiError => e
83
+ raise PassageError.new(
84
+ status_code: e.code,
85
+ body: try_parse_json_string(e.response_body)
86
+ )
87
+ rescue Faraday::Error => e
88
+ raise PassageError.new(
89
+ status_code: e.response[:status],
90
+ body: e.response[:body]
91
+ )
92
+ end
93
+ end
94
+
95
+ def update(user_id:, options:)
96
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
97
+ raise ArgumentError, 'options are required.' if options.empty?
98
+
99
+ begin
100
+ response = @user_client.update_user(@app_id, user_id, options, @req_opts)
101
+ response.user
102
+ rescue OpenapiClient::ApiError => e
103
+ raise PassageError.new(
104
+ status_code: e.code,
105
+ body: try_parse_json_string(e.response_body)
106
+ )
107
+ rescue Faraday::Error => e
108
+ raise PassageError.new(
109
+ status_code: e.response[:status],
110
+ body: e.response[:body]
111
+ )
112
+ end
113
+ end
114
+
115
+ def create(args:)
116
+ if blank_str?(args['email']) && blank_str?(args['phone'])
117
+ raise ArgumentError,
118
+ 'At least one of args.email or args.phone is required.'
119
+ end
120
+
121
+ begin
122
+ response = @user_client.create_user(@app_id, args, @req_opts)
123
+ response.user
124
+ rescue OpenapiClient::ApiError => e
125
+ raise PassageError.new(
126
+ status_code: e.code,
127
+ body: try_parse_json_string(e.response_body)
128
+ )
129
+ rescue Faraday::Error => e
130
+ raise PassageError.new(
131
+ status_code: e.response[:status],
132
+ body: e.response[:body]
133
+ )
134
+ end
135
+ end
136
+
137
+ def delete(user_id:)
138
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
139
+
140
+ begin
141
+ @user_client.delete_user(@app_id, user_id, @req_opts)
142
+ rescue OpenapiClient::ApiError => e
143
+ raise PassageError.new(
144
+ status_code: e.code,
145
+ body: try_parse_json_string(e.response_body)
146
+ )
147
+ rescue Faraday::Error => e
148
+ raise PassageError.new(
149
+ 'failed to delete Passage User',
150
+ status_code: e.response[:status],
151
+ body: e.response[:body]
152
+ )
153
+ end
154
+ end
155
+
156
+ def revoke_device(user_id:, device_id:)
157
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
158
+ raise ArgumentError, 'device_id is required.' if blank_str?(device_id)
159
+
160
+ begin
161
+ @user_device_client.delete_user_devices(@app_id, user_id, device_id, @req_opts)
162
+ rescue OpenapiClient::ApiError => e
163
+ raise PassageError.new(
164
+ status_code: e.code,
165
+ body: try_parse_json_string(e.response_body)
166
+ )
167
+ rescue Faraday::Error => e
168
+ raise PassageError.new(
169
+ status_code: e.response[:status],
170
+ body: e.response[:body]
171
+ )
172
+ end
173
+ end
174
+
175
+ def list_devices(user_id:)
176
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
177
+
178
+ begin
179
+ response = @user_device_client.list_user_devices(@app_id, user_id, @req_opts)
180
+ response.devices
181
+ rescue OpenapiClient::ApiError => e
182
+ raise PassageError.new(
183
+ status_code: e.code,
184
+ body: try_parse_json_string(e.response_body)
185
+ )
186
+ rescue Faraday::Error => e
187
+ raise PassageError.new(
188
+ status_code: e.response[:status],
189
+ body: e.response[:body]
190
+ )
191
+ end
192
+ end
193
+
194
+ def revoke_refresh_tokens(user_id:)
195
+ raise ArgumentError, 'user_id is required.' if blank_str?(user_id)
196
+
197
+ begin
198
+ @tokens_client.revoke_user_refresh_tokens(@app_id, user_id, @req_opts)
199
+ rescue OpenapiClient::ApiError => e
200
+ raise PassageError.new(
201
+ status_code: e.code,
202
+ body: try_parse_json_string(e.response_body)
203
+ )
204
+ rescue Faraday::Error => e
205
+ raise PassageError.new(
206
+ status_code: e.response[:status],
207
+ body: e.response[:body]
208
+ )
209
+ end
210
+ end
211
+
212
+ private
213
+
214
+ def blank_str?(str)
215
+ blank_pattern = /\A[[:space:]]*\z/
216
+ str.empty? || blank_pattern.match?(str)
217
+ end
218
+
219
+ def set_get_by_identifier_query_params(identifier:)
220
+ req_opts = @req_opts.dup
221
+ req_opts[:limit] = 1
222
+ req_opts[:identifier] = identifier.downcase
223
+ req_opts
224
+ end
225
+
226
+ def handle_get_by_identifier(users:)
227
+ if users.empty?
228
+ raise PassageError.new(
229
+ status_code: 404,
230
+ body: {
231
+ error: 'User not found.',
232
+ code: 'user_not_found'
233
+ }
234
+ )
235
+ end
236
+
237
+ get(user_id: users.first.id)
238
+ end
239
+
240
+ def try_parse_json_string(string)
241
+ JSON.parse(string)
242
+ rescue JSON::ParserError
243
+ string
244
+ end
245
+ end
246
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Passage
4
- VERSION = '0.7.1'
4
+ VERSION = '1.0.0'
5
5
  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.7.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Passage by 1Password
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-20 00:00:00.000000000 Z
11
+ date: 2025-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '7.2'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: '7.0'
22
+ version: '7.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,47 +29,67 @@ dependencies:
29
29
  version: '7.2'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '7.0'
32
+ version: '7.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: faraday
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 0.17.0
39
+ version: '2.12'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '2.0'
42
+ version: '3.0'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 0.17.0
49
+ version: '2.12'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '2.0'
52
+ version: '3.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: faraday-multipart
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.1'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 1.1.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.1'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 1.1.0
53
73
  - !ruby/object:Gem::Dependency
54
74
  name: jwt
55
75
  requirement: !ruby/object:Gem::Requirement
56
76
  requirements:
57
77
  - - "~>"
58
78
  - !ruby/object:Gem::Version
59
- version: '2.3'
79
+ version: '2.10'
60
80
  - - ">="
61
81
  - !ruby/object:Gem::Version
62
- version: 2.3.0
82
+ version: 2.10.1
63
83
  type: :runtime
64
84
  prerelease: false
65
85
  version_requirements: !ruby/object:Gem::Requirement
66
86
  requirements:
67
87
  - - "~>"
68
88
  - !ruby/object:Gem::Version
69
- version: '2.3'
89
+ version: '2.10'
70
90
  - - ">="
71
91
  - !ruby/object:Gem::Version
72
- version: 2.3.0
92
+ version: 2.10.1
73
93
  - !ruby/object:Gem::Dependency
74
94
  name: marcel
75
95
  requirement: !ruby/object:Gem::Requirement
@@ -97,11 +117,7 @@ executables: []
97
117
  extensions: []
98
118
  extra_rdoc_files: []
99
119
  files:
100
- - lib/models/update_magic_link_auth_method.rb
101
- - lib/models/update_otp_auth_method.rb
102
- - lib/models/update_passkeys_auth_method.rb
103
120
  - lib/openapi_client.rb
104
- - lib/openapi_client/api/apps_api.rb
105
121
  - lib/openapi_client/api/magic_links_api.rb
106
122
  - lib/openapi_client/api/tokens_api.rb
107
123
  - lib/openapi_client/api/user_devices_api.rb
@@ -109,25 +125,18 @@ files:
109
125
  - lib/openapi_client/api_client.rb
110
126
  - lib/openapi_client/api_error.rb
111
127
  - lib/openapi_client/configuration.rb
112
- - lib/openapi_client/models/app_info.rb
113
- - lib/openapi_client/models/app_response.rb
114
128
  - lib/openapi_client/models/apple_user_social_connection.rb
115
- - lib/openapi_client/models/auth_methods.rb
116
129
  - lib/openapi_client/models/create_magic_link_request.rb
117
- - lib/openapi_client/models/create_user_request.rb
118
- - lib/openapi_client/models/element_customization.rb
119
- - lib/openapi_client/models/font_family.rb
130
+ - lib/openapi_client/models/create_user_args.rb
120
131
  - lib/openapi_client/models/github_user_social_connection.rb
121
132
  - lib/openapi_client/models/google_user_social_connection.rb
122
- - lib/openapi_client/models/layout_config.rb
123
- - lib/openapi_client/models/layouts.rb
124
133
  - lib/openapi_client/models/link.rb
125
134
  - lib/openapi_client/models/list_devices_response.rb
126
135
  - lib/openapi_client/models/list_paginated_users_item.rb
127
136
  - lib/openapi_client/models/list_paginated_users_response.rb
128
137
  - lib/openapi_client/models/magic_link.rb
129
- - lib/openapi_client/models/magic_link_auth_method.rb
130
138
  - lib/openapi_client/models/magic_link_channel.rb
139
+ - lib/openapi_client/models/magic_link_language.rb
131
140
  - lib/openapi_client/models/magic_link_response.rb
132
141
  - lib/openapi_client/models/magic_link_type.rb
133
142
  - lib/openapi_client/models/model400_error.rb
@@ -136,19 +145,12 @@ files:
136
145
  - lib/openapi_client/models/model404_error.rb
137
146
  - lib/openapi_client/models/model500_error.rb
138
147
  - lib/openapi_client/models/nonce.rb
139
- - lib/openapi_client/models/otp_auth_method.rb
140
148
  - lib/openapi_client/models/paginated_links.rb
141
- - lib/openapi_client/models/passkeys_auth_method.rb
149
+ - lib/openapi_client/models/passage_user.rb
142
150
  - lib/openapi_client/models/social_connection_type.rb
143
- - lib/openapi_client/models/technologies.rb
144
- - lib/openapi_client/models/theme_type.rb
145
- - lib/openapi_client/models/ttl_display_unit.rb
146
- - lib/openapi_client/models/update_user_request.rb
151
+ - lib/openapi_client/models/update_user_args.rb
147
152
  - lib/openapi_client/models/user_event_action.rb
148
153
  - lib/openapi_client/models/user_event_status.rb
149
- - lib/openapi_client/models/user_info.rb
150
- - lib/openapi_client/models/user_metadata_field.rb
151
- - lib/openapi_client/models/user_metadata_field_type.rb
152
154
  - lib/openapi_client/models/user_recent_event.rb
153
155
  - lib/openapi_client/models/user_response.rb
154
156
  - lib/openapi_client/models/user_social_connections.rb
@@ -161,7 +163,7 @@ files:
161
163
  - lib/passageidentity/auth.rb
162
164
  - lib/passageidentity/client.rb
163
165
  - lib/passageidentity/error.rb
164
- - lib/passageidentity/user_api.rb
166
+ - lib/passageidentity/user.rb
165
167
  - lib/passageidentity/version.rb
166
168
  homepage: http://docs.passage.id/complete
167
169
  licenses:
@@ -177,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
179
  requirements:
178
180
  - - ">="
179
181
  - !ruby/object:Gem::Version
180
- version: 3.1.3
182
+ version: 3.1.6
181
183
  required_rubygems_version: !ruby/object:Gem::Requirement
182
184
  requirements:
183
185
  - - ">="