Skip to content

Commit

Permalink
Add WebAuthnUpdate (#99)
Browse files Browse the repository at this point in the history
* Add WebAuthnUpdate

* version

* lint

* lint 2
  • Loading branch information
alex-stytch authored Nov 1, 2023
1 parent 95fe768 commit d8c6a06
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/stytch/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Stytch
VERSION = '6.5.1'
VERSION = '6.5.2'
end
74 changes: 66 additions & 8 deletions lib/stytch/webauthn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def initialize(connection)
# 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:
Expand All @@ -52,14 +55,16 @@ 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
Expand All @@ -75,6 +80,20 @@ def register_start(
# 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:
Expand All @@ -87,17 +106,40 @@ def register_start(
# 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
Expand All @@ -107,12 +149,15 @@ def register(
# 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:
Expand All @@ -129,13 +174,15 @@ def register(
# 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
Expand Down Expand Up @@ -217,5 +264,16 @@ def authenticate(

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

0 comments on commit d8c6a06

Please sign in to comment.