stytch 6.6.0 → 7.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,6 +9,44 @@
9
9
  require_relative 'request_helper'
10
10
 
11
11
  module StytchB2B
12
+ class GetConnectionsRequestOptions
13
+ # Optional authorization object.
14
+ # Pass in an active Stytch Member session token or session JWT and the request
15
+ # will be run using that member's permissions.
16
+ attr_accessor :authorization
17
+
18
+ def initialize(
19
+ authorization: nil
20
+ )
21
+ @authorization = authorization
22
+ end
23
+
24
+ def to_headers
25
+ headers = {}
26
+ headers.merge!(@authorization.to_headers) if authorization
27
+ headers
28
+ end
29
+ end
30
+
31
+ class DeleteConnectionRequestOptions
32
+ # Optional authorization object.
33
+ # Pass in an active Stytch Member session token or session JWT and the request
34
+ # will be run using that member's permissions.
35
+ attr_accessor :authorization
36
+
37
+ def initialize(
38
+ authorization: nil
39
+ )
40
+ @authorization = authorization
41
+ end
42
+
43
+ def to_headers
44
+ headers = {}
45
+ headers.merge!(@authorization.to_headers) if authorization
46
+ headers
47
+ end
48
+ end
49
+
12
50
  class SSO
13
51
  include Stytch::RequestHelper
14
52
  attr_reader :oidc, :saml
@@ -20,7 +58,7 @@ module StytchB2B
20
58
  @saml = StytchB2B::SSO::SAML.new(@connection)
21
59
  end
22
60
 
23
- # Get all SSO Connections owned by the organization.
61
+ # Get all SSO Connections owned by the organization. /%}
24
62
  #
25
63
  # == Parameters:
26
64
  # organization_id::
@@ -41,15 +79,21 @@ module StytchB2B
41
79
  # status_code::
42
80
  # The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
43
81
  # The type of this field is +Integer+.
82
+ #
83
+ # == Method Options:
84
+ # This method supports an optional +GetConnectionsRequestOptions+ object which will modify the headers sent in the HTTP request.
44
85
  def get_connections(
45
- organization_id:
86
+ organization_id:,
87
+ method_options: nil
46
88
  )
89
+ headers = {}
90
+ headers = headers.merge(method_options.to_headers) unless method_options.nil?
47
91
  query_params = {}
48
92
  request = request_with_query_params("/v1/b2b/sso/#{organization_id}", query_params)
49
- get_request(request)
93
+ get_request(request, headers)
50
94
  end
51
95
 
52
- # Delete an existing SSO connection.
96
+ # Delete an existing SSO connection. /%}
53
97
  #
54
98
  # == Parameters:
55
99
  # organization_id::
@@ -70,11 +114,17 @@ module StytchB2B
70
114
  # status_code::
71
115
  # The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
72
116
  # The type of this field is +Integer+.
117
+ #
118
+ # == Method Options:
119
+ # This method supports an optional +DeleteConnectionRequestOptions+ object which will modify the headers sent in the HTTP request.
73
120
  def delete_connection(
74
121
  organization_id:,
75
- connection_id:
122
+ connection_id:,
123
+ method_options: nil
76
124
  )
77
- delete_request("/v1/b2b/sso/#{organization_id}/connections/#{connection_id}")
125
+ headers = {}
126
+ headers = headers.merge(method_options.to_headers) unless method_options.nil?
127
+ delete_request("/v1/b2b/sso/#{organization_id}/connections/#{connection_id}", headers)
78
128
  end
79
129
 
80
130
  # Authenticate a user given a token.
@@ -184,6 +234,7 @@ module StytchB2B
184
234
  session_custom_claims: nil,
185
235
  locale: nil
186
236
  )
237
+ headers = {}
187
238
  request = {
188
239
  sso_token: sso_token
189
240
  }
@@ -194,7 +245,7 @@ module StytchB2B
194
245
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
195
246
  request[:locale] = locale unless locale.nil?
196
247
 
197
- post_request('/v1/b2b/sso/authenticate', request)
248
+ post_request('/v1/b2b/sso/authenticate', request, headers)
198
249
  end
199
250
 
200
251
  class OIDC
@@ -204,7 +255,7 @@ module StytchB2B
204
255
  @connection = connection
205
256
  end
206
257
 
207
- # Create a new OIDC Connection.
258
+ # Create a new OIDC Connection. /%}
208
259
  #
