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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48edd9284cb043177840d772dd58a7c1d7ae8cb77f3a52aee0722b2546835048
4
- data.tar.gz: f68bacf557d743155928c4265e47fdc734dbed8183e7b20cbe8ab1eb44ac7b1d
3
+ metadata.gz: ef72de911b6f4c335d25c91ffd4354e63806d0ff585e505e3ef75a017b50b6b5
4
+ data.tar.gz: 29957392dffba413ee3c209ffa42d5a9c5c3a53e92577d1bcf29bfd7c17b38ab
5
5
  SHA512:
6
- metadata.gz: f91d166d539836b0434c6120944137dbf15dda319608b62966ec7d2263258467c61856e325303796d2f37bb702c6716a79ddcf2fe88a2ebe4156c7c76b6ce37f
7
- data.tar.gz: c632f9b44f9a9ef7ee50a85547095b64ad8c2cb028e5a2b06ca50f6e6101a117ea75310b0f55cd86ceeb0ff753041713da8fc95f68e8e0c083e5ec8d377da115
6
+ metadata.gz: 1d76f5cc705d322f05454d89d6dbd952ebaf7521183bf304d7b95a730e35a05d26aaefd55525f25979cca79ac684c36bc2c2a3ce60e27317efa017fdab1e1da6
7
+ data.tar.gz: c5fb43f90c6fa84b6d88185c9dfb771395c35d925a19bedd58add14d633f8015bca10f0a6a4ff6f656027e027dc322bd7703f4cbc25b0f5a52e38c7ce3d7611d
@@ -91,21 +91,21 @@ module OpenapiClient
91
91
  # Create User
92
92
  # Create user for an application. Must provide an email of phone number identifier.
93
93
  # @param app_id [String] App ID
94
- # @param create_user_request [CreateUserRequest] email, phone, user_metadata
94
+ # @param create_user_args [CreateUserArgs] email, phone, user_metadata
95
95
  # @param [Hash] opts the optional parameters
96
96
  # @return [UserResponse]
97
- def create_user(app_id, create_user_request, opts = {})
98
- data, _status_code, _headers = create_user_with_http_info(app_id, create_user_request, opts)
97
+ def create_user(app_id, create_user_args, opts = {})
98
+ data, _status_code, _headers = create_user_with_http_info(app_id, create_user_args, opts)
99
99
  data
100
100
  end
101
101
 
102
102
  # Create User
103
103
  # Create user for an application. Must provide an email of phone number identifier.
104
104
  # @param app_id [String] App ID
105
- # @param create_user_request [CreateUserRequest] email, phone, user_metadata
105
+ # @param create_user_args [CreateUserArgs] email, phone, user_metadata
106
106
  # @param [Hash] opts the optional parameters
107
107
  # @return [Array<(UserResponse, Integer, Hash)>] UserResponse data, response status code and response headers
108
- def create_user_with_http_info(app_id, create_user_request, opts = {})
108
+ def create_user_with_http_info(app_id, create_user_args, opts = {})
109
109
  if @api_client.config.debugging
110
110
  @api_client.config.logger.debug 'Calling API: UsersApi.create_user ...'
111
111
  end
@@ -113,9 +113,9 @@ module OpenapiClient
113
113
  if @api_client.config.client_side_validation && app_id.nil?
114
114
  fail ArgumentError, "Missing the required parameter 'app_id' when calling UsersApi.create_user"
115
115
  end
116
- # verify the required parameter 'create_user_request' is set
117
- if @api_client.config.client_side_validation && create_user_request.nil?
118
- fail ArgumentError, "Missing the required parameter 'create_user_request' when calling UsersApi.create_user"
116
+ # verify the required parameter 'create_user_args' is set
117
+ if @api_client.config.client_side_validation && create_user_args.nil?
118
+ fail ArgumentError, "Missing the required parameter 'create_user_args' when calling UsersApi.create_user"
119
119
  end
120
120
  # resource path
121
121
  local_var_path = '/apps/{app_id}/users'.sub('{' + 'app_id' + '}', CGI.escape(app_id.to_s))
