stytch 4.4.0 → 4.5.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: d2a9ecc30de6afe24d2a2bcc37d47d72cdc617f20339b03184b7ce60badc37e5
4
- data.tar.gz: 34dc8549f4ccdd667f6bf02a351e0b8bf0292c8027ccb301144e6377013dcfce
3
+ metadata.gz: ee8240601c590ea9fac8e84fc7d93370c6244cbb028ea0cbf881794d9c78aad9
4
+ data.tar.gz: 531fd7ba0fd00397152083c2f99417e5fd0982c8ee53b9d578e207e530381bd6
5
5
  SHA512:
6
- metadata.gz: 972b2a3aecca06699d3d3ca1a2812f1062ea3bc463d0e0ed274421cf71058b63309daa81c2ae2b5a37de14c38cf9b5dfea80a20d5129f9b3b985bdf761417e24
7
- data.tar.gz: 2a58549c33709a42cccb4b29eb791bf471c88c62c7f939e619002f8298be7621c049c63bb1c55fe5d68676e10d3310b677364ef0e67040fc044e3f33ce0a9fa1
6
+ metadata.gz: d352d1e8faf1fb38cc73cf30b8229cbb30cca0b9cf4fc2ee782e35fdad9e43343df1a6ea404261eca11012586b800a3dc3a856fada4e5ff52bc9371f0a285acd
7
+ data.tar.gz: 3e3199bfcf473eb6d19efe139a918dda570a42ace8fdfcd5a07af856107f4fa495cfd18a28e8c7a825791217ba25036a9bdbd541925180563c528b3411330767
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'b2b_magic_links'
4
+ require_relative 'b2b_organizations'
5
+ require_relative 'b2b_passwords'
6
+ require_relative 'b2b_sessions'
7
+ require_relative 'b2b_sso'
8
+
9
+ module StytchB2B
10
+ class Client
11
+ ENVIRONMENTS = %i[live test].freeze
12
+
13
+ attr_reader :magic_links, :organizations, :passwords, :sso, :sessions
14
+
15
+ def initialize(project_id:, secret:, env: nil, &block)
16
+ @api_host = api_host(env, project_id)
17
+ @project_id = project_id
18
+ @secret = secret
19
+
20
+ create_connection(&block)
21
+
22
+ @magic_links = StytchB2B::MagicLinks.new(@connection)
23
+ @organizations = StytchB2B::Organizations.new(@connection)
24
+ @passwords = StytchB2B::Passwords.new(@connection)
25
+ @sso = StytchB2B::SSO.new(@connection)
26
+ @sessions = StytchB2B::Sessions.new(@connection)
27
+ end
28
+
29
+ private
30
+
31
+ def api_host(env, project_id)
32
+ case env
33
+ when :live
34
+ 'https://api.stytch.com'
35
+ when :test
36
+ 'https://test.stytch.com'
37
+ when %r{\Ahttps?://}
38
+ # If this is a string that looks like a URL, assume it's an internal development URL.
39
+ env
40
+ else
41
+ if project_id.start_with? 'project-live-'
42
+ 'https://api.stytch.com'
43
+ else
44
+ 'https://test.stytch.com'
45
+ end
46
+ end
47
+ end
48
+
49
+ def create_connection
50
+ @connection = Faraday.new(url: @api_host) do |builder|
51
+ block_given? ? yield(builder) : build_default_connection(builder)
52
+ end
53
+ @connection.basic_auth(@project_id, @secret)
54
+ end
55
+
56
+ def build_default_connection(builder)
57
+ builder.options[:timeout] = Stytch::Middleware::NETWORK_TIMEOUT
58
+ builder.headers = Stytch::Middleware::NETWORK_HEADERS
59
+ builder.request :json
60
+ builder.use Stytch::Middleware
61
+ builder.response :json, content_type: /\bjson$/
62
+ builder.adapter Faraday.default_adapter
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'request_helper'
4
+
5
+ module StytchB2B
6
+ class Discovery
7
+ include Stytch::RequestHelper
8
+ attr_reader :intermediate_sessions, :organizations
9
+
10
+ def initialize(connection)
11
+ @connection = connection
12
+
13
+ @intermediate_sessions = StytchB2B::Discovery::IntermediateSessions.new(@connection)
14
+ @organizations = StytchB2B::Discovery::Organizations.new(@connection)
15
+ end
16
+
17
+ class IntermediateSessions
18
+ include Stytch::RequestHelper
19
+
20
+ def initialize(connection)
21
+ @connection = connection
22
+ end
23
+
24
+ def exchange(
25
+ intermediate_session_token:,
26
+ organization_id:,
27
+ session_duration_minutes: nil,
28
+ session_custom_claims: nil
29
+ )
30
+ request = {
31
+ intermediate_session_token: intermediate_session_token,
32
+ organization_id: organization_id
33
+ }
34
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
35
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
36
+
37
+ post_request('/v1/b2b/discovery/intermediate_sessions/exchange', request)
38
+ end
39
+ end
40
+
41
+ class Organizations
42
+ include Stytch::RequestHelper
43
+
44
+ def initialize(connection)
45
+ @connection = connection
46
+ end
47
+
48
+ def create(
49
+ intermediate_session_token:,
50
+ organization_name:,
51
+ organization_slug:,
52
+ session_duration_minutes: nil,
53
+ session_custom_claims: nil,
54
+ organization_logo_url: nil,
55
+ trusted_metadata: nil,
56
+ sso_jit_provisioning: nil,
57
+ email_allowed_domains: nil,
58
+ email_jit_provisioning: nil,
59
+ email_invites: nil,
60
+ auth_methods: nil,
61
+ allowed_auth_methods: nil
62
+ )
63
+ request = {
64
+ intermediate_session_token: intermediate_session_token,
65
+ organization_name: organization_name,
66
+ organization_slug: organization_slug
67
+ }
68
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
69
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
70
+ request[:organization_logo_url] = organization_logo_url unless organization_logo_url.nil?
71
+ request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
72
+ request[:sso_jit_provisioning] = sso_jit_provisioning unless sso_jit_provisioning.nil?
73
+ request[:email_allowed_domains] = email_allowed_domains unless email_allowed_domains.nil?
74
+ request[:email_jit_provisioning] = email_jit_provisioning unless email_jit_provisioning.nil?
75
+ request[:email_invites] = email_invites unless email_invites.nil?
76
+ request[:auth_methods] = auth_methods unless auth_methods.nil?
77
+ request[:allowed_auth_methods] = allowed_auth_methods unless allowed_auth_methods.nil?
78
+
79
+ post_request('/v1/b2b/discovery/organizations/create', request)
80
+ end
81
+
82
+ def list(
83
+ intermediate_session_token: nil,
84
+ session_token: nil,
85
+ session_jwt: nil
86
+ )
87
+ request = {}
88
+ request[:intermediate_session_token] = intermediate_session_token unless intermediate_session_token.nil?
89
+ request[:session_token] = session_token unless session_token.nil?
90
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
91
+
92
+ post_request('/v1/b2b/discovery/organizations', request)
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'request_helper'
4
+
5
+ module StytchB2B
6
+ class MagicLinks
7
+ include Stytch::RequestHelper
8
+ attr_reader :email, :discovery
9
+
10
+ def initialize(connection)
11
+ @connection = connection
12
+
13
+ @email = StytchB2B::MagicLinks::Email.new(@connection)
14
+ @discovery = StytchB2B::MagicLinks::Discovery.new(@connection)
15
+ end
16
+
17
+ def authenticate(
18
+ magic_links_token:,
19
+ pkce_code_verifier: nil,
20
+ session_token: nil,
21
+ session_jwt: nil,
22
+ session_duration_minutes: nil,
23
+ session_custom_claims: nil
24
+ )
25
+ request = {
26
+ magic_links_token: magic_links_token
27
+ }
28
+ request[:pkce_code_verifier] = pkce_code_verifier unless pkce_code_verifier.nil?
29
+ request[:session_token] = session_token unless session_token.nil?
30
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
31
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
32
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
33
+
34
+ post_request('/v1/b2b/magic_links/authenticate', request)
35
+ end
36
+
37
+ class Email
38
+ include Stytch::RequestHelper
39
+ attr_reader :discovery
40
+
41
+ def initialize(connection)
42
+ @connection = connection
43
+
44
+ @discovery = StytchB2B::MagicLinks::Email::Discovery.new(@connection)
45
+ end
46
+
47
+ def login_or_signup(
48
+ organization_id:,
49
+ email_address:,
50
+ login_redirect_url: nil,
51
+ signup_redirect_url: nil,
52
+ pkce_code_challenge: nil,
53
+ login_template_id: nil,
54
+ signup_template_id: nil,
55
+ locale: nil
56
+ )
57
+ request = {
58
+ organization_id: organization_id,
59
+ email_address: email_address
60
+ }
61
+ request[:login_redirect_url] = login_redirect_url unless login_redirect_url.nil?
62
+ request[:signup_redirect_url] = signup_redirect_url unless signup_redirect_url.nil?
63
+ request[:pkce_code_challenge] = pkce_code_challenge unless pkce_code_challenge.nil?
64
+ request[:login_template_id] = login_template_id unless login_template_id.nil?
65
+ request[:signup_template_id] = signup_template_id unless signup_template_id.nil?
66
+ request[:locale] = locale unless locale.nil?
67
+
68
+ post_request('/v1/b2b/magic_links/email/login_or_signup', request)
69
+ end
70
+
71
+ def invite(
72
+ organization_id:,
73
+ email_address:,
74
+ invite_redirect_url: nil,
75
+ invited_by_member_id: nil,
76
+ name: nil,
77
+ trusted_metadata: nil,
78
+ untrusted_metadata: nil,
79
+ invite_template_id: nil,
80
+ locale: nil
81
+ )
82
+ request = {
83
+ organization_id: organization_id,
84
+ email_address: email_address
85
+ }
86
+ request[:invite_redirect_url] = invite_redirect_url unless invite_redirect_url.nil?
87
+ request[:invited_by_member_id] = invited_by_member_id unless invited_by_member_id.nil?
88
+ request[:name] = name unless name.nil?
89
+ request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
90
+ request[:untrusted_metadata] = untrusted_metadata unless untrusted_metadata.nil?
91
+ request[:invite_template_id] = invite_template_id unless invite_template_id.nil?
92
+ request[:locale] = locale unless locale.nil?
93
+
94
+ post_request('/v1/b2b/magic_links/email/invite', request)
95
+ end
96
+
97
+ class Discovery
98
+ include Stytch::RequestHelper
99
+
100
+ def initialize(connection)
101
+ @connection = connection
102
+ end
103
+
104
+ def send(
105
+ email_address:,
106
+ discovery_redirect_url: nil,
107
+ pkce_code_challenge: nil,
108
+ login_template_id: nil,
109
+ locale: nil
110
+ )
111
+ request = {
112
+ email_address: email_address
113
+ }
114
+ request[:discovery_redirect_url] = discovery_redirect_url unless discovery_redirect_url.nil?
115
+ request[:pkce_code_challenge] = pkce_code_challenge unless pkce_code_challenge.nil?
116
+ request[:login_template_id] = login_template_id unless login_template_id.nil?
117
+ request[:locale] = locale unless locale.nil?
118
+
119
+ post_request('/v1/b2b/magic_links/email/discovery/send', request)
120
+ end
121
+ end
122
+ end
123
+
124
+ class Discovery
125
+ include Stytch::RequestHelper
126
+
127
+ def initialize(connection)
128
+ @connection = connection
129
+ end
130
+
131
+ def authenticate(
132
+ discovery_magic_links_token:,
133
+ pkce_code_verifier: nil
134
+ )
135
+ request = {
136
+ discovery_magic_links_token: discovery_magic_links_token
137
+ }
138
+ request[:pkce_code_verifier] = pkce_code_verifier unless pkce_code_verifier.nil?
139
+
140
+ post_request('/v1/b2b/magic_links/discovery/authenticate', request)
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,204 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'request_helper'
4
+
5
+ module StytchB2B
6
+ class Organizations
7
+ include Stytch::RequestHelper
8
+ attr_reader :members
9
+
10
+ def initialize(connection)
11
+ @connection = connection
12
+
13
+ @members = StytchB2B::Organizations::Members.new(@connection)
14
+ end
15
+
16
+ def create(
17
+ organization_name:,
18
+ organization_slug:,
19
+ organization_logo_url: nil,
20
+ trusted_metadata: nil,
21
+ sso_jit_provisioning: nil,
22
+ email_allowed_domains: nil,
23
+ email_jit_provisioning: nil,
24
+ email_invites: nil,
25
+ auth_methods: nil,
26
+ allowed_auth_methods: nil
27
+ )
28
+ request = {
29
+ organization_name: organization_name,
30
+ organization_slug: organization_slug
31
+ }
32
+ request[:organization_logo_url] = organization_logo_url unless organization_logo_url.nil?
33
+ request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
34
+ request[:sso_jit_provisioning] = sso_jit_provisioning unless sso_jit_provisioning.nil?
35
+ request[:email_allowed_domains] = email_allowed_domains unless email_allowed_domains.nil?
36
+ request[:email_jit_provisioning] = email_jit_provisioning unless email_jit_provisioning.nil?
37
+ request[:email_invites] = email_invites unless email_invites.nil?
38
+ request[:auth_methods] = auth_methods unless auth_methods.nil?
39
+ request[:allowed_auth_methods] = allowed_auth_methods unless allowed_auth_methods.nil?
40
+
41
+ post_request('/v1/b2b/organizations', request)
42
+ end
43
+
44
+ def get(
45
+ organization_id:
46
+ )
47
+ query_params = {
48
+ organization_id: organization_id
49
+ }
50
+ request = request_with_query_params("/v1/b2b/organizations/#{organization_id}", query_params)
51
+ get_request(request)
52
+ end
53
+
54
+ def update(
55
+ organization_id:,
56
+ organization_name: nil,
57
+ organization_slug: nil,
58
+ organization_logo_url: nil,
59
+ trusted_metadata: nil,
60
+ sso_default_connection_id: nil,
61
+ sso_jit_provisioning: nil,
62
+ sso_jit_provisioning_allowed_connections: nil,
63
+ email_allowed_domains: nil,
64
+ email_jit_provisioning: nil,
65
+ email_invites: nil,
66
+ auth_methods: nil,
67
+ allowed_auth_methods: nil
68
+ )
69
+ request = {
70
+ organization_id: organization_id
71
+ }
72
+ request[:organization_name] = organization_name unless organization_name.nil?
73
+ request[:organization_slug] = organization_slug unless organization_slug.nil?
74
+ request[:organization_logo_url] = organization_logo_url unless organization_logo_url.nil?
75
+ request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
76
+ request[:sso_default_connection_id] = sso_default_connection_id unless sso_default_connection_id.nil?
77
+ request[:sso_jit_provisioning] = sso_jit_provisioning unless sso_jit_provisioning.nil?
78
+ unless sso_jit_provisioning_allowed_connections.nil?
79
+ request[:sso_jit_provisioning_allowed_connections] =
80
+ sso_jit_provisioning_allowed_connections
81
+ end
82
+ request[:email_allowed_domains] = email_allowed_domains unless email_allowed_domains.nil?
83
+ request[:email_jit_provisioning] = email_jit_provisioning unless email_jit_provisioning.nil?
84
+ request[:email_invites] = email_invites unless email_invites.nil?
85
+ request[:auth_methods] = auth_methods unless auth_methods.nil?
86
+ request[:allowed_auth_methods] = allowed_auth_methods unless allowed_auth_methods.nil?
87
+
88
+ put_request("/v1/b2b/organizations/#{organization_id}", request)
89
+ end
90
+
91
+ def delete(
92
+ organization_id:
93
+ )
94
+ delete_request("/v1/b2b/organizations/#{organization_id}")
95
+ end
96
+
97
+ def search(
98
+ cursor: nil,
99
+ limit: nil,
100
+ query: nil
101
+ )
102
+ request = {}
103
+ request[:cursor] = cursor unless cursor.nil?
104
+ request[:limit] = limit unless limit.nil?
105
+ request[:query] = query unless query.nil?
106
+
107
+ post_request('/v1/b2b/organizations/search', request)
108
+ end
109
+
110
+ class Members
111
+ include Stytch::RequestHelper
112
+
113
+ def initialize(connection)
114
+ @connection = connection
115
+ end
116
+
117
+ def create(
118
+ organization_id:,
119
+ email_address:,
120
+ name: nil,
121
+ trusted_metadata: nil,
122
+ untrusted_metadata: nil,
123
+ create_member_as_pending: nil,
124
+ is_breakglass: nil
125
+ )
126
+ request = {
127
+ organization_id: organization_id,
128
+ email_address: email_address
129
+ }
130
+ request[:name] = name unless name.nil?
131
+ request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
132
+ request[:untrusted_metadata] = untrusted_metadata unless untrusted_metadata.nil?
133
+ request[:create_member_as_pending] = create_member_as_pending unless create_member_as_pending.nil?
134
+ request[:is_breakglass] = is_breakglass unless is_breakglass.nil?
135
+
136
+ post_request("/v1/b2b/organizations/#{organization_id}/members", request)
137
+ end
138
+
139
+ def get(
140
+ organization_id:,
141
+ member_id: nil,
142
+ email_address: nil
143
+ )
144
+ query_params = {
145
+ organization_id: organization_id,
146
+ member_id: member_id,
147
+ email_address: email_address
148
+ }
149
+ request = request_with_query_params("/v1/b2b/organizations/#{organization_id}/member", query_params)
150
+ get_request(request)
151
+ end
152
+
153
+ def update(
154
+ organization_id:,
155
+ member_id:,
156
+ name: nil,
157
+ trusted_metadata: nil,
158
+ untrusted_metadata: nil,
159
+ is_breakglass: nil
160
+ )
161
+ request = {
162
+ organization_id: organization_id,
163
+ member_id: member_id
164
+ }
165
+ request[:name] = name unless name.nil?
166
+ request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
167
+ request[:untrusted_metadata] = untrusted_metadata unless untrusted_metadata.nil?
168
+ request[:is_breakglass] = is_breakglass unless is_breakglass.nil?
169
+
170
+ put_request("/v1/b2b/organizations/#{organization_id}/members/#{member_id}", request)
171
+ end
172
+
173
+ def delete(
174
+ organization_id:,
175
+ member_id:
176
+ )
177
+ delete_request("/v1/b2b/organizations/#{organization_id}/members/#{member_id}")
178
+ end
179
+
180
+ def search(
181
+ organization_ids:,
182
+ cursor: nil,
183
+ limit: nil,
184
+ query: nil
185
+ )
186
+ request = {
187
+ organization_ids: organization_ids
188
+ }
189
+ request[:cursor] = cursor unless cursor.nil?
190
+ request[:limit] = limit unless limit.nil?
191
+ request[:query] = query unless query.nil?
192
+
193
+ post_request('/v1/b2b/organizations/members/search', request)
194
+ end
195
+
196
+ def organizations_delete_password(
197
+ organization_id:,
198
+ member_password_id:
199
+ )
200
+ delete_request("/v1/b2b/organizations/#{organization_id}/members/passwords/#{member_password_id}")
201
+ end
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,195 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'request_helper'
4
+
5
+ module StytchB2B
6
+ class Passwords
7
+ include Stytch::RequestHelper
8
+ attr_reader :email, :sessions, :existing_password
9
+
10
+ def initialize(connection)
11
+ @connection = connection
12
+
13
+ @email = StytchB2B::Passwords::Email.new(@connection)
14
+ @sessions = StytchB2B::Passwords::Sessions.new(@connection)
15
+ @existing_password = StytchB2B::Passwords::ExistingPassword.new(@connection)
16
+ end
17
+
18
+ def strength_check(
19
+ password:,
20
+ email_address: nil
21
+ )
22
+ request = {
23
+ password: password
24
+ }
25
+ request[:email_address] = email_address unless email_address.nil?
26
+
27
+ post_request('/v1/b2b/passwords/strength_check', request)
28
+ end
29
+
30
+ def migrate(
31
+ email_address:,
32
+ hash:,
33
+ hash_type:,
34
+ organization_id:,
35
+ md_5_config: nil,
36
+ argon_2_config: nil,
37
+ sha_1_config: nil,
38
+ scrypt_config: nil,
39
+ name: nil,
40
+ trusted_metadata: nil,
41
+ untrusted_metadata: nil
42
+ )
43
+ request = {
44
+ email_address: email_address,
45
+ hash: hash,
46
+ hash_type: hash_type,
47
+ organization_id: organization_id
48
+ }
49
+ request[:md_5_config] = md_5_config unless md_5_config.nil?
50
+ request[:argon_2_config] = argon_2_config unless argon_2_config.nil?
51
+ request[:sha_1_config] = sha_1_config unless sha_1_config.nil?
52
+ request[:scrypt_config] = scrypt_config unless scrypt_config.nil?
53
+ request[:name] = name unless name.nil?
54
+ request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
55
+ request[:untrusted_metadata] = untrusted_metadata unless untrusted_metadata.nil?
56
+
57
+ post_request('/v1/b2b/passwords/migrate', request)
58
+ end
59
+
60
+ def authenticate(
61
+ organization_id:,
62
+ email_address:,
63
+ password:,
64
+ session_token: nil,
65
+ session_duration_minutes: nil,
66
+ session_jwt: nil,
67
+ session_custom_claims: nil
68
+ )
69
+ request = {
70
+ organization_id: organization_id,
71
+ email_address: email_address,
72
+ password: password
73
+ }
74
+ request[:session_token] = session_token unless session_token.nil?
75
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
76
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
77
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
78
+
79
+ post_request('/v1/b2b/passwords/authenticate', request)
80
+ end
81
+
82
+ class Email
83
+ include Stytch::RequestHelper
84
+
85
+ def initialize(connection)
86
+ @connection = connection
87
+ end
88
+
89
+ def reset_start(
90
+ organization_id:,
91
+ email_address:,
92
+ reset_password_redirect_url: nil,
93
+ reset_password_expiration_minutes: nil,
94
+ code_challenge: nil,
95
+ login_redirect_url: nil,
96
+ locale: nil,
97
+ reset_password_template_id: nil
98
+ )
99
+ request = {
100
+ organization_id: organization_id,
101
+ email_address: email_address
102
+ }
103
+ request[:reset_password_redirect_url] = reset_password_redirect_url unless reset_password_redirect_url.nil?
104
+ unless reset_password_expiration_minutes.nil?
105
+ request[:reset_password_expiration_minutes] =
106
+ reset_password_expiration_minutes
107
+ end
108
+ request[:code_challenge] = code_challenge unless code_challenge.nil?
109
+ request[:login_redirect_url] = login_redirect_url unless login_redirect_url.nil?
110
+ request[:locale] = locale unless locale.nil?
111
+ request[:reset_password_template_id] = reset_password_template_id unless reset_password_template_id.nil?
112
+
113
+ post_request('/v1/b2b/passwords/email/reset/start', request)
114
+ end
115
+
116
+ def reset(
117
+ password_reset_token:,
118
+ password:,
119
+ session_token: nil,
120
+ session_duration_minutes: nil,
121
+ session_jwt: nil,
122
+ code_verifier: nil,
123
+ session_custom_claims: nil
124
+ )
125
+ request = {
126
+ password_reset_token: password_reset_token,
127
+ password: password
128
+ }
129
+ request[:session_token] = session_token unless session_token.nil?
130
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
131
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
132
+ request[:code_verifier] = code_verifier unless code_verifier.nil?
133
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
134
+
135
+ post_request('/v1/b2b/passwords/email/reset', request)
136
+ end
137
+ end
138
+
139
+ class Sessions
140
+ include Stytch::RequestHelper
141
+
142
+ def initialize(connection)
143
+ @connection = connection
144
+ end
145
+
146
+ def reset(
147
+ organization_id:,
148
+ password:,
149
+ session_token: nil,
150
+ session_jwt: nil
151
+ )
152
+ request = {
153
+ organization_id: organization_id,
154
+ password: password
155
+ }
156
+ request[:session_token] = session_token unless session_token.nil?
157
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
158
+
159
+ post_request('/v1/b2b/passwords/session/reset', request)
160
+ end
161
+ end
162
+
163
+ class ExistingPassword
164
+ include Stytch::RequestHelper
165
+
166
+ def initialize(connection)
167
+ @connection = connection
168
+ end
169
+
170
+ def reset(
171
+ email_address:,
172
+ existing_password:,
173
+ new_password:,
174
+ organization_id:,
175
+ session_token: nil,
176
+ session_duration_minutes: nil,
177
+ session_jwt: nil,
178
+ session_custom_claims: nil
179
+ )
180
+ request = {
181
+ email_address: email_address,
182
+ existing_password: existing_password,
183
+ new_password: new_password,
184
+ organization_id: organization_id
185
+ }
186
+ request[:session_token] = session_token unless session_token.nil?
187
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
188
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
189
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
190
+
191
+ post_request('/v1/b2b/passwords/existing_password/reset', request)
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'request_helper'
4
+
5
+ module StytchB2B
6
+ class Sessions
7
+ include Stytch::RequestHelper
8
+
9
+ def initialize(connection)
10
+ @connection = connection
11
+ end
12
+
13
+ def get(
14
+ organization_id:,
15
+ member_id:
16
+ )
17
+ query_params = {
18
+ organization_id: organization_id,
19
+ member_id: member_id
20
+ }
21
+ request = request_with_query_params('/v1/b2b/sessions', query_params)
22
+ get_request(request)
23
+ end
24
+
25
+ def authenticate(
26
+ session_token: nil,
27
+ session_duration_minutes: nil,
28
+ session_jwt: nil,
29
+ session_custom_claims: nil
30
+ )
31
+ request = {}
32
+ request[:session_token] = session_token unless session_token.nil?
33
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
34
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
35
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
36
+
37
+ post_request('/v1/b2b/sessions/authenticate', request)
38
+ end
39
+
40
+ def revoke(
41
+ member_session_id: nil,
42
+ session_token: nil,
43
+ session_jwt: nil,
44
+ member_id: nil
45
+ )
46
+ request = {}
47
+ request[:member_session_id] = member_session_id unless member_session_id.nil?
48
+ request[:session_token] = session_token unless session_token.nil?
49
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
50
+ request[:member_id] = member_id unless member_id.nil?
51
+
52
+ post_request('/v1/b2b/sessions/revoke', request)
53
+ end
54
+
55
+ def exchange(
56
+ organization_id:,
57
+ session_token: nil,
58
+ session_jwt: nil,
59
+ session_duration_minutes: nil,
60
+ session_custom_claims: nil
61
+ )
62
+ request = {
63
+ organization_id: organization_id
64
+ }
65
+ request[:session_token] = session_token unless session_token.nil?
66
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
67
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
68
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
69
+
70
+ post_request('/v1/b2b/sessions/exchange', request)
71
+ end
72
+
73
+ def jwks(
74
+ project_id:
75
+ )
76
+ query_params = {
77
+ project_id: project_id
78
+ }
79
+ request = request_with_query_params("/v1/b2b/sessions/jwks/#{project_id}", query_params)
80
+ get_request(request)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'request_helper'
4
+
5
+ module StytchB2B
6
+ class SSO
7
+ include Stytch::RequestHelper
8
+ attr_reader :oidc, :saml
9
+
10
+ def initialize(connection)
11
+ @connection = connection
12
+
13
+ @oidc = StytchB2B::SSO::OIDC.new(@connection)
14
+ @saml = StytchB2B::SSO::SAML.new(@connection)
15
+ end
16
+
17
+ def get_connections(
18
+ organization_id:
19
+ )
20
+ query_params = {}
21
+ request = request_with_query_params("/v1/b2b/sso/#{organization_id}", query_params)
22
+ get_request(request)
23
+ end
24
+
25
+ def delete_connection(
26
+ organization_id:,
27
+ connection_id:
28
+ )
29
+ delete_request("/v1/b2b/sso/#{organization_id}/connections/#{connection_id}")
30
+ end
31
+
32
+ def authenticate(
33
+ sso_token:,
34
+ pkce_code_verifier: nil,
35
+ session_token: nil,
36
+ session_jwt: nil,
37
+ session_duration_minutes: nil,
38
+ session_custom_claims: nil
39
+ )
40
+ request = {
41
+ sso_token: sso_token
42
+ }
43
+ request[:pkce_code_verifier] = pkce_code_verifier unless pkce_code_verifier.nil?
44
+ request[:session_token] = session_token unless session_token.nil?
45
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
46
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
47
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
48
+
49
+ post_request('/v1/b2b/sso/authenticate', request)
50
+ end
51
+
52
+ class OIDC
53
+ include Stytch::RequestHelper
54
+
55
+ def initialize(connection)
56
+ @connection = connection
57
+ end
58
+
59
+ def create_connection(
60
+ organization_id:,
61
+ display_name: nil
62
+ )
63
+ request = {
64
+ organization_id: organization_id
65
+ }
66
+ request[:display_name] = display_name unless display_name.nil?
67
+
68
+ post_request("/v1/b2b/sso/oidc/#{organization_id}", request)
69
+ end
70
+
71
+ def update_connection(
72
+ organization_id:,
73
+ connection_id:,
74
+ display_name: nil,
75
+ client_id: nil,
76
+ client_secret: nil,
77
+ issuer: nil,
78
+ authorization_url: nil,
79
+ token_url: nil,
80
+ userinfo_url: nil,
81
+ jwks_url: nil
82
+ )
83
+ request = {
84
+ organization_id: organization_id,
85
+ connection_id: connection_id
86
+ }
87
+ request[:display_name] = display_name unless display_name.nil?
88
+ request[:client_id] = client_id unless client_id.nil?
89
+ request[:client_secret] = client_secret unless client_secret.nil?
90
+ request[:issuer] = issuer unless issuer.nil?
91
+ request[:authorization_url] = authorization_url unless authorization_url.nil?
92
+ request[:token_url] = token_url unless token_url.nil?
93
+ request[:userinfo_url] = userinfo_url unless userinfo_url.nil?
94
+ request[:jwks_url] = jwks_url unless jwks_url.nil?
95
+
96
+ put_request("/v1/b2b/sso/oidc/#{organization_id}/connections/#{connection_id}", request)
97
+ end
98
+ end
99
+
100
+ class SAML
101
+ include Stytch::RequestHelper
102
+
103
+ def initialize(connection)
104
+ @connection = connection
105
+ end
106
+
107
+ def create_connection(
108
+ organization_id:,
109
+ display_name: nil
110
+ )
111
+ request = {
112
+ organization_id: organization_id
113
+ }
114
+ request[:display_name] = display_name unless display_name.nil?
115
+
116
+ post_request("/v1/b2b/sso/saml/#{organization_id}", request)
117
+ end
118
+
119
+ def update_connection(
120
+ organization_id:,
121
+ connection_id:,
122
+ idp_entity_id: nil,
123
+ display_name: nil,
124
+ attribute_mapping: nil,
125
+ x509_certificate: nil,
126
+ idp_sso_url: nil
127
+ )
128
+ request = {
129
+ organization_id: organization_id,
130
+ connection_id: connection_id
131
+ }
132
+ request[:idp_entity_id] = idp_entity_id unless idp_entity_id.nil?
133
+ request[:display_name] = display_name unless display_name.nil?
134
+ request[:attribute_mapping] = attribute_mapping unless attribute_mapping.nil?
135
+ request[:x509_certificate] = x509_certificate unless x509_certificate.nil?
136
+ request[:idp_sso_url] = idp_sso_url unless idp_sso_url.nil?
137
+
138
+ put_request("/v1/b2b/sso/saml/#{organization_id}/connections/#{connection_id}", request)
139
+ end
140
+
141
+ def delete_verification_certificate(
142
+ organization_id:,
143
+ connection_id:,
144
+ certificate_id:
145
+ )
146
+ delete_request("/v1/b2b/sso/saml/#{organization_id}/connections/#{connection_id}/verification_certificates/#{certificate_id}")
147
+ end
148
+ end
149
+ end
150
+ end
data/lib/stytch/client.rb CHANGED
@@ -16,8 +16,8 @@ module Stytch
16
16
 
17
17
  attr_reader :users, :magic_links, :oauth, :otps, :sessions, :totps, :webauthn, :crypto_wallets, :passwords
18
18
 
19
- def initialize(env:, project_id:, secret:, &block)
20
- @api_host = api_host(env)
19
+ def initialize(project_id:, secret:, env: nil, &block)
20
+ @api_host = api_host(env, project_id)
21
21
  @project_id = project_id
22
22
  @secret = secret
23
23
 
@@ -36,7 +36,7 @@ module Stytch
36
36
 
37
37
  private
38
38
 
39
- def api_host(env)
39
+ def api_host(env, project_id)
40
40
  case env
41
41
  when :live
42
42
  'https://api.stytch.com'
@@ -46,7 +46,11 @@ module Stytch
46
46
  # If this is a string that looks like a URL, assume it's an internal development URL.
47
47
  env
48
48
  else
49
- raise ArgumentError, "Invalid value for env (#{env}): should be :live or :test"
49
+ if project_id.start_with? 'project-live-'
50
+ 'https://api.stytch.com'
51
+ else
52
+ 'https://test.stytch.com'
53
+ end
50
54
  end
51
55
  end
52
56
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stytch
4
- VERSION = '4.4.0'
4
+ VERSION = '4.5.0'
5
5
  end
data/lib/stytch.rb CHANGED
@@ -3,8 +3,10 @@
3
3
  require 'faraday'
4
4
  require 'faraday_middleware'
5
5
 
6
+ require_relative 'stytch/b2b_client'
6
7
  require_relative 'stytch/client'
7
8
  require_relative 'stytch/middleware'
8
9
  require_relative 'stytch/version'
9
10
 
10
11
  module Stytch end
12
+ module StytchB2B end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stytch
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.0
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - stytch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-29 00:00:00.000000000 Z
11
+ date: 2023-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -113,6 +113,13 @@ files:
113
113
  - bin/console
114
114
  - bin/setup
115
115
  - lib/stytch.rb
116
+ - lib/stytch/b2b_client.rb
117
+ - lib/stytch/b2b_discovery.rb
118
+ - lib/stytch/b2b_magic_links.rb
119
+ - lib/stytch/b2b_organizations.rb
120
+ - lib/stytch/b2b_passwords.rb
121
+ - lib/stytch/b2b_sessions.rb
122
+ - lib/stytch/b2b_sso.rb
116
123
  - lib/stytch/client.rb
117
124
  - lib/stytch/crypto_wallets.rb
118
125
  - lib/stytch/errors.rb
@@ -149,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
156
  - !ruby/object:Gem::Version
150
157
  version: '0'
151
158
  requirements: []
152
- rubygems_version: 3.1.4
159
+ rubygems_version: 3.2.3
153
160
  signing_key:
154
161
  specification_version: 4
155
162
  summary: Stytch Ruby Gem