209
260
  # == Parameters:
210
261
  # organization_id::
@@ -225,14 +276,20 @@ module StytchB2B
225
276
  # connection::
226
277
  # The `OIDC Connection` object affected by this API call. See the [OIDC Connection Object](https://stytch.com/docs/b2b/api/oidc-connection-object) for complete response field details.
227
278
  # The type of this field is nilable +OIDCConnection+ (+object+).
279
+ #
280
+ # == Method Options:
281
+ # This method supports an optional +CreateConnectionRequestOptions+ object which will modify the headers sent in the HTTP request.
228
282
  def create_connection(
229
283
  organization_id:,
230
- display_name: nil
284
+ display_name: nil,
285
+ method_options: nil
231
286
  )
287
+ headers = {}
288
+ headers = headers.merge(method_options.to_headers) unless method_options.nil?
232
289
  request = {}
233
290
  request[:display_name] = display_name unless display_name.nil?
234
291
 
235
- post_request("/v1/b2b/sso/oidc/#{organization_id}", request)
292
+ post_request("/v1/b2b/sso/oidc/#{organization_id}", request, headers)
236
293
  end
237
294
 
238
295
  # Updates an existing OIDC connection.
@@ -253,6 +310,7 @@ module StytchB2B
253
310
  # * `token_url`
254
311
  # * `userinfo_url`
255
312
  # * `jwks_url`
313
+ # /%}
256
314
  #
257
315
  # == Parameters:
258
316
  # organization_id::
@@ -300,6 +358,9 @@ module StytchB2B
300
358
  # warning::
301
359
  # If it is not possible to resolve the well-known metadata document from the OIDC issuer, this field will explain what went wrong if the request is successful otherwise. In other words, even if the overall request succeeds, there could be relevant warnings related to the connection update.
302
360
  # The type of this field is nilable +String+.
361
+ #
362
+ # == Method Options:
363
+ # This method supports an optional +UpdateConnectionRequestOptions+ object which will modify the headers sent in the HTTP request.
303
364
  def update_connection(
304
365
  organization_id:,
305
366
  connection_id:,
@@ -310,8 +371,11 @@ module StytchB2B
310
371
  authorization_url: nil,
311
372
  token_url: nil,
312
373
  userinfo_url: nil,
313
- jwks_url: nil
374
+ jwks_url: nil,
375
+ method_options: nil
314
376
  )
377
+ headers = {}
378
+ headers = headers.merge(method_options.to_headers) unless method_options.nil?
315
379
  request = {}
316
380
  request[:display_name] = display_name unless display_name.nil?
317
381
  request[:client_id] = client_id unless client_id.nil?
@@ -322,7 +386,7 @@ module StytchB2B
322
386
  request[:userinfo_url] = userinfo_url unless userinfo_url.nil?
323
387
  request[:jwks_url] = jwks_url unless jwks_url.nil?
324
388
 
325
- put_request("/v1/b2b/sso/oidc/#{organization_id}/connections/#{connection_id}", request)
389
+ put_request("/v1/b2b/sso/oidc/#{organization_id}/connections/#{connection_id}", request, headers)
326
390
  end
327
391
  end
328
392
 
@@ -333,7 +397,7 @@ module StytchB2B
333
397
  @connection = connection
334
398
  end
335
399
 
336
- # Create a new SAML Connection.
400
+ # Create a new SAML Connection. /%}
337
401
  #
338
402
  # == Parameters:
339
403
  # organization_id::
@@ -354,14 +418,20 @@ module StytchB2B
354
418
  # connection::
355
419
  # The `SAML Connection` object affected by this API call. See the [SAML Connection Object](https://stytch.com/docs/b2b/api/saml-connection-object) for complete response field details.
356
420
  # The type of this field is nilable +SAMLConnection+ (+object+).
421
+ #
422
+ # == Method Options:
423
+ # This method supports an optional +CreateConnectionRequestOptions+ object which will modify the headers sent in the HTTP request.
357
424
  def create_connection(
358
425
  organization_id:,
359
- display_name: nil
426
+ display_name: nil,
427
+ method_options: nil
360
428
  )
429
+ headers = {}
430
+ headers = headers.merge(method_options.to_headers) unless method_options.nil?
361
431
  request = {}
362
432
  request[:display_name] = display_name unless display_name.nil?
363
433
 
