stytch 5.0.2 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/stytch/client.rb CHANGED
@@ -1,20 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'users'
3
+ require_relative 'crypto_wallets'
4
4
  require_relative 'magic_links'
5
5
  require_relative 'oauth'
6
6
  require_relative 'otps'
7
+ require_relative 'passwords'
7
8
  require_relative 'sessions'
8
9
  require_relative 'totps'
10
+ require_relative 'users'
9
11
  require_relative 'webauthn'
10
- require_relative 'crypto_wallets'
11
- require_relative 'passwords'
12
12
 
13
13
  module Stytch
14
14
  class Client
15
15
  ENVIRONMENTS = %i[live test].freeze
16
16
 
17
- attr_reader :users, :magic_links, :oauth, :otps, :sessions, :totps, :webauthn, :crypto_wallets, :passwords
17
+ attr_reader :crypto_wallets, :magic_links, :oauth, :otps, :passwords, :sessions, :totps, :users, :webauthn
18
18
 
19
19
  def initialize(project_id:, secret:, env: nil, &block)
20
20
  @api_host = api_host(env, project_id)
@@ -23,15 +23,15 @@ module Stytch
23
23
 
24
24
  create_connection(&block)
25
25
 
26
- @users = Stytch::Users.new(@connection)
26
+ @crypto_wallets = Stytch::CryptoWallets.new(@connection)
27
27
  @magic_links = Stytch::MagicLinks.new(@connection)
28
28
  @oauth = Stytch::OAuth.new(@connection)
29
29
  @otps = Stytch::OTPs.new(@connection)
30
- @sessions = Stytch::Sessions.new(@connection, @project_id)
30
+ @passwords = Stytch::Passwords.new(@connection)
31
+ @sessions = Stytch::Sessions.new(@connection, project_id)
31
32
  @totps = Stytch::TOTPs.new(@connection)
33
+ @users = Stytch::Users.new(@connection)
32
34
  @webauthn = Stytch::WebAuthn.new(@connection)
33
- @crypto_wallets = Stytch::CryptoWallets.new(@connection)
34
- @passwords = Stytch::Passwords.new(@connection)
35
35
  end
36
36
 
37
37
  private
@@ -42,7 +42,7 @@ module Stytch
42
42
  'https://api.stytch.com'
43
43
  when :test
44
44
  'https://test.stytch.com'
