lib/stytch/webauthn.rb in stytch-6.5.1 vs lib/stytch/webauthn.rb in stytch-6.5.2
- old
+ new
@@ -31,10 +31,13 @@
# The user agent of the User.
# The type of this field is nilable +String+.
# authenticator_type::
# The requested authenticator type of the WebAuthn device. The two valid value are platform and cross-platform. If no value passed, we assume both values are allowed.
# The type of this field is nilable +String+.
+ # return_passkey_credential_options::
+ # If true, the public_key_credential_creation_options returned will be optimized for Passkeys.
+ # The type of this field is nilable +Boolean+.
#
# == 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.
@@ -50,18 +53,20 @@
# The type of this field is +Integer+.
def register_start(
user_id:,
domain:,
user_agent: nil,
- authenticator_type: nil
+ authenticator_type: nil,
+ return_passkey_credential_options: nil
)
request = {
user_id: user_id,
domain: domain
}
request[:user_agent] = user_agent unless user_agent.nil?
request[:authenticator_type] = authenticator_type unless authenticator_type.nil?
+ request[:return_passkey_credential_options] = return_passkey_credential_options unless return_passkey_credential_options.nil?
post_request('/v1/webauthn/register/start', request)
end
# Complete the creation of a WebAuthn registration by passing the response from the [navigator.credentials.create()](https://www.w3.org/TR/webauthn-2/#sctn-createCredential) request to this endpoint as the `public_key_credential` parameter.
@@ -73,11 +78,25 @@
# The `user_id` of an active user the WebAuthn registration should be tied to.
# The type of this field is +String+.
# public_key_credential::
# The response of the [navigator.credentials.create()](https://www.w3.org/TR/webauthn-2/#sctn-createCredential).
# The type of this field is +String+.
+ # session_token::
+ # The session token to authenticate.
+ # The type of this field is nilable +String+.
+ # session_duration_minutes::
+ # Set the session lifetime to be this many minutes from now; minimum of 5 and a maximum of 527040 minutes (366 days). Note that a successful authentication will continue to extend the session this many minutes.
+ # The type of this field is nilable +Integer+.
+ # session_jwt::
+ # The JWT to authenticate. You may provide a JWT that has expired according to its `exp` claim and needs to be refreshed. If the signature is valid and the underlying session is still active then Stytch will return a new JWT.
+ # 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+.
@@ -85,36 +104,62 @@
# The unique ID of the affected User.
# The type of this field is +String+.
# webauthn_registration_id::
# The unique ID for the WebAuthn registration.
# 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](https://stytch.com/docs/api/get-user) for complete response field details.
+ # The type of this field is +User+ (+object+).
# 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](https://stytch.com/docs/api/session-get) for complete response fields.
+ #
+ # The type of this field is nilable +Session+ (+object+).
def register(
user_id:,
- public_key_credential:
+ public_key_credential:,
+ session_token: nil,
+ session_duration_minutes: nil,
+ session_jwt: nil,
+ session_custom_claims: nil
)
request = {
user_id: user_id,
public_key_credential: public_key_credential
}
+ request[:session_token] = session_token unless session_token.nil?
+ request[:session_jwt] = session_jwt unless session_jwt.nil?
+ request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
+ request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
post_request('/v1/webauthn/register', request)
end
# Initiate the authentication of a WebAuthn registration. After calling this endpoint, the browser will need to call [navigator.credentials.get()](https://www.w3.org/TR/webauthn-2/#sctn-getAssertion) with the data from `public_key_credential_request_options` passed to the [navigator.credentials.get()](https://www.w3.org/TR/webauthn-2/#sctn-getAssertion) request via the public key argument. We recommend using the `get()` wrapper provided by the webauthn-json library.
#
# If you are not using the [webauthn-json](https://github.com/github/webauthn-json) library, `the public_key_credential_request_options` will need to be converted to a suitable public key by unmarshalling the JSON and converting some the fields to array buffers.
#
# == Parameters:
- # user_id::
- # The `user_id` of an active user the WebAuthn registration should be tied to.
- # The type of this field is +String+.
# domain::
# The domain for WebAuthn. Defaults to `window.location.hostname`.
# The type of this field is +String+.
+ # user_id::
+ # The `user_id` of an active user the WebAuthn registration should be tied to.
+ # The type of this field is nilable +String+.
+ # return_passkey_credential_options::
+ # If true, the public_key_credential_creation_options returned will be optimized for Passkeys.
+ # The type of this field is nilable +Boolean+.
#
# == 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.
@@ -127,17 +172,19 @@
# The type of this field is +String+.
# 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+.
def authenticate_start(
- user_id:,
- domain:
+ domain:,
+ user_id: nil,
+ return_passkey_credential_options: nil
)
request = {
- user_id: user_id,
domain: domain
}
+ request[:user_id] = user_id unless user_id.nil?
+ request[:return_passkey_credential_options] = return_passkey_credential_options unless return_passkey_credential_options.nil?
post_request('/v1/webauthn/authenticate/start', request)
end
# Complete the authentication of a WebAuthn registration by passing the response from the [navigator.credentials.get()](https://www.w3.org/TR/webauthn-2/#sctn-getAssertion) request to the authenticate endpoint.
@@ -214,8 +261,19 @@
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/webauthn/authenticate', request)
+ end
+
+ def update(
+ webauthn_registration_id:,
+ name:
+ )
+ request = {
+ name: name
+ }
+
+ put_request("/v1/webauthn/#{webauthn_registration_id}", request)
end
end
end