364
- post_request("/v1/b2b/sso/saml/#{organization_id}", request)
434
+ post_request("/v1/b2b/sso/saml/#{organization_id}", request, headers)
365
435
  end
366
436
 
367
437
  # Updates an existing SAML connection.
@@ -371,6 +441,7 @@ module StytchB2B
371
441
  # * `attribute_mapping`
372
442
  # * `idp_entity_id`
373
443
  # * `x509_certificate`
444
+ # /%}
374
445
  #
375
446
  # == Parameters:
376
447
  # organization_id::
@@ -394,6 +465,17 @@ module StytchB2B
394
465
  # idp_sso_url::
395
466
  # The URL for which assertions for login requests will be sent. This will be provided by the IdP.
396
467
  # The type of this field is nilable +String+.
468
+ # saml_connection_implicit_role_assignments::
469
+ # (Coming Soon) All Members who log in with this SAML connection will implicitly receive the specified Roles. See the [RBAC guide](https://stytch.com/docs/b2b/guides/rbac/role-assignment) for more information about role assignment.
470
+ # The type of this field is nilable list of +String+.
471
+ # saml_group_implicit_role_assignments::
472
+ # (Coming Soon) Defines the names of the SAML groups
473
+ # that grant specific role assignments. For each group-Role pair, if a Member logs in with this SAML connection and
474
+ # belongs to the specified SAML group, they will be granted the associated Role. See the
475
+ # [RBAC guide](https://stytch.com/docs/b2b/guides/rbac/role-assignment) for more information about role assignment.
476
+ # Before adding any group implicit role assignments, you must add a "groups" key to your SAML connection's
477
+ # `attribute_mapping`. Make sure that your IdP is configured to correctly send the group information.
478
+ # The type of this field is nilable list of +String+.
397
479
  # alternative_audience_uri::
398
480
  # An alternative URL to use for the Audience Restriction. This value can be used when you wish to migrate an existing SAML integration to Stytch with zero downtime.
399
481
  # The type of this field is nilable +String+.
@@ -409,6 +491,9 @@ module StytchB2B
409
491
  # connection::
410
492
  # The `SAML Connection` object affected by this API call. See the [SAML Connection Object](https://stytch.com/docs/b2b/api/saml-connection-object) for complete response field details.
411
493
  # The type of this field is nilable +SAMLConnection+ (+object+).
494
+ #
495
+ # == Method Options:
496
+ # This method supports an optional +UpdateConnectionRequestOptions+ object which will modify the headers sent in the HTTP request.
412
497
  def update_connection(
413
498
  organization_id:,
414
499
  connection_id:,
@@ -417,17 +502,24 @@ module StytchB2B
417
502
  attribute_mapping: nil,
418
503
  x509_certificate: nil,
419
504
  idp_sso_url: nil,
420
- alternative_audience_uri: nil
505
+ saml_connection_implicit_role_assignments: nil,
506
+ saml_group_implicit_role_assignments: nil,
507
+ alternative_audience_uri: nil,
508
+ method_options: nil
421
509
  )
510
+ headers = {}
511
+ headers = headers.merge(method_options.to_headers) unless method_options.nil?
422
512
  request = {}
423
513
  request[:idp_entity_id] = idp_entity_id unless idp_entity_id.nil?
424
514
  request[:display_name] = display_name unless display_name.nil?
425
515
  request[:attribute_mapping] = attribute_mapping unless attribute_mapping.nil?
426
516
  request[:x509_certificate] = x509_certificate unless x509_certificate.nil?
427
517
  request[:idp_sso_url] = idp_sso_url unless idp_sso_url.nil?
518
+ request[:saml_connection_implicit_role_assignments] = saml_connection_implicit_role_assignments unless saml_connection_implicit_role_assignments.nil?
519
+ request[:saml_group_implicit_role_assignments] = saml_group_implicit_role_assignments unless saml_group_implicit_role_assignments.nil?
428
520
  request[:alternative_audience_uri] = alternative_audience_uri unless alternative_audience_uri.nil?
429
521
 
430
- put_request("/v1/b2b/sso/saml/#{organization_id}/connections/#{connection_id}", request)
522
+ put_request("/v1/b2b/sso/saml/#{organization_id}/connections/#{connection_id}", request, headers)
431
523
  end
432
524
 
433
525
  # Used to update an existing SAML connection using an IDP metadata URL.
@@ -437,6 +529,7 @@ module StytchB2B
437
529
  # * `idp_entity_id`