@@ -137,7 +137,7 @@ module OpenapiClient
137
137
  form_params = opts[:form_params] || {}
138
138
 
139
139
  # http body (model)
140
- post_body = opts[:debug_body] || @api_client.object_to_http_body(create_user_request)
140
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(create_user_args)
141
141
 
142
142
  # return_type
143
143
  return_type = opts[:debug_return_type] || 'UserResponse'
@@ -469,11 +469,11 @@ module OpenapiClient
469
469
  # Update a user's information.
470
470
  # @param app_id [String] App ID
471
471
  # @param user_id [String] User ID
472
- # @param update_user_request [UpdateUserRequest] user settings
472
+ # @param update_user_args [UpdateUserArgs] user settings
473
473
  # @param [Hash] opts the optional parameters
474
474
  # @return [UserResponse]
475
- def update_user(app_id, user_id, update_user_request, opts = {})
476
- data, _status_code, _headers = update_user_with_http_info(app_id, user_id, update_user_request, opts)
475
+ def update_user(app_id, user_id, update_user_args, opts = {})
476
+ data, _status_code, _headers = update_user_with_http_info(app_id, user_id, update_user_args, opts)
477
477
  data
478
478
  end
479
479
 
@@ -481,10 +481,10 @@ module OpenapiClient
481
481
  # Update a user&#39;s information.
482
482
  # @param app_id [String] App ID
483
483
  # @param user_id [String] User ID
484
- # @param update_user_request [UpdateUserRequest] user settings
484
+ # @param update_user_args [UpdateUserArgs] user settings
485
485
  # @param [Hash] opts the optional parameters
486
486
  # @return [Array<(UserResponse, Integer, Hash)>] UserResponse data, response status code and response headers
487
- def update_user_with_http_info(app_id, user_id, update_user_request, opts = {})
487
+ def update_user_with_http_info(app_id, user_id, update_user_args, opts = {})
488
488
  if @api_client.config.debugging
489
489
  @api_client.config.logger.debug 'Calling API: UsersApi.update_user ...'
490
490
  end
@@ -496,9 +496,9 @@ module OpenapiClient
496
496
  if @api_client.config.client_side_validation && user_id.nil?
497
497
  fail ArgumentError, "Missing the required parameter 'user_id' when calling UsersApi.update_user"
498
498
  end
499
- # verify the required parameter 'update_user_request' is set
500
- if @api_client.config.client_side_validation && update_user_request.nil?
501
- fail ArgumentError, "Missing the required parameter 'update_user_request' when calling UsersApi.update_user"
499
+ # verify the required parameter 'update_user_args' is set
500
+ if @api_client.config.client_side_validation && update_user_args.nil?
501
+ fail ArgumentError, "Missing the required parameter 'update_user_args' when calling UsersApi.update_user"
502
502
  end
503
503
  # resource path
504
504
  local_var_path = '/apps/{app_id}/users/{user_id}'.sub('{' + 'app_id' + '}', CGI.escape(app_id.to_s)).sub('{' + 'user_id' + '}', CGI.escape(user_id.to_s))
@@ -520,7 +520,7 @@ module OpenapiClient
520
520
  form_params = opts[:form_params] || {}
521
521
 
522
522
  # http body (model)
523
- post_body = opts[:debug_body] || @api_client.object_to_http_body(update_user_request)
523
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(update_user_args)
524
524
 
525
525
  # return_type
526
526
  return_type = opts[:debug_return_type] || 'UserResponse'
@@ -19,7 +19,6 @@ module OpenapiClient
19
19
 
20
20
  attr_accessor :email
21
21
 
22
- # language of the email to send (optional)
23
22
  attr_accessor :language
24
23
 
25
24
  # must be a relative url
@@ -31,6 +30,7 @@ module OpenapiClient
31
30
 
32
31
  attr_accessor :_send
33
32
 
33
+ # time to live in minutes
34
34
  attr_accessor :ttl
35
35
 
36
36
  attr_accessor :type
