stytch 10.25.0 → 10.27.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/lib/stytch/b2b_client.rb +10 -2
- data/lib/stytch/b2b_discovery.rb +6 -6
- data/lib/stytch/b2b_idp.rb +266 -0
- data/lib/stytch/b2b_magic_links.rb +3 -3
- data/lib/stytch/b2b_oauth.rb +1 -1
- data/lib/stytch/b2b_organizations.rb +47 -35
- data/lib/stytch/b2b_otp.rb +9 -7
- data/lib/stytch/b2b_passwords.rb +10 -7
- data/lib/stytch/b2b_rbac.rb +2 -2
- data/lib/stytch/b2b_recovery_codes.rb +3 -3
- data/lib/stytch/b2b_scim.rb +8 -8
- data/lib/stytch/b2b_sessions.rb +6 -6
- data/lib/stytch/b2b_sso.rb +10 -10
- data/lib/stytch/b2b_totps.rb +6 -4
- data/lib/stytch/client.rb +16 -2
- data/lib/stytch/fraud.rb +6 -3
- data/lib/stytch/idp.rb +251 -0
- data/lib/stytch/otps.rb +2 -2
- data/lib/stytch/passwords.rb +4 -4
- data/lib/stytch/rbac.rb +49 -0
- data/lib/stytch/rbac_local.rb +66 -3
- data/lib/stytch/sessions.rb +37 -10
- data/lib/stytch/version.rb +1 -1
- data/lib/stytch.rb +1 -0
- metadata +5 -2
data/lib/stytch/b2b_sessions.rb
CHANGED
@@ -57,7 +57,7 @@ module StytchB2B
|
|
57
57
|
#
|
58
58
|
# == Parameters:
|
59
59
|
# organization_id::
|
60
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
60
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
61
61
|
# The type of this field is +String+.
|
62
62
|
# member_id::
|
63
63
|
# Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value. You may use an external_id here if one is set for the member.
|
@@ -164,7 +164,7 @@ module StytchB2B
|
|
164
164
|
# The type of this field is +Integer+.
|
165
165
|
# verdict::
|
166
166
|
# If an `authorization_check` is provided in the request and the check succeeds, this field will return
|
167
|
-
#
|
167
|
+
# information about why the Member was granted permission.
|
168
168
|
# The type of this field is nilable +AuthorizationVerdict+ (+object+).
|
169
169
|
def authenticate(
|
170
170
|
session_token: nil,
|
@@ -248,7 +248,7 @@ module StytchB2B
|
|
248
248
|
#
|
249
249
|
# == Parameters:
|
250
250
|
# organization_id::
|
251
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
251
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
252
252
|
# The type of this field is +String+.
|
253
253
|
# session_token::
|
254
254
|
# The `session_token` belonging to the member that you wish to associate the email with.
|
@@ -417,7 +417,7 @@ module StytchB2B
|
|
417
417
|
post_request('/v1/b2b/sessions/exchange_access_token', request, headers)
|
418
418
|
end
|
419
419
|
|
420
|
-
# Exchange an auth token issued by a trusted identity provider for a Stytch session. You must first register a Trusted Auth Token profile in the Stytch dashboard [here](https://stytch.com/
|
420
|
+
# Exchange an auth token issued by a trusted identity provider for a Stytch session. You must first register a Trusted Auth Token profile in the Stytch dashboard [here](https://stytch.com/dashboard/trusted-auth-tokens). If a session token or session JWT is provided, it will add the trusted auth token as an authentication factor to the existing session.
|
421
421
|
#
|
422
422
|
# == Parameters:
|
423
423
|
# organization_id::
|
@@ -504,7 +504,7 @@ module StytchB2B
|
|
504
504
|
end
|
505
505
|
|
506
506
|
# Migrate a session from an external OIDC compliant endpoint.
|
507
|
-
# Stytch will call the external UserInfo endpoint defined in your Stytch Project settings in the [Dashboard](https://stytch.com/
|
507
|
+
# Stytch will call the external UserInfo endpoint defined in your Stytch Project settings in the [Dashboard](https://stytch.com/dashboard/migrations), and then perform a lookup using the `session_token`.
|
508
508
|
# If the response contains a valid email address, Stytch will attempt to match that email address with an existing Member in your Organization and create a Stytch Session.
|
509
509
|
# You will need to create the member before using this endpoint.
|
510
510
|
#
|
@@ -513,7 +513,7 @@ module StytchB2B
|
|
513
513
|
# The authorization token Stytch will pass in to the external userinfo endpoint.
|
514
514
|
# The type of this field is +String+.
|
515
515
|
# organization_id::
|
516
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
516
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
517
517
|
# The type of this field is +String+.
|
518
518
|
# session_duration_minutes::
|
519
519
|
# Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
|
data/lib/stytch/b2b_sso.rb
CHANGED
@@ -63,7 +63,7 @@ module StytchB2B
|
|
63
63
|
#
|
64
64
|
# == Parameters:
|
65
65
|
# organization_id::
|
66
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
66
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
67
67
|
# The type of this field is +String+.
|
68
68
|
#
|
69
69
|
# == Returns:
|
@@ -101,7 +101,7 @@ module StytchB2B
|
|
101
101
|
#
|
102
102
|
# == Parameters:
|
103
103
|
# organization_id::
|
104
|
-
# The organization ID that the SSO connection belongs to. You may also use the organization_slug here as a convenience.
|
104
|
+
# The organization ID that the SSO connection belongs to. You may also use the organization_slug or organization_external_id here as a convenience.
|
105
105
|
# The type of this field is +String+.
|
106
106
|
# connection_id::
|
107
107
|
# The ID of the SSO connection. SAML, OIDC, and External connection IDs can be provided.
|
@@ -307,7 +307,7 @@ module StytchB2B
|
|
307
307
|
#
|
308
308
|
# == Parameters:
|
309
309
|
# organization_id::
|
310
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
310
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
311
311
|
# The type of this field is +String+.
|
312
312
|
# display_name::
|
313
313
|
# A human-readable display name for the connection.
|
@@ -368,7 +368,7 @@ module StytchB2B
|
|
368
368
|
#
|
369
369
|
# == Parameters:
|
370
370
|
# organization_id::
|
371
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
371
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
372
372
|
# The type of this field is +String+.
|
373
373
|
# connection_id::
|
374
374
|
# Globally unique UUID that identifies a specific SSO `connection_id` for a Member.
|
@@ -548,7 +548,7 @@ module StytchB2B
|
|
548
548
|
#
|
549
549
|
# == Parameters:
|
550
550
|
# organization_id::
|
551
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
551
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
552
552
|
# The type of this field is +String+.
|
553
553
|
# display_name::
|
554
554
|
# A human-readable display name for the connection.
|
@@ -598,7 +598,7 @@ module StytchB2B
|
|
598
598
|
#
|
599
599
|
# == Parameters:
|
600
600
|
# organization_id::
|
601
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
601
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
602
602
|
# The type of this field is +String+.
|
603
603
|
# connection_id::
|
604
604
|
# Globally unique UUID that identifies a specific SSO `connection_id` for a Member.
|
@@ -711,7 +711,7 @@ module StytchB2B
|
|
711
711
|
#
|
712
712
|
# == Parameters:
|
713
713
|
# organization_id::
|
714
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
714
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
715
715
|
# The type of this field is +String+.
|
716
716
|
# connection_id::
|
717
717
|
# Globally unique UUID that identifies a specific SSO `connection_id` for a Member.
|
@@ -755,7 +755,7 @@ module StytchB2B
|
|
755
755
|
#
|
756
756
|
# == Parameters:
|
757
757
|
# organization_id::
|
758
|
-
# The organization ID that the SAML connection belongs to. You may also use the organization_slug here as a convenience.
|
758
|
+
# The organization ID that the SAML connection belongs to. You may also use the organization_slug or organization_external_id here as a convenience.
|
759
759
|
# The type of this field is +String+.
|
760
760
|
# connection_id::
|
761
761
|
# The ID of the SAML connection.
|
@@ -839,7 +839,7 @@ module StytchB2B
|
|
839
839
|
#
|
840
840
|
# == Parameters:
|
841
841
|
# organization_id::
|
842
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
842
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
843
843
|
# The type of this field is +String+.
|
844
844
|
# external_organization_id::
|
845
845
|
# Globally unique UUID that identifies a different Organization within your Project.
|
@@ -897,7 +897,7 @@ module StytchB2B
|
|
897
897
|
#
|
898
898
|
# == Parameters:
|
899
899
|
# organization_id::
|
900
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
900
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
901
901
|
# The type of this field is +String+.
|
902
902
|
# connection_id::
|
903
903
|
# Globally unique UUID that identifies a specific External SSO Connection.
|
data/lib/stytch/b2b_totps.rb
CHANGED
@@ -18,11 +18,13 @@ module StytchB2B
|
|
18
18
|
|
19
19
|
# Create a new TOTP instance for a Member. The Member can use the authenticator application of their choice to scan the QR code or enter the secret.
|
20
20
|
#
|
21
|
-
#
|
21
|
+
# If the Member already has an active MFA factor, then passing an intermediate session token, session token, or session JWT with the existing MFA factor on it is required to prevent bypassing MFA.
|
22
|
+
#
|
23
|
+
# Otherwise, passing an intermediate session token, session token, or session JWT is not required, but if passed must match the `member_id` passed.
|
22
24
|
#
|
23
25
|
# == Parameters:
|
24
26
|
# organization_id::
|
25
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
27
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
26
28
|
# The type of this field is +String+.
|
27
29
|
# member_id::
|
28
30
|
# Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value. You may use an external_id here if one is set for the member.
|
@@ -94,7 +96,7 @@ module StytchB2B
|
|
94
96
|
#
|
95
97
|
# == Parameters:
|
96
98
|
# organization_id::
|
97
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
99
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
98
100
|
# The type of this field is +String+.
|
99
101
|
# member_id::
|
100
102
|
# Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value. You may use an external_id here if one is set for the member.
|
@@ -200,7 +202,7 @@ module StytchB2B
|
|
200
202
|
#
|
201
203
|
# == Parameters:
|
202
204
|
# organization_id::
|
203
|
-
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug here as a convenience.
|
205
|
+
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience.
|
204
206
|
# The type of this field is +String+.
|
205
207
|
# member_id::
|
206
208
|
# Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value. You may use an external_id here if one is set for the member.
|
data/lib/stytch/client.rb
CHANGED
@@ -1,8 +1,15 @@
|
|
1
|
+
# !!!
|
2
|
+
# WARNING: This file is autogenerated
|
3
|
+
# Only modify code within MANUAL() sections
|
4
|
+
# or your changes may be overwritten later!
|
5
|
+
# !!!
|
6
|
+
|
1
7
|
# frozen_string_literal: true
|
2
8
|
|
3
9
|
require_relative 'connected_apps'
|
4
10
|
require_relative 'crypto_wallets'
|
5
11
|
require_relative 'fraud'
|
12
|
+
require_relative 'idp'
|
6
13
|
require_relative 'impersonation'
|
7
14
|
require_relative 'm2m'
|
8
15
|
require_relative 'magic_links'
|
@@ -10,6 +17,8 @@ require_relative 'oauth'
|
|
10
17
|
require_relative 'otps'
|
11
18
|
require_relative 'passwords'
|
12
19
|
require_relative 'project'
|
20
|
+
require_relative 'rbac'
|
21
|
+
require_relative 'rbac_local'
|
13
22
|
require_relative 'sessions'
|
14
23
|
require_relative 'totps'
|
15
24
|
require_relative 'users'
|
@@ -19,7 +28,7 @@ module Stytch
|
|
19
28
|
class Client
|
20
29
|
ENVIRONMENTS = %i[live test].freeze
|
21
30
|
|
22
|
-
attr_reader :connected_app, :crypto_wallets, :fraud, :impersonation, :m2m, :magic_links, :oauth, :otps, :passwords, :project, :sessions, :totps, :users, :webauthn
|
31
|
+
attr_reader :connected_app, :crypto_wallets, :fraud, :impersonation, :m2m, :magic_links, :oauth, :otps, :passwords, :project, :rbac, :sessions, :totps, :users, :webauthn, :idp
|
23
32
|
|
24
33
|
def initialize(project_id:, secret:, env: nil, fraud_env: nil, &block)
|
25
34
|
@api_host = api_host(env, project_id)
|
@@ -30,6 +39,10 @@ module Stytch
|
|
30
39
|
|
31
40
|
create_connection(&block)
|
32
41
|
|
42
|
+
rbac = Stytch::RBAC.new(@connection)
|
43
|
+
@policy_cache = Stytch::PolicyCache.new(rbac_client: rbac)
|
44
|
+
@idp = Stytch::IDP.new(@connection, @project_id, @policy_cache)
|
45
|
+
|
33
46
|
@connected_app = Stytch::ConnectedApp.new(@connection)
|
34
47
|
@crypto_wallets = Stytch::CryptoWallets.new(@connection)
|
35
48
|
@fraud = Stytch::Fraud.new(@fraud_connection)
|
@@ -40,7 +53,8 @@ module Stytch
|
|
40
53
|
@otps = Stytch::OTPs.new(@connection)
|
41
54
|
@passwords = Stytch::Passwords.new(@connection)
|
42
55
|
@project = Stytch::Project.new(@connection)
|
43
|
-
@
|
56
|
+
@rbac = Stytch::RBAC.new(@connection)
|
57
|
+
@sessions = Stytch::Sessions.new(@connection, @project_id, @policy_cache)
|
44
58
|
@totps = Stytch::TOTPs.new(@connection)
|
45
59
|
@users = Stytch::Users.new(@connection)
|
46
60
|
@webauthn = Stytch::WebAuthn.new(@connection)
|
data/lib/stytch/fraud.rb
CHANGED
@@ -28,14 +28,17 @@ module Stytch
|
|
28
28
|
@connection = connection
|
29
29
|
end
|
30
30
|
|
31
|
-
# Lookup the associated fingerprint for the `telemetry_id` returned from the `GetTelemetryID()` function.
|
31
|
+
# Lookup the associated fingerprint for the `telemetry_id` returned from the `GetTelemetryID()` function.
|
32
|
+
# Learn more about the different fingerprint types and verdicts in our [DFP guide](https://stytch.com/docs/fraud/guides/device-fingerprinting/overview).
|
32
33
|
#
|
33
|
-
#
|
34
|
+
# You can make a decision based on the recommended `verdict` in the response:
|
34
35
|
# * `ALLOW` - This is a known valid device grouping or device profile that is part of the default `ALLOW` listed set of known devices by Stytch. This grouping is made up of verified device profiles that match the characteristics of known/authentic traffic origins.
|
35
36
|
# * `BLOCK` - This is a known bad or malicious device profile that is undesirable and should be blocked from completing the privileged action in question.
|
36
37
|
# * `CHALLENGE` - This is an unknown or potentially malicious device that should be put through increased friction such as 2FA or other forms of extended user verification before allowing the privileged action to proceed.
|
37
38
|
#
|
38
|
-
# If the `telemetry_id` is not found,
|
39
|
+
# If the `telemetry_id` is expired or not found, this endpoint returns a 404 `telemetry_id_not_found` [error](https://stytch.com/docs/fraud/api/errors/404#telemetry_id_not_found).
|
40
|
+
# We recommend treating 404 errors as a `BLOCK`, since it could be a sign of an attacker trying to bypass DFP protections.
|
41
|
+
# See [Attacker-controlled telemetry IDs](https://stytch.com/docs/fraud/guides/device-fingerprinting/integration-steps/test-your-integration#attacker-controlled-telemetry-ids) for more information.
|
39
42
|
#
|
40
43
|
# == Parameters:
|
41
44
|
# telemetry_id::
|
data/lib/stytch/idp.rb
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jwt'
|
4
|
+
require 'json/jwt'
|
5
|
+
require_relative 'errors'
|
6
|
+
require_relative 'request_helper'
|
7
|
+
require_relative 'rbac_local'
|
8
|
+
|
9
|
+
module Stytch
|
10
|
+
class IDP
|
11
|
+
include Stytch::RequestHelper
|
12
|
+
|
13
|
+
def initialize(connection, project_id, policy_cache)
|
14
|
+
@connection = connection
|
15
|
+
@project_id = project_id
|
16
|
+
@policy_cache = policy_cache
|
17
|
+
@non_custom_claim_keys = %w[
|
18
|
+
aud
|
19
|
+
exp
|
20
|
+
iat
|
21
|
+
iss
|
22
|
+
jti
|
23
|
+
nbf
|
24
|
+
sub
|
25
|
+
active
|
26
|
+
client_id
|
27
|
+
request_id
|
28
|
+
scope
|
29
|
+
status_code
|
30
|
+
token_type
|
31
|
+
]
|
32
|
+
end
|
33
|
+
|
34
|
+
# Introspects a token JWT from an authorization code response.
|
35
|
+
# Access tokens are JWTs signed with the project's JWKs. Refresh tokens are opaque tokens.
|
36
|
+
# Access tokens contain a standard set of claims as well as any custom claims generated from templates.
|
37
|
+
#
|
38
|
+
# == Parameters:
|
39
|
+
# token::
|
40
|
+
# The access token (or refresh token) to introspect.
|
41
|
+
# The type of this field is +String+.
|
42
|
+
# client_id::
|
43
|
+
# The ID of the client.
|
44
|
+
# The type of this field is +String+.
|
45
|
+
# client_secret::
|
46
|
+
# The secret of the client.
|
47
|
+
# The type of this field is nilable +String+.
|
48
|
+
# token_type_hint::
|
49
|
+
# A hint on what the token contains. Valid fields are 'access_token' and 'refresh_token'.
|
50
|
+
# The type of this field is +String+.
|
51
|
+
# authorization_check::
|
52
|
+
# Optional authorization check object.
|
53
|
+
# The type of this field is nilable +Hash+.
|
54
|
+
#
|
55
|
+
# == Returns:
|
56
|
+
# An object with the following fields:
|
57
|
+
# subject::
|
58
|
+
# The subject of the token.
|
59
|
+
# The type of this field is +String+.
|
60
|
+
# scope::
|
61
|
+
# The scope of the token.
|
62
|
+
# The type of this field is +String+.
|
63
|
+
# audience::
|
64
|
+
# The audience of the token.
|
65
|
+
# The type of this field is +String+.
|
66
|
+
# expires_at::
|
67
|
+
# The expiration time of the token.
|
68
|
+
# The type of this field is +Integer+.
|
69
|
+
# issued_at::
|
70
|
+
# The issued at time of the token.
|
71
|
+
# The type of this field is +Integer+.
|
72
|
+
# issuer::
|
73
|
+
# The issuer of the token.
|
74
|
+
# The type of this field is +String+.
|
75
|
+
# not_before::
|
76
|
+
# The not before time of the token.
|
77
|
+
# The type of this field is +Integer+.
|
78
|
+
# token_type::
|
79
|
+
# The type of the token.
|
80
|
+
# The type of this field is +String+.
|
81
|
+
# custom_claims::
|
82
|
+
# Custom claims in the token.
|
83
|
+
# The type of this field is +Hash+.
|
84
|
+
def introspect_token_network(
|
85
|
+
token:,
|
86
|
+
client_id:,
|
87
|
+
client_secret: nil,
|
88
|
+
token_type_hint: 'access_token',
|
89
|
+
authorization_check: nil
|
90
|
+
)
|
91
|
+
headers = {}
|
92
|
+
data = {
|
93
|
+
'token' => token,
|
94
|
+
'client_id' => client_id,
|
95
|
+
'token_type_hint' => token_type_hint
|
96
|
+
}
|
97
|
+
data['client_secret'] = client_secret unless client_secret.nil?
|
98
|
+
|
99
|
+
url = @connection.url_prefix + '/v1/oauth2/introspect'
|
100
|
+
res = post_request(url, data, headers)
|
101
|
+
|
102
|
+
jwt_response = res
|
103
|
+
return nil unless jwt_response['active']
|
104
|
+
|
105
|
+
custom_claims = res.reject { |k, _| @non_custom_claim_keys.include?(k) }
|
106
|
+
scope = jwt_response['scope']
|
107
|
+
|
108
|
+
if authorization_check
|
109
|
+
@policy_cache.perform_scope_authorization_check(
|
110
|
+
token_scopes: scope.split,
|
111
|
+
authorization_check: authorization_check
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
{
|
116
|
+
'subject' => jwt_response['sub'],
|
117
|
+
'scope' => jwt_response['scope'],
|
118
|
+
'audience' => jwt_response['aud'],
|
119
|
+
'expires_at' => jwt_response['exp'],
|
120
|
+
'issued_at' => jwt_response['iat'],
|
121
|
+
'issuer' => jwt_response['iss'],
|
122
|
+
'not_before' => jwt_response['nbf'],
|
123
|
+
'token_type' => jwt_response['token_type'],
|
124
|
+
'custom_claims' => custom_claims
|
125
|
+
}
|
126
|
+
end
|
127
|
+
|
128
|
+
# Introspects a token JWT from an authorization code response.
|
129
|
+
# Access tokens are JWTs signed with the project's JWKs. Refresh tokens are opaque tokens.
|
130
|
+
# Access tokens contain a standard set of claims as well as any custom claims generated from templates.
|
131
|
+
#
|
132
|
+
# == Parameters:
|
133
|
+
# access_token::
|
134
|
+
# The access token (or refresh token) to introspect.
|
135
|
+
# The type of this field is +String+.
|
136
|
+
# authorization_check::
|
137
|
+
# Optional authorization check object.
|
138
|
+
# The type of this field is nilable +Hash+.
|
139
|
+
#
|
140
|
+
# == Returns:
|
141
|
+
# An object with the following fields:
|
142
|
+
# subject::
|
143
|
+
# The subject of the token.
|
144
|
+
# The type of this field is +String+.
|
145
|
+
# scope::
|
146
|
+
# The scope of the token.
|
147
|
+
# The type of this field is +String+.
|
148
|
+
# audience::
|
149
|
+
# The audience of the token.
|
150
|
+
# The type of this field is +String+.
|
151
|
+
# expires_at::
|
152
|
+
# The expiration time of the token.
|
153
|
+
# The type of this field is +Integer+.
|
154
|
+
# issued_at::
|
155
|
+
# The issued at time of the token.
|
156
|
+
# The type of this field is +Integer+.
|
157
|
+
# issuer::
|
158
|
+
# The issuer of the token.
|
159
|
+
# The type of this field is +String+.
|
160
|
+
# not_before::
|
161
|
+
# The not before time of the token.
|
162
|
+
# The type of this field is +Integer+.
|
163
|
+
# token_type::
|
164
|
+
# The type of the token.
|
165
|
+
# The type of this field is +String+.
|
166
|
+
# custom_claims::
|
167
|
+
# Custom claims in the token.
|
168
|
+
# The type of this field is +Hash+.
|
169
|
+
def introspect_access_token_local(
|
170
|
+
access_token:,
|
171
|
+
authorization_check: nil
|
172
|
+
)
|
173
|
+
scope_claim = 'scope'
|
174
|
+
|
175
|
+
# Create a JWKS loader similar to other classes in the codebase
|
176
|
+
@cache_last_update = 0
|
177
|
+
jwks_loader = lambda do |options|
|
178
|
+
@cached_keys = nil if options[:invalidate] && @cache_last_update < Time.now.to_i - 300
|
179
|
+
if @cached_keys.nil?
|
180
|
+
@cached_keys = get_jwks(project_id: @project_id)
|
181
|
+
@cache_last_update = Time.now.to_i
|
182
|
+
end
|
183
|
+
@cached_keys
|
184
|
+
end
|
185
|
+
|
186
|
+
begin
|
187
|
+
decoded_jwt = JWT.decode(
|
188
|
+
access_token,
|
189
|
+
nil,
|
190
|
+
true,
|
191
|
+
{
|
192
|
+
algorithms: ['RS256'],
|
193
|
+
jwks: jwks_loader,
|
194
|
+
iss: ["stytch.com/#{@project_id}", @connection.url_prefix],
|
195
|
+
aud: @project_id
|
196
|
+
}
|
197
|
+
)[0]
|
198
|
+
|
199
|
+
generic_claims = decoded_jwt
|
200
|
+
custom_claims = generic_claims.reject { |k, _| @non_custom_claim_keys.include?(k) }
|
201
|
+
scope = generic_claims[scope_claim]
|
202
|
+
|
203
|
+
if authorization_check
|
204
|
+
@policy_cache.perform_scope_authorization_check(
|
205
|
+
token_scopes: scope.split,
|
206
|
+
authorization_check: authorization_check
|
207
|
+
)
|
208
|
+
end
|
209
|
+
|
210
|
+
{
|
211
|
+
'subject' => generic_claims['sub'],
|
212
|
+
'scope' => generic_claims[scope_claim],
|
213
|
+
'audience' => generic_claims['aud'],
|
214
|
+
'expires_at' => generic_claims['exp'],
|
215
|
+
'issued_at' => generic_claims['iat'],
|
216
|
+
'issuer' => generic_claims['iss'],
|
217
|
+
'not_before' => generic_claims['nbf'],
|
218
|
+
'token_type' => 'access_token',
|
219
|
+
'custom_claims' => custom_claims
|
220
|
+
}
|
221
|
+
rescue JWT::InvalidIssuerError
|
222
|
+
raise Stytch::JWTInvalidIssuerError
|
223
|
+
rescue JWT::InvalidAudError
|
224
|
+
raise Stytch::JWTInvalidAudienceError
|
225
|
+
rescue JWT::ExpiredSignature
|
226
|
+
raise Stytch::JWTExpiredSignatureError
|
227
|
+
rescue JWT::IncorrectAlgorithm
|
228
|
+
raise Stytch::JWTIncorrectAlgorithmError
|
229
|
+
rescue JWT::DecodeError
|
230
|
+
nil
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
# Gets the JWKS for the project.
|
235
|
+
#
|
236
|
+
# == Parameters:
|
237
|
+
# project_id::
|
238
|
+
# The ID of the project.
|
239
|
+
# The type of this field is +String+.
|
240
|
+
#
|
241
|
+
# == Returns:
|
242
|
+
# The JWKS for the project.
|
243
|
+
# The type of this field is +Hash+.
|
244
|
+
def get_jwks(project_id:)
|
245
|
+
headers = {}
|
246
|
+
query_params = {}
|
247
|
+
request = request_with_query_params("/v1/sessions/jwks/#{project_id}", query_params)
|
248
|
+
get_request(request, headers)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
data/lib/stytch/otps.rb
CHANGED
@@ -130,7 +130,7 @@ module Stytch
|
|
130
130
|
# ### Cost to send SMS OTP
|
131
131
|
# Before configuring SMS or WhatsApp OTPs, please review how Stytch [bills the costs of international OTPs](https://stytch.com/pricing) and understand how to protect your app against [toll fraud](https://stytch.com/docs/guides/passcodes/toll-fraud/overview).
|
132
132
|
#
|
133
|
-
# __Note:__ SMS to phone numbers outside of the US and Canada is disabled by default for customers who did not use SMS prior to October 2023. If you're interested in sending international SMS, please add those countries to your Project's allowlist via
|
133
|
+
# __Note:__ SMS to phone numbers outside of the US and Canada is disabled by default for customers who did not use SMS prior to October 2023. If you're interested in sending international SMS, please add those countries to your Project's allowlist via the [Dashboard](https://stytch.com/dashboard/country-code-allowlists) or [Programmatic Workspace Actions](https://stytch.com/docs/workspace-management/pwa/set-allowed-country-codes), and [add credit card details](https://stytch.com/dashboard/settings/billing) to your account.
|
134
134
|
#
|
135
135
|
# Even when international SMS is enabled, we do not support sending SMS to countries on our [Unsupported countries list](https://stytch.com/docs/guides/passcodes/unsupported-countries).
|
136
136
|
#
|
@@ -212,7 +212,7 @@ module Stytch
|
|
212
212
|
# ### Cost to send SMS OTP
|
213
213
|
# Before configuring SMS or WhatsApp OTPs, please review how Stytch [bills the costs of international OTPs](https://stytch.com/pricing) and understand how to protect your app against [toll fraud](https://stytch.com/docs/guides/passcodes/toll-fraud/overview).
|
214
214
|
#
|
215
|
-
# __Note:__ SMS to phone numbers outside of the US and Canada is disabled by default for customers who did not use SMS prior to October 2023. If you're interested in sending international SMS, please add those countries to your Project's allowlist via
|
215
|
+
# __Note:__ SMS to phone numbers outside of the US and Canada is disabled by default for customers who did not use SMS prior to October 2023. If you're interested in sending international SMS, please add those countries to your Project's allowlist via the [Dashboard](https://stytch.com/dashboard/country-code-allowlists) or [Programmatic Workspace Actions](https://stytch.com/docs/workspace-management/pwa/set-allowed-country-codes), and [add credit card details](https://stytch.com/dashboard/settings/billing) to your account.
|
216
216
|
#
|
217
217
|
# Even when international SMS is enabled, we do not support sending SMS to countries on our [Unsupported countries list](https://stytch.com/docs/guides/passcodes/unsupported-countries).
|
218
218
|
#
|
data/lib/stytch/passwords.rb
CHANGED
@@ -116,7 +116,7 @@ module Stytch
|
|
116
116
|
|
117
117
|
# Authenticate a user with their email address and password. This endpoint verifies that the user has a password currently set, and that the entered password is correct. There are two instances where the endpoint will return a `reset_password` error even if they enter their previous password:
|
118
118
|
#
|
119
|
-
# **One:** The user
|
119
|
+
# **One:** The user's credentials appeared in the HaveIBeenPwned dataset. We force a password reset to ensure that the user is the legitimate owner of the email address, and not a malicious actor abusing the compromised credentials.
|
120
120
|
#
|
121
121
|
# **Two:** A user that has previously authenticated with email/password uses a passwordless authentication method tied to the same email address (e.g. Magic Links, Google OAuth) for the first time. Any subsequent email/password authentication attempt will result in this error. We force a password reset in this instance in order to safely deduplicate the account by email address, without introducing the risk of a pre-hijack account takeover attack.
|
122
122
|
#
|
@@ -408,7 +408,7 @@ module Stytch
|
|
408
408
|
# login_redirect_url::
|
409
409
|
# The URL Stytch redirects to after the OAuth flow is completed for a user that already exists. This URL should be a route in your application which will run `oauth.authenticate` (see below) and finish the login.
|
410
410
|
#
|
411
|
-
# The URL must be configured as a Login URL in the [Redirect URL page](https://stytch.com/
|
411
|
+
# The URL must be configured as a Login URL in the [Redirect URL page](https://stytch.com/dashboard/redirect-urls). If the field is not specified, the default Login URL will be used.
|
412
412
|
# The type of this field is nilable +String+.
|
413
413
|
# locale::
|
414
414
|
# Used to determine which language to use when sending the user this delivery method. Parameter is a [IETF BCP 47 language tag](https://www.w3.org/International/articles/language-tags/), e.g. `"en"`.
|
@@ -462,7 +462,7 @@ module Stytch
|
|
462
462
|
post_request('/v1/passwords/email/reset/start', request, headers)
|
463
463
|
end
|
464
464
|
|
465
|
-
# Reset the user
|
465
|
+
# Reset the user's password and authenticate them. This endpoint checks that the magic link `token` is valid, hasn't expired, or already been used – and can optionally require additional security settings, such as the IP address and user agent matching the initial reset request.
|
466
466
|
#
|
467
467
|
# The provided password needs to meet our password strength requirements, which can be checked in advance with the password strength endpoint. If the token and password are accepted, the password is securely stored for future authentication and the user is authenticated.
|
468
468
|
#
|
@@ -572,7 +572,7 @@ module Stytch
|
|
572
572
|
@connection = connection
|
573
573
|
end
|
574
574
|
|
575
|
-
# Reset the User
|
575
|
+
# Reset the User's password using their existing password.
|
576
576
|
#
|
577
577
|
# Note that a successful password reset via an existing password will revoke all active sessions for the `user_id`.
|
578
578
|
#
|
data/lib/stytch/rbac.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# !!!
|
4
|
+
# WARNING: This file is autogenerated
|
5
|
+
# Only modify code within MANUAL() sections
|
6
|
+
# or your changes may be overwritten later!
|
7
|
+
# !!!
|
8
|
+
|
9
|
+
require_relative 'request_helper'
|
10
|
+
|
11
|
+
module Stytch
|
12
|
+
class RBAC
|
13
|
+
include Stytch::RequestHelper
|
14
|
+
|
15
|
+
def initialize(connection)
|
16
|
+
@connection = connection
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get the active RBAC Policy for your current Stytch Project. An RBAC Policy is the canonical document that stores all defined Resources and Roles within your RBAC permissioning model.
|
20
|
+
#
|
21
|
+
# When using the backend SDKs, the RBAC Policy will be cached to allow for local evaluations, eliminating the need for an extra request to Stytch.
|
22
|
+
# The policy will be refreshed if an authorization check is requested and the RBAC policy was last updated more than 5 minutes ago.
|
23
|
+
#
|
24
|
+
# Resources and Roles can be created and managed within the [RBAC page](https://stytch.com/dashboard/rbac) in the Dashboard.
|
25
|
+
# Additionally, [Role assignment](https://stytch.com/docs/guides/rbac/role-assignment) can be programmatically managed through certain Stytch API endpoints.
|
26
|
+
#
|
27
|
+
# Check out the [RBAC overview](https://stytch.com/docs/guides/rbac/overview) to learn more about Stytch's RBAC permissioning model.
|
28
|
+
#
|
29
|
+
# == Parameters:
|
30
|
+
#
|
31
|
+
# == Returns:
|
32
|
+
# An object with the following fields:
|
33
|
+
# request_id::
|
34
|
+
# Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
|
35
|
+
# The type of this field is +String+.
|
36
|
+
# status_code::
|
37
|
+
# 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.
|
38
|
+
# The type of this field is +Integer+.
|
39
|
+
# policy::
|
40
|
+
# The RBAC Policy document that contains all defined Roles and Resources – which are managed in the [Dashboard](https://stytch.com/dashboard/rbac). Read more about these entities and how they work in our [RBAC overview](https://stytch.com/docs/guides/rbac/overview).
|
41
|
+
# The type of this field is nilable +Policy+ (+object+).
|
42
|
+
def policy
|
43
|
+
headers = {}
|
44
|
+
query_params = {}
|
45
|
+
request = request_with_query_params('/v1/rbac/policy', query_params)
|
46
|
+
get_request(request, headers)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|