438
530
  # * `x509_certificate`
439
531
  # * `attribute_mapping` (must be supplied using [Update SAML Connection](update-saml-connection))
532
+ # /%}
440
533
  #
441
534
  # == Parameters:
442
535
  # organization_id::
@@ -460,21 +553,28 @@ module StytchB2B
460
553
  # connection::
461
554
  # The `SAML Connection` object affected by this API call. See the [SAML Connection Object](https://stytch.com/docs/b2b/api/saml-connection-object) for complete response field details.
462
555
  # The type of this field is nilable +SAMLConnection+ (+object+).
556
+ #
557
+ # == Method Options:
558
+ # This method supports an optional +UpdateByURLRequestOptions+ object which will modify the headers sent in the HTTP request.
463
559
  def update_by_url(
464
560
  organization_id:,
465
561
  connection_id:,
466
- metadata_url:
562
+ metadata_url:,
563
+ method_options: nil
467
564
  )
565
+ headers = {}
566
+ headers = headers.merge(method_options.to_headers) unless method_options.nil?
468
567
  request = {
469
568
  metadata_url: metadata_url
470
569
  }
471
570
 
472
- put_request("/v1/b2b/sso/saml/#{organization_id}/connections/#{connection_id}/url", request)
571
+ put_request("/v1/b2b/sso/saml/#{organization_id}/connections/#{connection_id}/url", request, headers)
473
572
  end
474
573
 
475
574
  # Delete a SAML verification certificate.
476
575
  #
477
576
  # You may need to do this when rotating certificates from your IdP, since Stytch allows a maximum of 5 certificates per connection. There must always be at least one certificate per active connection.
577
+ # /%}
478
578
  #
479
579
  # == Parameters:
480
580
  # organization_id::
@@ -498,12 +598,18 @@ module StytchB2B
498
598
  # status_code::
499
599
  # The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
500
600
  # The type of this field is +Integer+.
601
+ #
602
+ # == Method Options:
603
+ # This method supports an optional +DeleteVerificationCertificateRequestOptions+ object which will modify the headers sent in the HTTP request.
501
604
  def delete_verification_certificate(
502
605
  organization_id:,
503
606
  connection_id:,
504
- certificate_id:
607
+ certificate_id:,
608
+ method_options: nil
505
609
  )
506
- delete_request("/v1/b2b/sso/saml/#{organization_id}/connections/#{connection_id}/verification_certificates/#{certificate_id}")
610
+ headers = {}
611
+ headers = headers.merge(method_options.to_headers) unless method_options.nil?
612
+ delete_request("/v1/b2b/sso/saml/#{organization_id}/connections/#{connection_id}/verification_certificates/#{certificate_id}", headers)
507
613
  end
508
614
  end
509
615
  end
data/lib/stytch/client.rb CHANGED
@@ -25,12 +25,12 @@ module Stytch
25
25
  create_connection(&block)
26
26
 
27
27
  @crypto_wallets = Stytch::CryptoWallets.new(@connection)
28
- @m2m = Stytch::M2M.new(@connection, project_id)
28
+ @m2m = Stytch::M2M.new(@connection, @project_id)
29
29
  @magic_links = Stytch::MagicLinks.new(@connection)
30
30
  @oauth = Stytch::OAuth.new(@connection)
31
31
  @otps = Stytch::OTPs.new(@connection)
32
32
  @passwords = Stytch::Passwords.new(@connection)
33
- @sessions = Stytch::Sessions.new(@connection, project_id)
33
+ @sessions = Stytch::Sessions.new(@connection, @project_id)
34
34
  @totps = Stytch::TOTPs.new(@connection)
35
35
  @users = Stytch::Users.new(@connection)
36
36
  @webauthn = Stytch::WebAuthn.new(@connection)
@@ -59,6 +59,7 @@ module Stytch
59
59
  session_token: nil,
60
60
  session_jwt: nil
61
61
  )
62
+ headers = {}
62
63
  request = {
63
64
  crypto_wallet_type: crypto_wallet_type,
64
65
  crypto_wallet_address: crypto_wallet_address
@@ -67,7 +68,7 @@ module Stytch
67
68
  request[:session_token] = session_token unless session_token.nil?
68
69
  request[:session_jwt] = session_jwt unless session_jwt.nil?
69
70
 
70
- post_request('/v1/crypto_wallets/authenticate/start', request)
71
+ post_request('/v1/crypto_wallets/authenticate/start', request, headers)
71
72
  end
72
73
 
73
74
  # Complete the authentication of a crypto wallet by passing the signature.
@@ -140,6 +141,7 @@ module Stytch
140
141
  session_jwt: nil,
141
142
  session_custom_claims: nil
142
143
  )
