Class: Stytch::WebAuthn
- Inherits:
-
Object
- Object
- Stytch::WebAuthn
- Includes:
- RequestHelper
- Defined in:
- lib/stytch/webauthn.rb
Instance Method Summary collapse
-
#authenticate(public_key_credential:, session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil, telemetry_id: nil) ⇒ Object
Complete the authentication of a Passkey or WebAuthn registration by passing the response from the navigator.credentials.get() request to the authenticate endpoint.
-
#authenticate_start(domain:, user_id: nil, return_passkey_credential_options: nil, use_base64_url_encoding: nil) ⇒ Object
Initiate the authentication of a Passkey or WebAuthn registration.
-
#initialize(connection) ⇒ WebAuthn
constructor
A new instance of WebAuthn.
-
#list_credentials(user_id:, domain:) ⇒ Object
List the public key credentials of the WebAuthn Registrations or Passkeys registered to a specific User.
-
#register(user_id:, public_key_credential:, session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil, telemetry_id: nil) ⇒ Object
Complete the creation of a WebAuthn registration by passing the response from the navigator.credentials.create() request to this endpoint as the
public_key_credentialparameter. -
#register_start(user_id:, domain:, user_agent: nil, authenticator_type: nil, return_passkey_credential_options: nil, override_id: nil, override_name: nil, override_display_name: nil, use_base64_url_encoding: nil) ⇒ Object
Initiate the process of creating a new Passkey or WebAuthn registration.
-
#update(webauthn_registration_id:, name:) ⇒ Object
Updates a Passkey or WebAuthn registration.
Methods included from RequestHelper
#delete_request, #get_request, #post_request, #put_request, #request_with_query_params
Constructor Details
#initialize(connection) ⇒ WebAuthn
Returns a new instance of WebAuthn.
15 16 17 |
# File 'lib/stytch/webauthn.rb', line 15 def initialize(connection) @connection = connection end |
Instance Method Details
#authenticate(public_key_credential:, session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil, telemetry_id: nil) ⇒ Object
Complete the authentication of a Passkey or WebAuthn registration by passing the response from the navigator.credentials.get() request to the authenticate endpoint.
See our WebAuthn setup guide for additional usage instructions and example code.
Parameters:
- public_key_credential
The response of the navigator.credentials.create(). The type of this field is
String.- session_token
The
session_tokenassociated with a User's existing Session. The type of this field is nilableString.- 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_tokenandsession_jwtfor this session. Remember that thesession_jwtwill 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_jwtassociated with a User's existing Session. The type of this field is nilableString.- 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.
- telemetry_id
If the
telemetry_idis passed, as part of this request, Stytch will call the Fingerprint Lookup API and store the associated fingerprints and IPGEO information for the User. Your workspace must be enabled for Device Fingerprinting to use this feature. The type of this field is nilableString.
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.- webauthn_registration_id
The unique ID for the Passkey or 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
userobject affected by this API call. See the Get user endpoint for complete response field details. The type of this field isUser(+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_minutesin your authenticate call, you'll receive a full Session object in the response.
See Session object for complete response fields.
The type of this field is nilable +Session+ (+object+).
- user_device
If a valid
telemetry_idwas passed in the request and the Fingerprint Lookup API returned results, theuser_deviceresponse field will contain information about the user's device attributes. The type of this field is nilableDeviceInfo(+object+).
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/stytch/webauthn.rb', line 314 def authenticate( public_key_credential:, session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil, telemetry_id: nil ) headers = {} request = { public_key_credential: public_key_credential } 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? request[:telemetry_id] = telemetry_id unless telemetry_id.nil? post_request('/v1/webauthn/authenticate', request, headers) end |
#authenticate_start(domain:, user_id: nil, return_passkey_credential_options: nil, use_base64_url_encoding: nil) ⇒ Object
Initiate the authentication of a Passkey or WebAuthn registration.
To optimize for Passkeys, set the return_passkey_credential_options field to true.
After calling this endpoint, the browser will need to call navigator.credentials.get() with the data from public_key_credential_request_options passed to the navigator.credentials.get() request via the public key argument.
When using built-in browser methods like navigator.credentials.get(), set the use_base64_url_encoding option to true.
See our WebAuthn setup guide for additional usage instructions and example code.
Parameters:
- domain
The domain for Passkeys or WebAuthn. Defaults to
window.location.hostname. The type of this field isString.- user_id
The
user_idof an active user the Passkey or WebAuthn registration should be tied to. You may use anexternal_idhere if one is set for the user. The type of this field is nilableString.- return_passkey_credential_options
If true, the
public_key_credential_creation_optionsreturned will be optimized for Passkeys withuserVerificationset to"preferred".
The type of this field is nilable Boolean.
- use_base64_url_encoding
If true, values in the
public_key_credential_creation_optionswill be base64 URL encoded. Set this option to true when using built-in browser methods likenavigator.credentials.createandnavigator.credentials.get. The type of this field is nilableBoolean.
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.- public_key_credential_request_options
Options used for Passkey or WebAuthn authentication. 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.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/stytch/webauthn.rb', line 231 def authenticate_start( domain:, user_id: nil, return_passkey_credential_options: nil, use_base64_url_encoding: nil ) headers = {} request = { domain: domain } request[:user_id] = user_id unless user_id.nil? request[:return_passkey_credential_options] = unless .nil? request[:use_base64_url_encoding] = use_base64_url_encoding unless use_base64_url_encoding.nil? post_request('/v1/webauthn/authenticate/start', request, headers) end |
#list_credentials(user_id:, domain:) ⇒ Object
List the public key credentials of the WebAuthn Registrations or Passkeys registered to a specific User.
Parameters:
- user_id
The
user_idof an active user the Passkey or WebAuthn registration should be tied to. The type of this field isString.- domain
The domain for Passkeys or WebAuthn. Defaults to
window.location.hostname. The type of this field isString.
Returns:
An object with the following fields:
- credentials
A list of WebAuthn credential objects. The type of this field is list of
WebAuthnCredential(+object+).- 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.- 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.
389 390 391 392 393 394 395 396 397 |
# File 'lib/stytch/webauthn.rb', line 389 def list_credentials( user_id:, domain: ) headers = {} query_params = {} request = request_with_query_params("/v1/webauthn/credentials/#{user_id}/#{domain}", query_params) get_request(request, headers) end |
#register(user_id:, public_key_credential:, session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil, telemetry_id: nil) ⇒ Object
Complete the creation of a WebAuthn registration by passing the response from the navigator.credentials.create() request to this endpoint as the public_key_credential parameter.
See our WebAuthn setup guide for additional usage instructions and example code.
Parameters:
- user_id
The
user_idof an active user the Passkey or WebAuthn registration should be tied to. You may use anexternal_idhere if one is set for the user. The type of this field isString.- public_key_credential
The response of the navigator.credentials.create(). The type of this field is
String.- session_token
The
session_tokenassociated with a User's existing Session. The type of this field is nilableString.- 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_tokenandsession_jwtfor this session. Remember that thesession_jwtwill 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_jwtassociated with a User's existing Session. The type of this field is nilableString.- 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.
- telemetry_id
If the
telemetry_idis passed, as part of this request, Stytch will call the Fingerprint Lookup API and store the associated fingerprints and IPGEO information for the User. Your workspace must be enabled for Device Fingerprinting to use this feature. The type of this field is nilableString.
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.- webauthn_registration_id
The unique ID for the Passkey or 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
(no documentation yet) 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_minutesin your authenticate call, you'll receive a full Session object in the response.
See Session object for complete response fields.
The type of this field is nilable +Session+ (+object+).
- user_device
If a valid
telemetry_idwas passed in the request and the Fingerprint Lookup API returned results, theuser_deviceresponse field will contain information about the user's device attributes. The type of this field is nilableDeviceInfo(+object+).
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/stytch/webauthn.rb', line 169 def register( user_id:, public_key_credential:, session_token: nil, session_duration_minutes: nil, session_jwt: nil, session_custom_claims: nil, telemetry_id: nil ) headers = {} request = { user_id: user_id, public_key_credential: public_key_credential } 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? request[:telemetry_id] = telemetry_id unless telemetry_id.nil? post_request('/v1/webauthn/register', request, headers) end |
#register_start(user_id:, domain:, user_agent: nil, authenticator_type: nil, return_passkey_credential_options: nil, override_id: nil, override_name: nil, override_display_name: nil, use_base64_url_encoding: nil) ⇒ Object
Initiate the process of creating a new Passkey or WebAuthn registration.
To optimize for Passkeys, set the return_passkey_credential_options field to true.
After calling this endpoint, the browser will need to call navigator.credentials.create() with the data from public_key_credential_creation_options passed to the navigator.credentials.create() request via the public key argument.
When using built-in browser methods like navigator.credentials.create(), set the use_base64_url_encoding option to true.
See our WebAuthn setup guide for additional usage instructions and example code.
Parameters:
- user_id
The
user_idof an active user the Passkey or WebAuthn registration should be tied to. You may use anexternal_idhere if one is set for the user. The type of this field isString.- domain
The domain for Passkeys or WebAuthn. Defaults to
window.location.hostname. The type of this field isString.- user_agent
The user agent of the client. The type of this field is nilable
String.- authenticator_type
The requested authenticator type of the Passkey or WebAuthn device. The two valid values 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_optionsreturned will be optimized for Passkeys withresidentKeyset to"required"anduserVerificationset to"preferred".
The type of this field is nilable Boolean.
- override_id
(no documentation yet) The type of this field is nilable
String.- override_name
(no documentation yet) The type of this field is nilable
String.- override_display_name
(no documentation yet) The type of this field is nilable
String.- use_base64_url_encoding
If true, values in the
public_key_credential_creation_optionswill be base64 URL encoded. Set this option to true when using built-in browser methods likenavigator.credentials.createandnavigator.credentials.get. The type of this field is nilableBoolean.
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.- public_key_credential_creation_options
Options used for Passkey or WebAuthn registration. 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.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/stytch/webauthn.rb', line 73 def register_start( user_id:, domain:, user_agent: nil, authenticator_type: nil, return_passkey_credential_options: nil, override_id: nil, override_name: nil, override_display_name: nil, use_base64_url_encoding: nil ) headers = {} 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] = unless .nil? request[:override_id] = override_id unless override_id.nil? request[:override_name] = override_name unless override_name.nil? request[:override_display_name] = override_display_name unless override_display_name.nil? request[:use_base64_url_encoding] = use_base64_url_encoding unless use_base64_url_encoding.nil? post_request('/v1/webauthn/register/start', request, headers) end |
#update(webauthn_registration_id:, name:) ⇒ Object
Updates a Passkey or WebAuthn registration.
Parameters:
- webauthn_registration_id
Globally unique UUID that identifies a Passkey or WebAuthn registration in the Stytch API. The
webauthn_registration_idis used when you need to operate on a specific User's WebAuthn registration. The type of this field isString.- name
The
nameof the WebAuthn registration or Passkey. The type of this field isString.
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.- 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.- webauthn_registration
A Passkey or WebAuthn registration. The type of this field is nilable
WebAuthnRegistration(+object+).
356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/stytch/webauthn.rb', line 356 def update( webauthn_registration_id:, name: ) headers = {} request = { name: name } put_request("/v1/webauthn/#{webauthn_registration_id}", request, headers) end |