@@ -85,7 +85,7 @@ module OpenapiClient
85
85
  {
86
86
  :'channel' => :'MagicLinkChannel',
87
87
  :'email' => :'String',
88
- :'language' => :'String',
88
+ :'language' => :'MagicLinkLanguage',
89
89
  :'magic_link_path' => :'String',
90
90
  :'phone' => :'String',
91
91
  :'redirect_url' => :'String',
@@ -163,6 +163,10 @@ module OpenapiClient
163
163
  def list_invalid_properties
164
164
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
165
165
  invalid_properties = Array.new
166
+ if !@ttl.nil? && @ttl < 1
167
+ invalid_properties.push('invalid value for "ttl", must be greater than or equal to 1.')
168
+ end
169
+
166
170
  invalid_properties
167
171
  end
168
172
 
@@ -170,9 +174,24 @@ module OpenapiClient
170
174
  # @return true if the model is valid
171
175
  def valid?
172
176
  warn '[DEPRECATED] the `valid?` method is obsolete'
177
+ return false if !@ttl.nil? && @ttl < 1
173
178
  true
174
179
  end
175
180
 
181
+ # Custom attribute writer method with validation
182
+ # @param [Object] ttl Value to be assigned
183
+ def ttl=(ttl)
184
+ if ttl.nil?
185
+ fail ArgumentError, 'ttl cannot be nil'
186
+ end
187
+
188
+ if ttl < 1
189
+ fail ArgumentError, 'invalid value for "ttl", must be greater than or equal to 1.'
190
+ end
191
+
192
+ @ttl = ttl
193
+ end
194
+
176
195
  # Checks equality by comparing each attribute.
177
196
  # @param [Object] Object to be compared
178
197
  def ==(o)
@@ -14,7 +14,7 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module OpenapiClient
17
- class CreateUserRequest
17
+ class CreateUserArgs
18
18
  # Email of the new user. Either this or `phone` is required; both may be provided.
19
19
  attr_accessor :email
20
20
 
@@ -56,13 +56,13 @@ module OpenapiClient
56
56
  # @param [Hash] attributes Model attributes in the form of hash
57
57
  def initialize(attributes = {})
58
58
  if (!attributes.is_a?(Hash))
59
- fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::CreateUserRequest` initialize method"
59
+ fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::CreateUserArgs` initialize method"
60
60
  end
61
61
 
62
62
  # check to see if the attribute exists and convert string to symbol for hash key
63
63
  attributes = attributes.each_with_object({}) { |(k, v), h|
64
64
  if (!self.class.attribute_map.key?(k.to_sym))
65
- fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::CreateUserRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
65
+ fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::CreateUserArgs`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
66
66
  end
67
67
  h[k.to_sym] = v
68
68
  }
@@ -27,6 +27,7 @@ module OpenapiClient
27
27
 
28
28
  attr_accessor :secret
29
29
 
30
+ # time to live in minutes
30
31
  attr_accessor :ttl
31
32
 
32
33
  attr_accessor :type
@@ -14,13 +14,17 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module OpenapiClient
17
- class ThemeType
18
- AUTO = "auto".freeze
19
- LIGHT = "light".freeze
20
- DARK = "dark".freeze
17
+ class MagicLinkLanguage
18
+ DE = "de".freeze
19
+ EN = "en".freeze
20
+ ES = "es".freeze
21
+ IT = "it".freeze
22
+ PL = "pl".freeze
23
+ PT = "pt".freeze
24
+ ZH = "zh".freeze
21
25
 
22
26
  def self.all_vars
23
- @all_vars ||= [AUTO, LIGHT, DARK].freeze
27
+ @all_vars ||= [DE, EN, ES, IT, PL, PT, ZH].freeze
24
28
  end
25
29
 
26
30
  # Builds the enum from string
@@ -34,8 +38,8 @@ module OpenapiClient
34
38
  # @param [String] The enum value in the form of the string
35
39
  # @return [String] The enum value
36
40
  def build_from_hash(value)
37
- return value if ThemeType.all_vars.include?(value)
38
- raise "Invalid ENUM value #{value} for class #ThemeType"
41
+ return value if MagicLinkLanguage.all_vars.include?(value)
42
+ raise "Invalid ENUM value #{value} for class #MagicLinkLanguage"
39
43
  end
40
44
  end
41
45
  end
@@ -14,7 +14,7 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module OpenapiClient
17
- class UserInfo
17
+ class PassageUser
18
18
  attr_accessor :created_at
19
19
 
20
20
  attr_accessor :email
@@ -135,13 +135,13 @@ module OpenapiClient
135
135
  # @param [Hash] attributes Model attributes in the form of hash
136
136
  def initialize(attributes = {})
137
137
  if (!attributes.is_a?(Hash))
138
- fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::UserInfo` initialize method"
138
+ fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::PassageUser` initialize method"
139
139
  end
140
140
 
141
141
  # check to see if the attribute exists and convert string to symbol for hash key
142
142
  attributes = attributes.each_with_object({}) { |(k, v), h|
143
143
  if (!self.class.attribute_map.key?(k.to_sym))
144
- fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::UserInfo`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
144
+ fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::PassageUser`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
145
145
  end
146
146
  h[k.to_sym] = v
147
147
  }
@@ -14,7 +14,7 @@ require 'date'
14
14
  require 'time'
15
15
 
16
16
  module OpenapiClient
17
- class UpdateUserRequest
17
+ class UpdateUserArgs
18
18
  attr_accessor :email
19
19
 
20
20
  attr_accessor :phone
@@ -54,13 +54,13 @@ module OpenapiClient
54
54
  # @param [Hash] attributes Model attributes in the form of hash
55
55
  def initialize(attributes = {})
56
56
  if (!attributes.is_a?(Hash))
57
- fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::UpdateUserRequest` initialize method"
57
+ fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::UpdateUserArgs` initialize method"
58
58
  end
59
59
 
60
60
  # check to see if the attribute exists and convert string to symbol for hash key
61
61
  attributes = attributes.each_with_object({}) { |(k, v), h|
62
62
  if (!self.class.attribute_map.key?(k.to_sym))
63
- fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::UpdateUserRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
63
+ fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::UpdateUserArgs`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
64
64
  end
65
65
  h[k.to_sym] = v
66
66
  }
@@ -32,7 +32,7 @@ module OpenapiClient
32
32
  # Attribute type mapping.
33
33
  def self.openapi_types
34
34
  {
35
- :'user' => :'UserInfo'
35
+ :'user' => :'PassageUser'
36
36
  }
37
37
  end
38
38
 
@@ -17,25 +17,18 @@ require_relative 'openapi_client/version'
17
17
  require_relative 'openapi_client/configuration'
18
18
 
19
19
  # Models
20
- require_relative 'openapi_client/models/app_info'
21
- require_relative 'openapi_client/models/app_response'
22
20
  require_relative 'openapi_client/models/apple_user_social_connection'
23
- require_relative 'openapi_client/models/auth_methods'
24
21
  require_relative 'openapi_client/models/create_magic_link_request'
25
- require_relative 'openapi_client/models/create_user_request'
26
- require_relative 'openapi_client/models/element_customization'
27
- require_relative 'openapi_client/models/font_family'
22
+ require_relative 'openapi_client/models/create_user_args'
28
23
  require_relative 'openapi_client/models/github_user_social_connection'
29
24
  require_relative 'openapi_client/models/google_user_social_connection'
30
- require_relative 'openapi_client/models/layout_config'
31
- require_relative 'openapi_client/models/layouts'
32
25
  require_relative 'openapi_client/models/link'
33
26
  require_relative 'openapi_client/models/list_devices_response'
34
27
  require_relative 'openapi_client/models/list_paginated_users_item'
35
28
  require_relative 'openapi_client/models/list_paginated_users_response'
36
29
  require_relative 'openapi_client/models/magic_link'
37
- require_relative 'openapi_client/models/magic_link_auth_method'
38
30
  require_relative 'openapi_client/models/magic_link_channel'
31
+ require_relative 'openapi_client/models/magic_link_language'
39
32
  require_relative 'openapi_client/models/magic_link_response'
40
33
  require_relative 'openapi_client/models/magic_link_type'
41
34
  require_relative 'openapi_client/models/model400_error'
@@ -44,19 +37,12 @@ require_relative 'openapi_client/models/model403_error'
44
37
  require_relative 'openapi_client/models/model404_error'
45
38
  require_relative 'openapi_client/models/model500_error'
46
39
  require_relative 'openapi_client/models/nonce'
47
- require_relative 'openapi_client/models/otp_auth_method'
48
40
  require_relative 'openapi_client/models/paginated_links'
49
- require_relative 'openapi_client/models/passkeys_auth_method'
41
+ require_relative 'openapi_client/models/passage_user'
50
42
  require_relative 'openapi_client/models/social_connection_type'
51
- require_relative 'openapi_client/models/technologies'
52
- require_relative 'openapi_client/models/theme_type'
53
- require_relative 'openapi_client/models/ttl_display_unit'
54
- require_relative 'openapi_client/models/update_user_request'
43
+ require_relative 'openapi_client/models/update_user_args'
55
44
  require_relative 'openapi_client/models/user_event_action'
56
45
  require_relative 'openapi_client/models/user_event_status'
57
- require_relative 'openapi_client/models/user_info'
58
- require_relative 'openapi_client/models/user_metadata_field'
59
- require_relative 'openapi_client/models/user_metadata_field_type'
60
46
  require_relative 'openapi_client/models/user_recent_event'
61
47
  require_relative 'openapi_client/models/user_response'
62
48
  require_relative 'openapi_client/models/user_social_connections'
@@ -66,7 +52,6 @@ require_relative 'openapi_client/models/web_authn_icons'
66
52
  require_relative 'openapi_client/models/web_authn_type'
67
53
 
68
54
  # APIs
69
- require_relative 'openapi_client/api/apps_api'
70
55
  require_relative 'openapi_client/api/magic_links_api'
71
56
  require_relative 'openapi_client/api/tokens_api'
72
57
  require_relative 'openapi_client/api/user_devices_api'
@@ -2,139 +2,66 @@
2
2
 
3
3
  require 'active_support'
4
4
  require 'jwt'
5
- require 'rubygems/deprecate'
6
- require_relative 'client'
7
5
  require_relative '../openapi_client'
8
6
 
9
7
  module Passage
10
8
  # The Passage::Auth class provides methods for authenticating requests and tokens
11
9
  class Auth
12
- extend Gem::Deprecate
13
-
14
- def initialize(app_id, api_key, auth_strategy)
15
- @app_cache = ActiveSupport::Cache::MemoryStore.new
10
+ def initialize(app_id:, req_opts:)
16
11
  @app_id = app_id
17
- @api_key = api_key
18
- @auth_strategy = auth_strategy
12
+ @req_opts = req_opts
19
13
 
14
+ @app_cache = ActiveSupport::Cache::MemoryStore.new
20
15
  fetch_jwks
21
16
 
22
- header_params = { 'Passage-Version' => "passage-ruby #{Passage::VERSION}" }
23
- header_params['Authorization'] = "Bearer #{@api_key}" if @api_key != ''
24
-
25
- @req_opts = {}
26
- @req_opts[:header_params] = header_params
27
- @req_opts[:debug_auth_names] = ['header']
28
-
29
- @tokens_client = OpenapiClient::TokensApi.new
30
17
  @magic_links_client = OpenapiClient::MagicLinksApi.new
31
18
  end
32
19
 
33
- def authenticate_request(request)
34
- # Get the token based on the strategy
35
- if @auth_strategy == Passage::COOKIE_STRATEGY
36
- unless request.cookies.key?('psg_auth_token')
37
- raise PassageError.new(
38
- status_code: 401,
39
- body: {
40
- error: 'missing authentication token: expected "psg_auth_token" cookie',
41
- code: 'invalid_access_token'
42
- }
43
- )
44
- end
45
- @token = request.cookies['psg_auth_token']
46
- else
47
- headers = request.headers
48
- unless headers.key?('Authorization')
49
- raise PassageError.new(
50
- status_code: 401,
51
- body: {
52
- error: 'no authentication token in header',
53
- code: 'invalid_access_token'
54
- }
55
- )
56
- end
57
-
58
- @token = headers['Authorization'].split(' ').last
59
- end
60
-
61
- validate_jwt(@token)
62
- end
63
-
64
- def validate_jwt(token)
65
- raise ArgumentError, 'jwt is required.' unless token && !token.empty?
66
-
67
- begin
68
- fetch_jwks
69
- rescue Faraday::Error
70
- raise PassageError.new(
71
- status_code: 401,
72
- body: {
73
- error: 'invalid JWKs',
74
- code: 'invalid_access_token'
75
- }
76
- )
77
- end
20
+ def validate_jwt(jwt:)
21
+ raise ArgumentError, 'jwt is required.' unless jwt && !jwt.empty?
78
22
 
79
23
  claims =
80
24
  JWT.decode(
81
- token,
25
+ jwt,
82
26
  nil,
83
27
  true,
84
28
  {
85
29
  aud: @app_id,
86
30
  verify_aud: true,
87
31
  algorithms: ['RS256'],
88
- jwks: @jwks
32
+ jwks: fetch_jwks
89
33
  }
90
34
  )
91
35
 
92
36
  claims[0]['sub']
93
- rescue JWT::InvalidIssuerError, JWT::InvalidAudError, JWT::ExpiredSignature, JWT::IncorrectAlgorithm,
94
- JWT::DecodeError => e
95
- raise PassageError.new(
96
- status_code: 401,
97
- body: {
98
- error: e.message,
99
- code: 'invalid_access_token'
100
- }
101
- )
102
37
  end
103
38
 
104
- def revoke_user_refresh_tokens(user_id)
105
- warn 'NOTE: Passage::Auth#revoke_user_refresh_tokens is deprecated;
106
- use Passage::User#revoke_refresh_tokens instead. It will be removed on or after 2024-12.'
107
- user_exists?(user_id)
108
-
109
- @tokens_client.revoke_user_refresh_tokens(@app_id, user_id, @req_opts)
110
- rescue Faraday::Error => e
111
- raise PassageError.new(
112
- status_code: e.response[:status],
113
- body: e.response[:body]
114
- )
115
- end
116
-
117
- def create_magic_link_with_email(email, type, send, opts = {})
39
+ def create_magic_link_with_email(email:, type:, send:, opts: {})
118
40
  args = {}
119
41
  args['email'] = email
120
- args['channel'] = EMAIL_CHANNEL
42
+ args['channel'] = 'email'
121
43
  args['type'] = type
122
44
  args['send'] = send
123
45
 
124
46
  create_magic_link(args, opts)
125
47
  end
126
48
 
127
- def create_magic_link_with_phone(phone, type, send, opts = {})
49
+ def create_magic_link_with_phone(phone:, type:, send:, opts: {})
128
50
  args = {}
129
51
  args['phone'] = phone
130
- args['channel'] = PHONE_CHANNEL
52
+ args['channel'] = 'phone'
131
53
  args['type'] = type
132
54
  args['send'] = send
133
55
 
134
56
  create_magic_link(args, opts)
135
57
  end
136
58
 
137
- def create_magic_link_with_user(user_id, channel, type, send, opts = {})
59
+ def create_magic_link_with_user(user_id:, channel:, type:, send:, opts: {})
60
+ raise ArgumentError, "channel must be either 'email' or 'phone'" unless %w[
61
+ email
62
+ phone
63
+ ].include?(channel)
64
+
138
65
  args = {}
139
66
  args['user_id'] = user_id
140
67
  args['channel'] = channel
@@ -144,50 +71,34 @@ module Passage
144
71
  create_magic_link(args, opts)
145
72
  end
146
73
 
147
- def fetch_app
148
- client = OpenapiClient::AppsApi.new
149
- response = client.get_app(@app_id)
150
-
151
- response.app
152
- rescue Faraday::Error => e
153
- raise PassageError.new(
154
- status_code: e.response[:status],
155
- body: e.response[:body]
156
- )
157
- end
74
+ private
158
75
 
159
76
  def fetch_jwks
160
- app_cache = get_cache(@app_id)
161
-
162
- if app_cache
163
- @jwks = app_cache
164
- else
165
- auth_gw_connection =
166
- Faraday.new(url: 'https://auth.passage.id') do |f|
167
- f.request :json
168
- f.response :raise_error
169
- f.response :json
170
- f.adapter :net_http
171
- end
172
-
173
- response =
174
- auth_gw_connection.get("/v1/apps/#{@app_id}/.well-known/jwks.json")
175
-
176
- if response.success?
177
- @jwks = response.body
178
- set_cache(key: @app_id, jwks: @jwks)
77
+ jwks = @app_cache.read(@app_id)
78
+ return jwks if jwks
79
+
80
+ auth_gw_connection =
81
+ Faraday.new(url: 'https://auth.passage.id') do |f|
82
+ f.request :json
83
+ f.response :raise_error
84
+ f.response :json
85
+ f.adapter :net_http
179
86
  end
180
- end
181
- end
182
87
 
183
- def authenticate_token(token)
184
- validate_jwt(token)
185
- end
88
+ response = auth_gw_connection.get("/v1/apps/#{@app_id}/.well-known/jwks.json")
89
+ jwks = response.body
186
90
 
187
- private
91
+ @app_cache.write(@app_id, jwks, expires_in: 86_400) # 24 hours in seconds
92
+ jwks
93
+ end
188
94
 
189
95
  def create_magic_link(args, opts)
190
- args['language'] = opts['language']
96
+ language = opts['language']
97
+ if language && !OpenapiClient::MagicLinkLanguage.all_vars.include?(language)
98
+ raise ArgumentError, "language must be one of #{OpenapiClient::MagicLinkLanguage.all_vars}"
99
+ end
100
+
101
+ args['language'] = language
191
102
  args['magic_link_path'] = opts['magic_link_path']
192
103
  args['redirect_url'] = opts['redirect_url']
193
104
  args['ttl'] = opts['ttl']
@@ -197,16 +108,16 @@ module Passage
197
108
 
198
109
  def handle_magic_link_creation(args)
199
110
  @magic_links_client.create_magic_link(@app_id, args, @req_opts).magic_link
200
- rescue Faraday::Error => e
201
- raise PassageError.new(
202
- status_code: e.response[:status],
203
- body: e.response[:body]
204
- )
205
111
  rescue OpenapiClient::ApiError => e
206
112
  raise PassageError.new(
207
113
  status_code: e.code,
208
114
  body: try_parse_json_string(e.response_body)
209
115
  )
116
+ rescue Faraday::Error => e
117
+ raise PassageError.new(
118
+ status_code: e.response[:status],
119
+ body: e.response[:body]
120
+ )
210
121
  end
211
122
 
212
123
  def try_parse_json_string(string)
@@ -214,29 +125,5 @@ module Passage
214
125
  rescue JSON::ParserError
215
126
  string
216
127
  end
217
-
218
- def user_exists?(user_id)
219
- return unless user_id.to_s.empty?
220
-
221
- raise PassageError.new(
222
- status_code: 400,
223
- body: {
224
- error: 'Must supply a valid user_id',
225
- code: 'invalid_request'
226
- }
227
- )
228
- end
229
-
230
- def get_cache(key)
231
- @app_cache.read(key)
232
- end
233
-
234
- def set_cache(key:, jwks:)
235
- @app_cache.write(key, jwks, expires_in: 86_400)
236
- end
237
- deprecate(:authenticate_request, :validate_jwt, 2025, 1)
238
- deprecate(:authenticate_token, :validate_jwt, 2025, 1)
239
- deprecate(:fetch_app, :none, 2025, 1)
240
- deprecate(:fetch_jwks, :none, 2025, 1)
241
128
  end
242
129
  end