144
+ headers = {}
143
145
  request = {
144
146
  crypto_wallet_type: crypto_wallet_type,
145
147
  crypto_wallet_address: crypto_wallet_address,
@@ -150,7 +152,7 @@ module Stytch
150
152
  request[:session_jwt] = session_jwt unless session_jwt.nil?
151
153
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
152
154
 
153
- post_request('/v1/crypto_wallets/authenticate', request)
155
+ post_request('/v1/crypto_wallets/authenticate', request, headers)
154
156
  end
155
157
  end
156
158
  end
data/lib/stytch/errors.rb CHANGED
@@ -35,4 +35,18 @@ module Stytch
35
35
  super(msg)
36
36
  end
37
37
  end
38
+
39
+ class TenancyError < StandardError
40
+ def initialize(subject_org_id, request_org_id)
41
+ msg = "Subject organization_id #{subject_org_id} does not match authZ request organization_id #{request_org_id}"
42
+ super(msg)
43
+ end
44
+ end
45
+
46
+ class PermissionError < StandardError
47
+ def initialize(request)
48
+ msg = "Permission denied for request #{request}"
49
+ super(msg)
50
+ end
51
+ end
38
52
  end
data/lib/stytch/m2m.rb CHANGED
@@ -17,7 +17,6 @@ module Stytch
17
17
  @connection = connection
18
18
 
19
19
  @clients = Stytch::M2M::Clients.new(@connection)
20
-
21
20
  @project_id = project_id
22
21
  @cache_last_update = 0
23
22
  @jwks_loader = lambda do |options|
@@ -191,9 +190,10 @@ module Stytch
191
190
  def get(
192
191
  client_id:
193
192
  )
193
+ headers = {}
194
194
  query_params = {}
195
195
  request = request_with_query_params("/v1/m2m/clients/#{client_id}", query_params)
196
- get_request(request)
196
+ get_request(request, headers)
197
197
  end
198
198
 
199
199
  # Search for M2M Clients within your Stytch Project. Submit an empty `query` in the request to return all M2M Clients.
@@ -233,12 +233,13 @@ module Stytch
233
233
  limit: nil,
234
234
  query: nil
235
235
  )
236
+ headers = {}
236
237
  request = {}
237
238
  request[:cursor] = cursor unless cursor.nil?
238
239
  request[:limit] = limit unless limit.nil?
239
240
  request[:query] = query unless query.nil?
240
241
 
241
- post_request('/v1/m2m/clients/search', request)
242
+ post_request('/v1/m2m/clients/search', request, headers)
242
243
  end
243
244
 
244
245
  # Updates an existing M2M Client. You can use this endpoint to activate or deactivate a M2M Client by changing its `status`. A deactivated M2M Client will not be allowed to perform future token exchange flows until it is reactivated.
@@ -285,6 +286,7 @@ module Stytch
285
286
  scopes: nil,
286
287
  trusted_metadata: nil
287
288
  )
289
+ headers = {}
288
290
  request = {}
289
291
  request[:client_name] = client_name unless client_name.nil?
290
292
  request[:client_description] = client_description unless client_description.nil?
@@ -292,7 +294,7 @@ module Stytch
292
294
  request[:scopes] = scopes unless scopes.nil?
293
295
  request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
294
296
 
295
- put_request("/v1/m2m/clients/#{client_id}", request)
297
+ put_request("/v1/m2m/clients/#{client_id}", request, headers)
296
298
  end
297
299
 
298
300
  # Deletes the M2M Client.
@@ -319,7 +321,8 @@ module Stytch
319
321
  def delete(
320
322
  client_id:
321
323
  )
322
- delete_request("/v1/m2m/clients/#{client_id}")
324
+ headers = {}
325
+ delete_request("/v1/m2m/clients/#{client_id}", headers)
323
326
  end
324
327
 
325
328
  # Creates a new M2M Client. On initial client creation, you may pass in a custom `client_id` or `client_secret` to import an existing M2M client. If you do not pass in a custom `client_id` or `client_secret`, one will be generated automatically. The `client_id` must be unique among all clients in your project.