45
- when /\Ahttps?:\/\//
45
+ when %r{\Ahttps?://}
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
@@ -1,57 +1,156 @@
1
1
  # frozen_string_literal: true
2
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
+
3
9
  require_relative 'request_helper'
4
10
 
5
11
  module Stytch
6
12
  class CryptoWallets
7
13
  include Stytch::RequestHelper
8
14
 
9
- PATH = '/v1/crypto_wallets'
10
-
11
15
  def initialize(connection)
12
16
  @connection = connection
13
17
  end
14
18
 
19
+ # Initiate the authentication of a crypto wallet. After calling this endpoint, the user will need to sign a message containing only the returned `challenge` field.
20
+ #
21
+ # == Parameters:
22
+ # crypto_wallet_type::
23
+ # The type of wallet to authenticate. Currently `ethereum` and `solana` are supported. Wallets for any EVM-compatible chains (such as Polygon or BSC) are also supported and are grouped under the `ethereum` type.
24
+ # The type of this field is +String+.
25
+ # crypto_wallet_address::
26
+ # The crypto wallet address to authenticate.
27
+ # The type of this field is +String+.
28
+ # user_id::
29
+ # The unique ID of a specific User.
30
+ # The type of this field is nilable +String+.
31
+ # session_token::
32
+ # The `session_token` associated with a User's existing Session.
33
+ # The type of this field is nilable +String+.
34
+ # session_jwt::
35
+ # The `session_jwt` associated with a User's existing Session.
36
+ # The type of this field is nilable +String+.
37
+ #
38
+ # == Returns:
39
+ # An object with the following fields:
40
+ # request_id::
41
+ # 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.
42
+ # The type of this field is +String+.
43
+ # user_id::
44
+ # The unique ID of the affected User.
45
+ # The type of this field is +String+.
46
+ # challenge::
47
+ # A challenge string to be signed by the wallet in order to prove ownership.
48
+ # The type of this field is +String+.
49
+ # user_created::
50
+ # In `login_or_create` endpoints, this field indicates whether or not a User was just created.
51
+ # The type of this field is +Boolean+.
52
+ # status_code::
53
+ # 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.
54
+ # The type of this field is +Integer+.
15
55
  def authenticate_start(
16
- crypto_wallet_address:,
17
56
  crypto_wallet_type:,
57
+ crypto_wallet_address:,
18
58
  user_id: nil,
19
59
  session_token: nil,
20
60
  session_jwt: nil
21
61
  )
22
62
  request = {
23
- crypto_wallet_address: crypto_wallet_address,
24
- crypto_wallet_type: crypto_wallet_type
63
+ crypto_wallet_type: crypto_wallet_type,
64
+ crypto_wallet_address: crypto_wallet_address
25
65
  }
26
-
27
66
  request[:user_id] = user_id unless user_id.nil?
28
67
  request[:session_token] = session_token unless session_token.nil?
29
68
  request[:session_jwt] = session_jwt unless session_jwt.nil?
30
69
 
31
- post_request("#{PATH}/authenticate/start", request)
70
+ post_request('/v1/crypto_wallets/authenticate/start', request)
32
71
  end
33
72
 
73
+ # Complete the authentication of a crypto wallet by passing the signature.
74
+ #
75
+ # == Parameters:
76
+ # crypto_wallet_type::
77
+ # The type of wallet to authenticate. Currently `ethereum` and `solana` are supported. Wallets for any EVM-compatible chains (such as Polygon or BSC) are also supported and are grouped under the `ethereum` type.
78
+ # The type of this field is +String+.
79
+ # crypto_wallet_address::
80
+ # The crypto wallet address to authenticate.
81
+ # The type of this field is +String+.
82
+ # signature::
83
+ # The signature from the message challenge.
84
+ # The type of this field is +String+.
85
+ # session_token::
86
+ # The `session_token` associated with a User's existing Session.
87
+ # The type of this field is nilable +String+.
88
+ # session_duration_minutes::
89
+ # Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
90
+ # returning both an opaque `session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of
91
+ # five minutes regardless of the underlying session duration, and will need to be refreshed over time.
92
+ #
93
+ # This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
94
+ #
95
+ # If a `session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.
96
+ #
97
+ # If the `session_duration_minutes` parameter is not specified, a Stytch session will not be created.
98
+ # The type of this field is nilable +Integer+.
99
+ # session_jwt::
100
+ # The `session_jwt` associated with a User's existing Session.
101
+ # The type of this field is nilable +String+.
102
+ # session_custom_claims::
103
+ # Add a custom claims map to the Session being authenticated. Claims are only created if a Session is initialized by providing a value in `session_duration_minutes`. Claims will be included on the Session object and in the JWT. To update a key in an existing Session, supply a new value. To delete a key, supply a null value.
104
+ #
105
+ # Custom claims made with reserved claims ("iss", "sub", "aud", "exp", "nbf", "iat", "jti") will be ignored. Total custom claims size cannot exceed four kilobytes.
106
+ # The type of this field is nilable +object+.
107
+ #
108
+ # == Returns:
109
+ # An object with the following fields:
110
+ # request_id::
111
+ # 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.
112
+ # The type of this field is +String+.
113
+ # user_id::
114
+ # The unique ID of the affected User.
115
+ # The type of this field is +String+.
116
+ # session_token::
117
+ # A secret token for a given Stytch Session.
118
+ # The type of this field is +String+.
119
+ # session_jwt::
120
+ # The JSON Web Token (JWT) for a given Stytch Session.
121
+ # The type of this field is +String+.
122
+ # user::
123
+ # The `user` object affected by this API call. See the [Get user endpoint](https://stytch.com/docs/api/get-user) for complete response field details.
124
+ # The type of this field is +User+ (+object+).
125
+ # status_code::
126
+ # 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.
127
+ # The type of this field is +Integer+.
128
+ # session::
129
+ # If you initiate a Session, by including `session_duration_minutes` in your authenticate call, you'll receive a full Session object in the response.
130
+ #
131
+ # See [GET sessions](https://stytch.com/docs/api/session-get) for complete response fields.
132
+ #
133
+ # The type of this field is nilable +Session+ (+object+).
34
134
  def authenticate(
35
- crypto_wallet_address:,
36
135
  crypto_wallet_type:,
136
+ crypto_wallet_address:,
37
137
  signature:,
38
138
  session_token: nil,
39
- session_jwt: nil,
40
139
  session_duration_minutes: nil,
140
+ session_jwt: nil,
41
141
  session_custom_claims: nil
42
142
  )
43
143
  request = {
44
- crypto_wallet_address: crypto_wallet_address,
45
144
  crypto_wallet_type: crypto_wallet_type,
145
+ crypto_wallet_address: crypto_wallet_address,
46
146
  signature: signature
47
147
  }
48
-
49
148
  request[:session_token] = session_token unless session_token.nil?
50
- request[:session_jwt] = session_jwt unless session_jwt.nil?
51
149
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
150
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
52
151
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
53
152
 
54
- post_request("#{PATH}/authenticate", request)
153
+ post_request('/v1/crypto_wallets/authenticate', request)
55
154
  end
56
155
  end
57
156
  end
data/lib/stytch/errors.rb CHANGED
@@ -1,25 +1,25 @@
1
1
  module Stytch
2
- class JWTInvalidIssuerError < StandardError
3
- def initialize(msg="JWT issuer did not match")
4
- super
5
- end
2
+ class JWTInvalidIssuerError < StandardError
3
+ def initialize(msg = 'JWT issuer did not match')
4
+ super
6
5
  end
6
+ end
7
7
 
8
- class JWTInvalidAudienceError < StandardError
9
- def initialize(msg="JWT audience did not match")
10
- super
11
- end
8
+ class JWTInvalidAudienceError < StandardError
9
+ def initialize(msg = 'JWT audience did not match')
10
+ super
12
11
  end
12
+ end
13
13
 
14
- class JWTExpiredSignatureError < StandardError
15
- def initialize(msg="JWT signature has expired")
16
- super
17
- end
14
+ class JWTExpiredSignatureError < StandardError
15
+ def initialize(msg = 'JWT signature has expired')
16
+ super
18
17
  end
18
+ end
19
19
 
20
- class JWTIncorrectAlgorithmError < StandardError
21
- def initialize(msg="JWT algorithm is incorrect")
22
- super
23
- end
20
+ class JWTIncorrectAlgorithmError < StandardError
21
+ def initialize(msg = 'JWT algorithm is incorrect')
22
+ super
24
23
  end
24
+ end
25
25
  end