passageidentity 0.2.3 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/README.md +18 -61
- data/docs/custom/AuthApi.md +141 -0
- data/docs/custom/ClientApi.md +107 -0
- data/docs/custom/UserApi.md +419 -0
- data/docs/generated/AppInfo.md +94 -0
- data/docs/generated/AppResponse.md +18 -0
- data/docs/generated/AppsApi.md +77 -0
- data/docs/generated/AuthMethods.md +22 -0
- data/docs/generated/CreateMagicLinkRequest.md +36 -0
- data/docs/generated/CreateUserRequest.md +22 -0
- data/docs/generated/ElementCustomization.md +56 -0
- data/docs/generated/FontFamily.md +15 -0
- data/docs/generated/LayoutConfig.md +26 -0
- data/docs/generated/Layouts.md +20 -0
- data/docs/generated/ListDevicesResponse.md +18 -0
- data/docs/generated/MagicLink.md +36 -0
- data/docs/generated/MagicLinkAuthMethod.md +22 -0
- data/docs/generated/MagicLinkChannel.md +15 -0
- data/docs/generated/MagicLinkResponse.md +18 -0
- data/docs/generated/MagicLinkType.md +15 -0
- data/docs/generated/MagicLinksApi.md +79 -0
- data/docs/generated/Model400Error.md +20 -0
- data/docs/generated/Model401Error.md +20 -0
- data/docs/generated/Model404Error.md +20 -0
- data/docs/generated/Model500Error.md +20 -0
- data/docs/generated/OtpAuthMethod.md +22 -0
- data/docs/generated/PasskeysAuthMethod.md +18 -0
- data/docs/generated/Technologies.md +15 -0
- data/docs/generated/TokensApi.md +78 -0
- data/docs/generated/TtlDisplayUnit.md +15 -0
- data/docs/generated/UpdateMagicLinkAuthMethod.md +22 -0
- data/docs/generated/UpdateOtpAuthMethod.md +22 -0
- data/docs/generated/UpdatePasskeysAuthMethod.md +18 -0
- data/docs/generated/UpdateUserRequest.md +22 -0
- data/docs/generated/UserDevicesApi.md +152 -0
- data/docs/generated/UserEventInfo.md +26 -0
- data/docs/generated/UserInfo.md +46 -0
- data/docs/generated/UserMetadataField.md +28 -0
- data/docs/generated/UserMetadataFieldType.md +15 -0
- data/docs/generated/UserResponse.md +18 -0
- data/docs/generated/UserStatus.md +15 -0
- data/docs/generated/UsersApi.md +440 -0
- data/docs/generated/WebAuthnDevices.md +34 -0
- data/docs/generated/WebAuthnIcons.md +20 -0
- data/docs/generated/WebAuthnType.md +15 -0
- data/generate.sh +31 -0
- data/lib/openapi_client/api/apps_api.rb +85 -0
- data/lib/openapi_client/api/magic_links_api.rb +96 -0
- data/lib/openapi_client/api/tokens_api.rb +91 -0
- data/lib/openapi_client/api/user_devices_api.rb +166 -0
- data/lib/openapi_client/api/users_api.rb +452 -0
- data/lib/openapi_client/api_client.rb +431 -0
- data/lib/openapi_client/api_error.rb +58 -0
- data/lib/openapi_client/configuration.rb +383 -0
- data/lib/openapi_client/models/app_info.rb +853 -0
- data/lib/openapi_client/models/app_response.rb +221 -0
- data/lib/openapi_client/models/auth_methods.rb +254 -0
- data/lib/openapi_client/models/create_magic_link_request.rb +374 -0
- data/lib/openapi_client/models/create_user_request.rb +234 -0
- data/lib/openapi_client/models/element_customization.rb +457 -0
- data/lib/openapi_client/models/font_family.rb +58 -0
- data/lib/openapi_client/models/layout_config.rb +285 -0
- data/lib/openapi_client/models/layouts.rb +241 -0
- data/lib/openapi_client/models/list_devices_response.rb +223 -0
- data/lib/openapi_client/models/magic_link.rb +387 -0
- data/lib/openapi_client/models/magic_link_auth_method.rb +302 -0
- data/lib/openapi_client/models/magic_link_channel.rb +40 -0
- data/lib/openapi_client/models/magic_link_response.rb +221 -0
- data/lib/openapi_client/models/magic_link_type.rb +40 -0
- data/lib/openapi_client/models/model400_error.rb +271 -0
- data/lib/openapi_client/models/model401_error.rb +271 -0
- data/lib/openapi_client/models/model404_error.rb +271 -0
- data/lib/openapi_client/models/model500_error.rb +271 -0
- data/lib/openapi_client/models/otp_auth_method.rb +302 -0
- data/lib/openapi_client/models/passkeys_auth_method.rb +228 -0
- data/lib/openapi_client/models/technologies.rb +46 -0
- data/lib/openapi_client/models/ttl_display_unit.rb +42 -0
- data/lib/openapi_client/models/update_magic_link_auth_method.rb +276 -0
- data/lib/openapi_client/models/update_otp_auth_method.rb +276 -0
- data/lib/openapi_client/models/update_passkeys_auth_method.rb +216 -0
- data/lib/openapi_client/models/update_user_request.rb +232 -0
- data/lib/openapi_client/models/user_event_info.rb +285 -0
- data/lib/openapi_client/models/user_info.rb +470 -0
- data/lib/openapi_client/models/user_metadata_field.rb +323 -0
- data/lib/openapi_client/models/user_metadata_field_type.rb +44 -0
- data/lib/openapi_client/models/user_response.rb +221 -0
- data/lib/openapi_client/models/user_status.rb +41 -0
- data/lib/openapi_client/models/web_authn_devices.rb +378 -0
- data/lib/openapi_client/models/web_authn_icons.rb +230 -0
- data/lib/openapi_client/models/web_authn_type.rb +41 -0
- data/lib/openapi_client/version.rb +15 -0
- data/lib/openapi_client.rb +74 -0
- data/lib/passageidentity/auth.rb +32 -5
- data/lib/passageidentity/client.rb +17 -121
- data/lib/passageidentity/user_api.rb +29 -131
- data/lib/passageidentity/version.rb +5 -0
- data/openapitools.json +7 -0
- data/passageidentity.gemspec +3 -1
- data/tests/auth_test.rb +6 -1
- data/tests/magic_link_test.rb +5 -4
- data/tests/user_api_test.rb +2 -2
- metadata +96 -2
@@ -0,0 +1,74 @@
|
|
1
|
+
=begin
|
2
|
+
#Passage Management API
|
3
|
+
|
4
|
+
#Passage's management API to manage your Passage apps and users.
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1
|
7
|
+
Contact: support@passage.id
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 7.1.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
# Common files
|
14
|
+
require_relative 'openapi_client/api_client'
|
15
|
+
require_relative 'openapi_client/api_error'
|
16
|
+
require_relative 'openapi_client/version'
|
17
|
+
require_relative 'openapi_client/configuration'
|
18
|
+
|
19
|
+
# Models
|
20
|
+
require_relative 'openapi_client/models/app_info'
|
21
|
+
require_relative 'openapi_client/models/app_response'
|
22
|
+
require_relative 'openapi_client/models/auth_methods'
|
23
|
+
require_relative 'openapi_client/models/create_magic_link_request'
|
24
|
+
require_relative 'openapi_client/models/create_user_request'
|
25
|
+
require_relative 'openapi_client/models/element_customization'
|
26
|
+
require_relative 'openapi_client/models/font_family'
|
27
|
+
require_relative 'openapi_client/models/layout_config'
|
28
|
+
require_relative 'openapi_client/models/layouts'
|
29
|
+
require_relative 'openapi_client/models/list_devices_response'
|
30
|
+
require_relative 'openapi_client/models/magic_link_auth_method'
|
31
|
+
require_relative 'openapi_client/models/magic_link'
|
32
|
+
require_relative 'openapi_client/models/magic_link_channel'
|
33
|
+
require_relative 'openapi_client/models/magic_link_response'
|
34
|
+
require_relative 'openapi_client/models/magic_link_type'
|
35
|
+
require_relative 'openapi_client/models/model400_error'
|
36
|
+
require_relative 'openapi_client/models/model401_error'
|
37
|
+
require_relative 'openapi_client/models/model404_error'
|
38
|
+
require_relative 'openapi_client/models/model500_error'
|
39
|
+
require_relative 'openapi_client/models/otp_auth_method'
|
40
|
+
require_relative 'openapi_client/models/passkeys_auth_method'
|
41
|
+
require_relative 'openapi_client/models/technologies'
|
42
|
+
require_relative 'openapi_client/models/ttl_display_unit'
|
43
|
+
require_relative 'openapi_client/models/update_magic_link_auth_method'
|
44
|
+
require_relative 'openapi_client/models/update_otp_auth_method'
|
45
|
+
require_relative 'openapi_client/models/update_passkeys_auth_method'
|
46
|
+
require_relative 'openapi_client/models/update_user_request'
|
47
|
+
require_relative 'openapi_client/models/user_event_info'
|
48
|
+
require_relative 'openapi_client/models/user_info'
|
49
|
+
require_relative 'openapi_client/models/user_metadata_field'
|
50
|
+
require_relative 'openapi_client/models/user_metadata_field_type'
|
51
|
+
require_relative 'openapi_client/models/user_response'
|
52
|
+
require_relative 'openapi_client/models/user_status'
|
53
|
+
require_relative 'openapi_client/models/web_authn_devices'
|
54
|
+
require_relative 'openapi_client/models/web_authn_icons'
|
55
|
+
require_relative 'openapi_client/models/web_authn_type'
|
56
|
+
|
57
|
+
# APIs
|
58
|
+
require_relative 'openapi_client/api/apps_api'
|
59
|
+
require_relative 'openapi_client/api/magic_links_api'
|
60
|
+
require_relative 'openapi_client/api/tokens_api'
|
61
|
+
require_relative 'openapi_client/api/user_devices_api'
|
62
|
+
require_relative 'openapi_client/api/users_api'
|
63
|
+
|
64
|
+
module OpenapiClient
|
65
|
+
class << self
|
66
|
+
def configure
|
67
|
+
if block_given?
|
68
|
+
yield(Configuration.default)
|
69
|
+
else
|
70
|
+
Configuration.default
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/passageidentity/auth.rb
CHANGED
@@ -2,22 +2,24 @@ require "openssl"
|
|
2
2
|
require "base64"
|
3
3
|
require "jwt"
|
4
4
|
require_relative "client"
|
5
|
+
require_relative "../openapi_client"
|
5
6
|
|
6
7
|
module Passage
|
7
8
|
class Auth
|
8
9
|
@@app_cache = {}
|
9
|
-
def initialize(app_id, auth_strategy
|
10
|
+
def initialize(app_id, auth_strategy)
|
10
11
|
@app_id = app_id
|
11
12
|
@auth_strategy = auth_strategy
|
12
|
-
@connection = connection
|
13
13
|
|
14
14
|
fetch_jwks
|
15
15
|
end
|
16
16
|
|
17
17
|
def fetch_app()
|
18
18
|
begin
|
19
|
-
|
20
|
-
|
19
|
+
client = OpenapiClient::AppsApi.new
|
20
|
+
response = client.get_app(@app_id)
|
21
|
+
|
22
|
+
return response.app
|
21
23
|
rescue Faraday::Error => e
|
22
24
|
raise PassageError.new(
|
23
25
|
message: "failed to fetch passage app",
|
@@ -43,7 +45,8 @@ module Passage
|
|
43
45
|
|
44
46
|
# fetch the public key if not in cache
|
45
47
|
app = fetch_app
|
46
|
-
|
48
|
+
|
49
|
+
@auth_origin = app.auth_origin
|
47
50
|
response =
|
48
51
|
auth_gw_connection.get("/v1/apps/#{@app_id}/.well-known/jwks.json")
|
49
52
|
@jwks = response.body
|
@@ -52,6 +55,8 @@ module Passage
|
|
52
55
|
end
|
53
56
|
|
54
57
|
def authenticate_request(request)
|
58
|
+
warn "[DEPRECATION] `auth.authenticate_request()` is deprecated. Please use `auth.validate_jwt()` instead."
|
59
|
+
|
55
60
|
# Get the token based on the strategy
|
56
61
|
if @auth_strategy === Passage::COOKIE_STRATEGY
|
57
62
|
unless request.cookies.key?("psg_auth_token")
|
@@ -78,6 +83,14 @@ module Passage
|
|
78
83
|
nil
|
79
84
|
end
|
80
85
|
|
86
|
+
def validate_jwt(token)
|
87
|
+
if token
|
88
|
+
return authenticate_token(token)
|
89
|
+
else
|
90
|
+
raise PassageError.new(message: "no authentication token")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
81
94
|
def authenticate_token(token)
|
82
95
|
begin
|
83
96
|
kid = JWT.decode(token, nil, false)[1]["kid"]
|
@@ -114,5 +127,19 @@ module Passage
|
|
114
127
|
raise PassageError.new(message: e.message)
|
115
128
|
end
|
116
129
|
end
|
130
|
+
|
131
|
+
def revoke_user_refresh_tokens(user_id)
|
132
|
+
begin
|
133
|
+
client = OpenapiClient::TokensApi.new
|
134
|
+
response = client.revoke_user_refresh_tokens(@app_id, user_id)
|
135
|
+
return true
|
136
|
+
rescue Faraday::Error => e
|
137
|
+
raise PassageError.new(
|
138
|
+
message: "failed to revoke user's refresh tokens",
|
139
|
+
status_code: e.response[:status],
|
140
|
+
body: e.response[:body]
|
141
|
+
)
|
142
|
+
end
|
143
|
+
end
|
117
144
|
end
|
118
145
|
end
|
@@ -3,67 +3,11 @@
|
|
3
3
|
require_relative "auth"
|
4
4
|
require_relative "user_api"
|
5
5
|
require_relative "error"
|
6
|
+
require_relative "version"
|
6
7
|
require "rubygems"
|
8
|
+
require_relative "../openapi_client"
|
7
9
|
|
8
10
|
module Passage
|
9
|
-
App =
|
10
|
-
Struct.new :name,
|
11
|
-
:id,
|
12
|
-
:auth_origin,
|
13
|
-
:redirect_url,
|
14
|
-
:login_url,
|
15
|
-
:rsa_public_key,
|
16
|
-
:allowed_identifer,
|
17
|
-
:require_identifier_verification,
|
18
|
-
:session_timeout_length,
|
19
|
-
:refresh_enabled,
|
20
|
-
:refresh_absolute_lifetime,
|
21
|
-
:refresh_inactivity_lifetime,
|
22
|
-
:user_metadata_schema,
|
23
|
-
:layouts,
|
24
|
-
:default_language,
|
25
|
-
:auth_fallback_method,
|
26
|
-
:auth_fallback_method_ttl,
|
27
|
-
keyword_init: true
|
28
|
-
|
29
|
-
User =
|
30
|
-
Struct.new :id,
|
31
|
-
:status,
|
32
|
-
:email,
|
33
|
-
:phone,
|
34
|
-
:email_verified,
|
35
|
-
:phone_verified,
|
36
|
-
:created_at,
|
37
|
-
:updated_at,
|
38
|
-
:last_login_at,
|
39
|
-
:login_count,
|
40
|
-
:recent_events,
|
41
|
-
:webauthn,
|
42
|
-
:webauthn_devices,
|
43
|
-
:user_metadata,
|
44
|
-
keyword_init: true
|
45
|
-
MagicLink =
|
46
|
-
Struct.new :id,
|
47
|
-
:secret,
|
48
|
-
:activated,
|
49
|
-
:user_id,
|
50
|
-
:app_id,
|
51
|
-
:identifier,
|
52
|
-
:type,
|
53
|
-
:redirect_url,
|
54
|
-
:ttl,
|
55
|
-
:url,
|
56
|
-
keyword_init: true
|
57
|
-
Device =
|
58
|
-
Struct.new :id,
|
59
|
-
:cred_id,
|
60
|
-
:friendly_name,
|
61
|
-
:usage_count,
|
62
|
-
:updated_at,
|
63
|
-
:created_at,
|
64
|
-
:last_login_at,
|
65
|
-
keyword_init: true
|
66
|
-
|
67
11
|
COOKIE_STRATEGY = 0
|
68
12
|
HEADER_STRATEGY = 1
|
69
13
|
|
@@ -75,7 +19,6 @@ module Passage
|
|
75
19
|
attr_reader :user
|
76
20
|
|
77
21
|
def initialize(app_id:, api_key: "", auth_strategy: COOKIE_STRATEGY)
|
78
|
-
@api_url = "https://api.passage.id"
|
79
22
|
@app_id = app_id
|
80
23
|
@api_key = api_key
|
81
24
|
|
@@ -85,58 +28,17 @@ module Passage
|
|
85
28
|
end
|
86
29
|
@auth_strategy = auth_strategy
|
87
30
|
|
88
|
-
# setup
|
89
|
-
get_connection
|
90
|
-
|
91
31
|
# initialize auth class
|
92
|
-
@auth = Passage::Auth.new(@app_id, @auth_strategy
|
32
|
+
@auth = Passage::Auth.new(@app_id, @auth_strategy)
|
93
33
|
|
94
34
|
# initialize user class
|
95
|
-
@user = Passage::UserAPI.new(@
|
96
|
-
end
|
97
|
-
|
98
|
-
def get_connection
|
99
|
-
gemspec = File.join(__dir__, "../../passageidentity.gemspec")
|
100
|
-
spec = Gem::Specification.load(gemspec)
|
101
|
-
headers = { "Passage-Version" => "passage-ruby #{spec.version}" }
|
102
|
-
headers["Authorization"] = "Bearer #{@api_key}" if @api_key != ""
|
103
|
-
|
104
|
-
@connection =
|
105
|
-
Faraday.new(url: @api_url, headers: headers) do |f|
|
106
|
-
f.request :json
|
107
|
-
f.request :retry
|
108
|
-
f.response :raise_error
|
109
|
-
f.response :json
|
110
|
-
f.adapter :net_http
|
111
|
-
end
|
35
|
+
@user = Passage::UserAPI.new(@app_id, @api_key)
|
112
36
|
end
|
113
37
|
|
114
38
|
def get_app()
|
115
39
|
begin
|
116
|
-
|
117
|
-
return(
|
118
|
-
Passage::App.new(
|
119
|
-
name: app_info["name"],
|
120
|
-
id: app_info["id"],
|
121
|
-
auth_origin: app_info["auth_origin"],
|
122
|
-
redirect_url: app_info["redirect_url"],
|
123
|
-
login_url: app_info["login_url"],
|
124
|
-
rsa_public_key: app_info["rsa_public_key"],
|
125
|
-
allowed_identifer: app_info["allowed_identifer"],
|
126
|
-
require_identifier_verification:
|
127
|
-
app_info["require_identifier_verification"],
|
128
|
-
session_timeout_length: app_info["session_timeout_length"],
|
129
|
-
refresh_enabled: app_info["refresh_enabled"],
|
130
|
-
refresh_absolute_lifetime: app_info["refresh_absolute_lifetime"],
|
131
|
-
refresh_inactivity_lifetime:
|
132
|
-
app_info["refresh_inactivity_lifetime"],
|
133
|
-
user_metadata_schema: app_info["user_metadata_schema"],
|
134
|
-
layouts: app_info["layouts"],
|
135
|
-
default_language: app_info["default_language"],
|
136
|
-
auth_fallback_method: app_info["auth_fallback_method"],
|
137
|
-
auth_fallback_method_ttl: app_info["auth_fallback_method_ttl"]
|
138
|
-
)
|
139
|
-
)
|
40
|
+
client = OpenapiClient::AppsApi.new
|
41
|
+
return client.get_app(@app_id).app
|
140
42
|
rescue => e
|
141
43
|
raise e
|
142
44
|
end
|
@@ -176,23 +78,17 @@ module Passage
|
|
176
78
|
magic_link_req["type"] = type
|
177
79
|
|
178
80
|
begin
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
type: magic_link["type"],
|
191
|
-
redirect_url: magic_link["redirect_url"],
|
192
|
-
ttl: magic_link["ttl"],
|
193
|
-
url: magic_link["url"]
|
194
|
-
)
|
195
|
-
)
|
81
|
+
gemspec = File.join(__dir__, "../../passageidentity.gemspec")
|
82
|
+
spec = Gem::Specification.load(gemspec)
|
83
|
+
header_params = { "Passage-Version" => "passage-ruby #{Passage::VERSION}" }
|
84
|
+
header_params["Authorization"] = "Bearer #{@api_key}" if @api_key != ""
|
85
|
+
|
86
|
+
opts = {}
|
87
|
+
opts[:header_params] = header_params
|
88
|
+
opts[:debug_auth_names] = ["header"]
|
89
|
+
|
90
|
+
client = OpenapiClient::MagicLinksApi.new
|
91
|
+
return client.create_magic_link(@app_id, magic_link_req, opts).magic_link
|
196
92
|
rescue Faraday::Error => e
|
197
93
|
raise PassageError.new(
|
198
94
|
message: "failed to create Passage Magic Link",
|
@@ -3,37 +3,28 @@ require_relative "client"
|
|
3
3
|
module Passage
|
4
4
|
class UserAPI
|
5
5
|
# This class will require an API key
|
6
|
-
def initialize(
|
7
|
-
@connection = connection
|
6
|
+
def initialize(app_id, api_key)
|
8
7
|
@app_id = app_id
|
9
8
|
@api_key = api_key
|
9
|
+
@user_client = OpenapiClient::UsersApi.new
|
10
|
+
@user_device_client = OpenapiClient::UserDevicesApi.new
|
11
|
+
|
12
|
+
header_params = { "Passage-Version" => "passage-ruby #{Passage::VERSION}"}
|
13
|
+
header_params["Authorization"] = "Bearer #{@api_key}" if @api_key != ""
|
14
|
+
|
15
|
+
@req_opts = {}
|
16
|
+
@req_opts[:header_params] = header_params
|
17
|
+
@req_opts[:debug_auth_names] = ["header"]
|
18
|
+
|
10
19
|
end
|
11
20
|
|
12
21
|
def get(user_id:)
|
13
22
|
user_exists?(user_id)
|
14
23
|
|
15
24
|
begin
|
16
|
-
response = @
|
17
|
-
user = response.
|
18
|
-
user
|
19
|
-
return(
|
20
|
-
Passage::User.new(
|
21
|
-
id: user["id"],
|
22
|
-
status: user["status"],
|
23
|
-
email: user["email"],
|
24
|
-
phone: user["phone"],
|
25
|
-
email_verified: user["email_verified"],
|
26
|
-
phone_verified: user["phone_verified"],
|
27
|
-
created_at: user["created_at"],
|
28
|
-
updated_at: user["updated_at"],
|
29
|
-
last_login_at: user["last_login_at"],
|
30
|
-
login_count: user["login_count"],
|
31
|
-
webauthn: user["webauthn"],
|
32
|
-
webauthn_devices: user["webauthn_devices"],
|
33
|
-
recent_events: user["recent_events"],
|
34
|
-
user_metadata: user["user_metadata"]
|
35
|
-
)
|
36
|
-
)
|
25
|
+
response = @user_client.get_user(@app_id, user_id, @req_opts)
|
26
|
+
user = response.user
|
27
|
+
return user
|
37
28
|
rescue Faraday::Error => e
|
38
29
|
if e.is_a? Faraday::ResourceNotFound
|
39
30
|
raise PassageError.new(
|
@@ -55,27 +46,8 @@ module Passage
|
|
55
46
|
user_exists?(user_id)
|
56
47
|
|
57
48
|
begin
|
58
|
-
response =
|
59
|
-
|
60
|
-
user = response.body["user"]
|
61
|
-
return(
|
62
|
-
Passage::User.new(
|
63
|
-
id: user["id"],
|
64
|
-
status: user["status"],
|
65
|
-
email: user["email"],
|
66
|
-
phone: user["phone"],
|
67
|
-
email_verified: user["email_verified"],
|
68
|
-
phone_verified: user["phone_verified"],
|
69
|
-
created_at: user["created_at"],
|
70
|
-
updated_at: user["updated_at"],
|
71
|
-
last_login_at: user["last_login_at"],
|
72
|
-
login_count: user["login_count"],
|
73
|
-
webauthn: user["webauthn"],
|
74
|
-
webauthn_devices: user["webauthn_devices"],
|
75
|
-
recent_events: user["recent_events"],
|
76
|
-
user_metadata: user["user_metadata"]
|
77
|
-
)
|
78
|
-
)
|
49
|
+
response = @user_client.activate_user(@app_id, user_id, @req_opts)
|
50
|
+
return response.user
|
79
51
|
rescue Faraday::Error => e
|
80
52
|
if e.is_a? Faraday::ResourceNotFound
|
81
53
|
raise PassageError.new(
|
@@ -97,27 +69,8 @@ module Passage
|
|
97
69
|
user_exists?(user_id)
|
98
70
|
|
99
71
|
begin
|
100
|
-
response =
|
101
|
-
|
102
|
-
user = response.body["user"]
|
103
|
-
return(
|
104
|
-
Passage::User.new(
|
105
|
-
id: user["id"],
|
106
|
-
status: user["status"],
|
107
|
-
email: user["email"],
|
108
|
-
phone: user["phone"],
|
109
|
-
email_verified: user["email_verified"],
|
110
|
-
phone_verified: user["phone_verified"],
|
111
|
-
created_at: user["created_at"],
|
112
|
-
updated_at: user["updated_at"],
|
113
|
-
last_login_at: user["last_login_at"],
|
114
|
-
login_count: user["login_count"],
|
115
|
-
webauthn: user["webauthn"],
|
116
|
-
webauthn_devices: user["webauthn_devices"],
|
117
|
-
recent_events: user["recent_events"],
|
118
|
-
user_metadata: user["user_metadata"]
|
119
|
-
)
|
120
|
-
)
|
72
|
+
response = @user_client.deactivate_user(@app_id, user_id, @req_opts)
|
73
|
+
return response.user
|
121
74
|
rescue Faraday::Error => e
|
122
75
|
if e.is_a? Faraday::ResourceNotFound
|
123
76
|
raise PassageError.new(
|
@@ -143,27 +96,8 @@ module Passage
|
|
143
96
|
updates["phone"] = phone unless phone.empty?
|
144
97
|
updates["user_metadata"] = user_metadata unless user_metadata.empty?
|
145
98
|
begin
|
146
|
-
response =
|
147
|
-
|
148
|
-
user = response.body["user"]
|
149
|
-
return(
|
150
|
-
Passage::User.new(
|
151
|
-
id: user["id"],
|
152
|
-
status: user["status"],
|
153
|
-
email: user["email"],
|
154
|
-
phone: user["phone"],
|
155
|
-
email_verified: user["email_verified"],
|
156
|
-
phone_verified: user["phone_verified"],
|
157
|
-
created_at: user["created_at"],
|
158
|
-
updated_at: user["updated_at"],
|
159
|
-
last_login_at: user["last_login_at"],
|
160
|
-
login_count: user["login_count"],
|
161
|
-
webauthn: user["webauthn"],
|
162
|
-
webauthn_devices: user["webauthn_devices"],
|
163
|
-
recent_events: user["recent_events"],
|
164
|
-
user_metadata: user["user_metadata"]
|
165
|
-
)
|
166
|
-
)
|
99
|
+
response = @user_client.update_user(@app_id, user_id, updates, @req_opts)
|
100
|
+
return response.user
|
167
101
|
rescue Faraday::Error => e
|
168
102
|
if e.is_a? Faraday::ResourceNotFound
|
169
103
|
raise PassageError.new(
|
@@ -187,26 +121,8 @@ module Passage
|
|
187
121
|
create["phone"] = phone unless phone.empty?
|
188
122
|
create["user_metadata"] = user_metadata unless user_metadata.empty?
|
189
123
|
begin
|
190
|
-
response = @
|
191
|
-
|
192
|
-
return(
|
193
|
-
Passage::User.new(
|
194
|
-
id: user["id"],
|
195
|
-
status: user["status"],
|
196
|
-
email: user["email"],
|
197
|
-
phone: user["phone"],
|
198
|
-
email_verified: user["email_verified"],
|
199
|
-
phone_verified: user["phone_verified"],
|
200
|
-
created_at: user["created_at"],
|
201
|
-
updated_at: user["updated_at"],
|
202
|
-
last_login_at: user["last_login_at"],
|
203
|
-
login_count: user["login_count"],
|
204
|
-
webauthn: user["webauthn"],
|
205
|
-
webauthn_devices: user["webauthn_devices"],
|
206
|
-
recent_events: user["recent_events"],
|
207
|
-
user_metadata: user["user_metadata"]
|
208
|
-
)
|
209
|
-
)
|
124
|
+
response = @user_client.create_user(@app_id, create, @req_opts)
|
125
|
+
return response.user
|
210
126
|
rescue Faraday::Error => e
|
211
127
|
raise PassageError.new(
|
212
128
|
"failed to create Passage User",
|
@@ -220,7 +136,7 @@ module Passage
|
|
220
136
|
user_exists?(user_id)
|
221
137
|
|
222
138
|
begin
|
223
|
-
response = @
|
139
|
+
response = @user_client.delete_user(@app_id, user_id, @req_opts)
|
224
140
|
return true
|
225
141
|
rescue Faraday::Error => e
|
226
142
|
if e.is_a? Faraday::ResourceNotFound
|
@@ -244,10 +160,7 @@ module Passage
|
|
244
160
|
device_exists?(device_id)
|
245
161
|
|
246
162
|
begin
|
247
|
-
response =
|
248
|
-
@connection.delete(
|
249
|
-
"/v1/apps/#{@app_id}/users/#{user_id}/devices/#{device_id}"
|
250
|
-
)
|
163
|
+
response = @user_device_client.delete_user_devices(@app_id, user_id, device_id, @req_opts)
|
251
164
|
return true
|
252
165
|
rescue Faraday::Error => e
|
253
166
|
raise PassageError.new(
|
@@ -262,24 +175,8 @@ module Passage
|
|
262
175
|
user_exists?(user_id)
|
263
176
|
|
264
177
|
begin
|
265
|
-
response =
|
266
|
-
|
267
|
-
devicesResp = response.body["devices"]
|
268
|
-
devices = Array.new
|
269
|
-
devicesResp.each do |device|
|
270
|
-
devices.append(
|
271
|
-
Passage::Device.new(
|
272
|
-
id: device["id"],
|
273
|
-
cred_id: device["cred_id"],
|
274
|
-
friendly_name: device["friendly_name"],
|
275
|
-
usage_count: device["usage_count"],
|
276
|
-
updated_at: device["updated_at"],
|
277
|
-
created_at: device["created_at"],
|
278
|
-
last_login_at: device["last_login_at"]
|
279
|
-
)
|
280
|
-
)
|
281
|
-
end
|
282
|
-
return devices
|
178
|
+
response = @user_device_client.list_user_devices(@app_id, user_id, @req_opts)
|
179
|
+
return response.devices
|
283
180
|
rescue Faraday::Error => e
|
284
181
|
raise PassageError.new(
|
285
182
|
"failed to delete Passage User Device",
|
@@ -290,10 +187,11 @@ module Passage
|
|
290
187
|
end
|
291
188
|
|
292
189
|
def signout(user_id:)
|
190
|
+
warn "[DEPRECATION] `user.signout()` is deprecated. Please use `auth.revoke_user_refresh_tokens()` instead."
|
293
191
|
user_exists?(user_id)
|
294
192
|
begin
|
295
|
-
|
296
|
-
|
193
|
+
tokens_client = OpenapiClient::TokensApi.new
|
194
|
+
response = tokens_client.revoke_user_refresh_tokens(@app_id, user_id, @req_opts)
|
297
195
|
return true
|
298
196
|
rescue Faraday::Error => e
|
299
197
|
raise PassageError.new(
|
data/openapitools.json
ADDED
data/passageidentity.gemspec
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
require_relative 'lib/passageidentity/version'
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
4
|
s.name = 'passageidentity'
|
3
|
-
s.version =
|
5
|
+
s.version = Passage::VERSION
|
4
6
|
s.summary = 'Passage SDK for biometric authentication'
|
5
7
|
s.description =
|
6
8
|
'Enables verification of server-side authentication and user management for applications using Passage'
|
data/tests/auth_test.rb
CHANGED
@@ -5,7 +5,7 @@ require "rack"
|
|
5
5
|
require "test/unit"
|
6
6
|
|
7
7
|
Dotenv.load(".env")
|
8
|
-
class
|
8
|
+
class TestAuthAPI < Test::Unit::TestCase
|
9
9
|
PassageClient =
|
10
10
|
Passage::Client.new(app_id: ENV["APP_ID"], api_key: ENV["API_KEY"])
|
11
11
|
PassageHeaderClient =
|
@@ -15,6 +15,11 @@ class TestUserAPI < Test::Unit::TestCase
|
|
15
15
|
auth_strategy: Passage::HEADER_STRATEGY
|
16
16
|
)
|
17
17
|
|
18
|
+
def test_valid_jwt
|
19
|
+
user_id = PassageClient.auth.validate_jwt(ENV["PSG_JWT"])
|
20
|
+
assert_equal ENV["TEST_USER_ID"], user_id
|
21
|
+
end
|
22
|
+
|
18
23
|
def test_valid_authenticate_token
|
19
24
|
user_id = PassageClient.auth.authenticate_token(ENV["PSG_JWT"])
|
20
25
|
assert_equal ENV["TEST_USER_ID"], user_id
|
data/tests/magic_link_test.rb
CHANGED
@@ -4,18 +4,19 @@ require "faraday"
|
|
4
4
|
require "test/unit"
|
5
5
|
|
6
6
|
Dotenv.load(".env")
|
7
|
-
class
|
7
|
+
class TestMagicLinkAPI < Test::Unit::TestCase
|
8
8
|
PassageClient =
|
9
9
|
Passage::Client.new(app_id: ENV["APP_ID"], api_key: ENV["API_KEY"])
|
10
10
|
|
11
|
-
def
|
11
|
+
def test_create_magic_link()
|
12
12
|
magic_link =
|
13
13
|
PassageClient.create_magic_link(
|
14
14
|
email: "chris@passage.id",
|
15
15
|
channel: Passage::EMAIL_CHANNEL,
|
16
|
-
ttl:
|
16
|
+
ttl: 122
|
17
17
|
)
|
18
|
-
|
18
|
+
|
19
|
+
assert_equal 122, magic_link.ttl
|
19
20
|
assert_equal "chris@passage.id", magic_link.identifier
|
20
21
|
end
|
21
22
|
end
|
data/tests/user_api_test.rb
CHANGED
@@ -27,7 +27,7 @@ class TestUserAPI < Test::Unit::TestCase
|
|
27
27
|
}
|
28
28
|
)
|
29
29
|
assert_equal "chris+test-create-delete@passage.id", user.email
|
30
|
-
assert_equal "cool", user.user_metadata[
|
30
|
+
assert_equal "cool", user.user_metadata[:example1]
|
31
31
|
deleted = PassageClient.user.delete(user_id: user.id)
|
32
32
|
assert_equal true, deleted
|
33
33
|
end
|
@@ -61,7 +61,7 @@ class TestUserAPI < Test::Unit::TestCase
|
|
61
61
|
)
|
62
62
|
assert_equal $global_test_user.id, user.id
|
63
63
|
assert_equal new_email, user.email
|
64
|
-
assert_equal "lame", user.user_metadata[
|
64
|
+
assert_equal "lame", user.user_metadata[:example1]
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_list_devices()
|