@@ -365,6 +368,7 @@ module Stytch
365
368
  client_description: nil,
366
369
  trusted_metadata: nil
367
370
  )
371
+ headers = {}
368
372
  request = {
369
373
  scopes: scopes
370
374
  }
@@ -374,7 +378,7 @@ module Stytch
374
378
  request[:client_description] = client_description unless client_description.nil?
375
379
  request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
376
380
 
377
- post_request('/v1/m2m/clients', request)
381
+ post_request('/v1/m2m/clients', request, headers)
378
382
  end
379
383
 
380
384
  class Secrets
@@ -408,9 +412,10 @@ module Stytch
408
412
  def rotate_start(
409
413
  client_id:
410
414
  )
415
+ headers = {}
411
416
  request = {}
412
417
 
413
- post_request("/v1/m2m/clients/#{client_id}/secrets/rotate/start", request)
418
+ post_request("/v1/m2m/clients/#{client_id}/secrets/rotate/start", request, headers)
414
419
  end
415
420
 
416
421
  # Cancel the rotation of an M2M client secret started with the [Start Secret Rotation Endpoint](https://stytch.com/docs/b2b/api/m2m-rotate-secret-start) [Start Secret Rotation Endpoint](https://stytch.com/docs/api/m2m-rotate-secret-start).
@@ -435,9 +440,10 @@ module Stytch
435
440
  def rotate_cancel(
436
441
  client_id:
437
442
  )
443
+ headers = {}
438
444
  request = {}
439
445
 
440
- post_request("/v1/m2m/clients/#{client_id}/secrets/rotate/cancel", request)
446
+ post_request("/v1/m2m/clients/#{client_id}/secrets/rotate/cancel", request, headers)
441
447
  end
442
448
 
443
449
  # Complete the rotation of an M2M client secret started with the [Start Secret Rotation Endpoint](https://stytch.com/docs/b2b/api/m2m-rotate-secret-start) [Start Secret Rotation Endpoint](https://stytch.com/docs/api/m2m-rotate-secret-start).
@@ -462,9 +468,10 @@ module Stytch
462
468
  def rotate(
463
469
  client_id:
464
470
  )
471
+ headers = {}
465
472
  request = {}
466
473
 
467
- post_request("/v1/m2m/clients/#{client_id}/secrets/rotate", request)
474
+ post_request("/v1/m2m/clients/#{client_id}/secrets/rotate", request, headers)
468
475
  end
469
476
  end
470
477
  end
@@ -103,6 +103,7 @@ module Stytch
103
103
  session_custom_claims: nil,
104
104
  code_verifier: nil
105
105
  )
106
+ headers = {}
106
107
  request = {
107
108
  token: token
108
109
  }
@@ -114,7 +115,7 @@ module Stytch
114
115
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
115
116
  request[:code_verifier] = code_verifier unless code_verifier.nil?
116
117
 
117
- post_request('/v1/magic_links/authenticate', request)
118
+ post_request('/v1/magic_links/authenticate', request, headers)
118
119
  end
119
120
 
120
121
  # Create an embeddable Magic Link token for a User. Access to this endpoint is restricted. To enable it, please send us a note at support@stytch.com.
@@ -152,13 +153,14 @@ module Stytch
152
153
  expiration_minutes: nil,
153
154
  attributes: nil
154
155
  )
156
+ headers = {}
155
157
  request = {
156
158
  user_id: user_id
157
159
  }
158
160
  request[:expiration_minutes] = expiration_minutes unless expiration_minutes.nil?
159
161
  request[:attributes] = attributes unless attributes.nil?
160
162
 
161
- post_request('/v1/magic_links', request)
163
+ post_request('/v1/magic_links', request, headers)
162
164
  end
163
165
 
164
166
  class Email
@@ -251,6 +253,7 @@ module Stytch
251
253
  locale: nil,
252
254
  signup_template_id: nil
253
255
  )
256
+ headers = {}
254
257
  request = {
255
258
  email: email
256
259
  }
@@ -267,7 +270,7 @@ module Stytch
267
270
  request[:locale] = locale unless locale.nil?
268
271
  request[:signup_template_id] = signup_template_id unless signup_template_id.nil?
269
272
 
270
- post_request('/v1/magic_links/email/send', request)
273
+ post_request('/v1/magic_links/email/send', request, headers)
271
274
  end
272
275
 
