Class: Stytch::OTPs
- Inherits:
-
Object
- Object
- Stytch::OTPs
- Includes:
- RequestHelper
- Defined in:
- lib/stytch/otps.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#sms ⇒ Object
readonly
Returns the value of attribute sms.
-
#whatsapp ⇒ Object
readonly
Returns the value of attribute whatsapp.
Instance Method Summary collapse
-
#authenticate(method_id:, code:, attributes: nil, options: nil, session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil) ⇒ Object
Authenticate a User given a ‘method_id` (the associated `email_id` or `phone_id`) and a `code`.
-
#initialize(connection) ⇒ OTPs
constructor
A new instance of OTPs.
Methods included from RequestHelper
#delete_request, #get_request, #post_request, #put_request, #request_with_query_params
Constructor Details
#initialize(connection) ⇒ OTPs
Returns a new instance of OTPs.
16 17 18 19 20 21 22 |
# File 'lib/stytch/otps.rb', line 16 def initialize(connection) @connection = connection @sms = Stytch::OTPs::Sms.new(@connection) @whatsapp = Stytch::OTPs::Whatsapp.new(@connection) @email = Stytch::OTPs::Email.new(@connection) end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
14 15 16 |
# File 'lib/stytch/otps.rb', line 14 def email @email end |
#sms ⇒ Object (readonly)
Returns the value of attribute sms.
14 15 16 |
# File 'lib/stytch/otps.rb', line 14 def sms @sms end |
#whatsapp ⇒ Object (readonly)
Returns the value of attribute whatsapp.
14 15 16 |
# File 'lib/stytch/otps.rb', line 14 def whatsapp @whatsapp end |
Instance Method Details
#authenticate(method_id:, code:, attributes: nil, options: nil, session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil) ⇒ Object
Authenticate a User given a ‘method_id` (the associated `email_id` or `phone_id`) and a `code`. This endpoint verifies that the code is valid, hasn’t expired or been previously used, and any optional security settings such as IP match or user agent match are satisfied. A given ‘method_id` may only have a single active OTP code at any given time, if a User requests another OTP code before the first one has expired, the first one will be invalidated.
Parameters:
- method_id
-
The ‘email_id` or `phone_id` involved in the given authentication. The type of this field is
String
. - code
-
The code to authenticate. The type of this field is
String
. - attributes
-
Provided attributes help with fraud detection. The type of this field is nilable
Attributes
(object
). - options
-
Specify optional security settings. The type of this field is nilable
Options
(object
). - session_token
-
The ‘session_token` associated with a User’s existing Session. The type of this field is nilable
String
. - session_duration_minutes
-
Set the session lifetime to be this many minutes from now. This will start a new session if one doesn’t already exist, returning both an opaque ‘session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of five minutes regardless of the underlying session duration, and will need to be refreshed over time.
This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).
If a ‘session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.
If the ‘session_duration_minutes` parameter is not specified, a Stytch session will not be created. The type of this field is nilable
Integer
. - session_jwt
-
The ‘session_jwt` associated with a User’s existing Session. The type of this field is nilable
String
. - session_custom_claims
-
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.
Custom claims made with reserved claims (“iss”, “sub”, “aud”, “exp”, “nbf”, “iat”, “jti”) will be ignored. Total custom claims size cannot exceed four kilobytes. The type of this field is nilable
object
.
Returns:
An object with the following fields:
- request_id
-
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. The type of this field is
String
. - user_id
-
The unique ID of the affected User. The type of this field is
String
. - method_id
-
The ‘email_id` or `phone_id` involved in the given authentication. The type of this field is
String
. - session_token
-
A secret token for a given Stytch Session. The type of this field is
String
. - session_jwt
-
The JSON Web Token (JWT) for a given Stytch Session. The type of this field is
String
. - user
-
The ‘user` object affected by this API call. See the [Get user endpoint](stytch.com/docs/api/get-user) for complete response field details. The type of this field is
User
(object
). - reset_sessions
-
Indicates if all other of the User’s Sessions need to be reset. You should check this field if you aren’t using Stytch’s Session product. If you are using Stytch’s Session product, we revoke the User’s other sessions for you. The type of this field is
Boolean
. - status_code
-
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. The type of this field is
Integer
. - session
-
If you initiate a Session, by including ‘session_duration_minutes` in your authenticate call, you’ll receive a full Session object in the response.
See [GET sessions](stytch.com/docs/api/session-get) for complete response fields.
The type of this field is nilable
Session
(object
).
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/stytch/otps.rb', line 94 def authenticate( method_id:, code:, attributes: nil, options: nil, session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil ) headers = {} request = { method_id: method_id, code: code } request[:attributes] = attributes unless attributes.nil? request[:options] = unless .nil? request[:session_token] = session_token unless session_token.nil? request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil? request[:session_jwt] = session_jwt unless session_jwt.nil? request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil? post_request('/v1/otps/authenticate', request, headers) end |