273
276
  # Send either a login or signup Magic Link to the User based on if the email is associated with a User already. A new or pending User will receive a signup Magic Link. An active User will receive a login Magic Link. For more information on how to control the status your Users are created in see the `create_user_as_pending` flag.
@@ -349,6 +352,7 @@ module Stytch
349
352
  code_challenge: nil,
350
353
  locale: nil
351
354
  )
355
+ headers = {}
352
356
  request = {
353
357
  email: email
354
358
  }
@@ -363,7 +367,7 @@ module Stytch
363
367
  request[:code_challenge] = code_challenge unless code_challenge.nil?
364
368
  request[:locale] = locale unless locale.nil?
365
369
 
366
- post_request('/v1/magic_links/email/login_or_create', request)
370
+ post_request('/v1/magic_links/email/login_or_create', request, headers)
367
371
  end
368
372
 
369
373
  # Create a User and send an invite Magic Link to the provided `email`. The User will be created with a `pending` status until they click the Magic Link in the invite email.
@@ -422,6 +426,7 @@ module Stytch
422
426
  invite_expiration_minutes: nil,
423
427
  locale: nil
424
428
  )
429
+ headers = {}
425
430
  request = {
426
431
  email: email
427
432
  }
@@ -432,7 +437,7 @@ module Stytch
432
437
  request[:invite_expiration_minutes] = invite_expiration_minutes unless invite_expiration_minutes.nil?
433
438
  request[:locale] = locale unless locale.nil?
434
439
 
435
- post_request('/v1/magic_links/email/invite', request)
440
+ post_request('/v1/magic_links/email/invite', request, headers)
436
441
  end
437
442
 
438
443
  # Revoke a pending invite based on the `email` provided.
@@ -453,11 +458,12 @@ module Stytch
453
458
  def revoke_invite(
454
459
  email:
455
460
  )
461
+ headers = {}
456
462
  request = {
457
463
  email: email
458
464
  }
459
465
 
460
- post_request('/v1/magic_links/email/revoke_invite', request)
466
+ post_request('/v1/magic_links/email/revoke_invite', request, headers)
461
467
  end
462
468
  end
463
469
  end
@@ -0,0 +1,22 @@
1
+ module Stytch
2
+ module MethodOptions
3
+ class Authorization
4
+ # A secret token for a given Stytch Session.
5
+ attr_accessor :session_token
6
+ # The JSON Web Token (JWT) for a given Stytch Session.
7
+ attr_accessor :session_jwt
8
+
9
+ def initialize(session_token: nil, session_jwt: nil)
10
+ @session_token = session_token
11
+ @session_jwt = session_jwt
12
+ end
13
+
14
+ def to_headers
15
+ headers = {}
16
+ headers['X-Stytch-Member-Session'] = session_token if session_token
17
+ headers['X-Stytch-Member-SessionJWT'] = session_jwt if session_jwt
18
+ headers
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/stytch/oauth.rb CHANGED
@@ -53,6 +53,7 @@ module Stytch
53
53
  session_token: nil,
54
54
  session_jwt: nil
55
55
  )
56
+ headers = {}
56
57
  request = {
57
58
  provider: provider
58
59
  }
@@ -60,7 +61,7 @@ module Stytch
60
61
  request[:session_token] = session_token unless session_token.nil?
61
62
  request[:session_jwt] = session_jwt unless session_jwt.nil?
62
63
 
63
- post_request('/v1/oauth/attach', request)
64
+ post_request('/v1/oauth/attach', request, headers)
64
65
  end
65
66
 
66
67
  # Authenticate a User given a `token`. This endpoint verifies that the user completed the OAuth flow by verifying that the token is valid and hasn't expired. To initiate a Stytch session for the user while authenticating their OAuth token, include `session_duration_minutes`; a session with the identity provider, e.g. Google or Facebook, will always be initiated upon successful authentication.
@@ -150,6 +151,7 @@ module Stytch
150
151
  session_custom_claims: nil,
151
152
  code_verifier: nil
152
153
  )
154
+ headers = {}
153
155
  request = {
154
156
  token: token
155
157
  }
@@ -159,7 +161,7 @@ module Stytch
159
161
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
160
162
  request[:code_verifier] = code_verifier unless code_verifier.nil?
161
163
 
162
- post_request('/v1/oauth/authenticate', request)
164
+ post_request('/v1/oauth/authenticate', request, headers)
163
165
  end
164
166
  end
165
167
  end