Sha256: 5f9b5d65aafa1efc7e9193205e82bcafd0f1674b5024618274362b9e0d952309

Contents?: true

Size: 1.7 KB

Versions: 23

Compression:

Stored size: 1.7 KB

Contents

# frozen_string_literal: true

require_relative 'request_helper'

module Stytch
  class WebAuthn
    include Stytch::RequestHelper

    PATH = '/v1/webauthn'

    def initialize(connection)
      @connection = connection
    end

    def register_start(
      user_id:,
      domain:,
      user_agent: nil,
      authenticator_type: 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?

      post_request("#{PATH}/register/start", request)
    end

    def register(
      user_id:,
      public_key_credential:
    )
      request = {
        user_id: user_id,
        public_key_credential: public_key_credential
      }

      post_request("#{PATH}/register", request)
    end

    def authenticate_start(
      user_id:,
      domain:
    )
      request = {
        user_id: user_id,
        domain: domain
      }

      post_request("#{PATH}/authenticate/start", request)
    end

    def authenticate(
      public_key_credential:,
      session_token: nil,
      session_jwt: nil,
      session_duration_minutes: nil,
      session_custom_claims: nil
    )
      request = {
        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("#{PATH}/authenticate", request)
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
stytch-5.0.2 lib/stytch/webauthn.rb
stytch-5.0.1 lib/stytch/webauthn.rb
stytch-5.0.0 lib/stytch/webauthn.rb
stytch-4.5.1 lib/stytch/webauthn.rb
stytch-4.5.0 lib/stytch/webauthn.rb
stytch-4.4.0 lib/stytch/webauthn.rb
stytch-4.3.1 lib/stytch/webauthn.rb
stytch-4.3.0 lib/stytch/webauthn.rb
stytch-4.2.0 lib/stytch/webauthn.rb
stytch-4.1.0 lib/stytch/webauthn.rb
stytch-4.0.0 lib/stytch/webauthn.rb
stytch-3.15.0 lib/stytch/webauthn.rb
stytch-3.14.0 lib/stytch/webauthn.rb
stytch-3.13.1 lib/stytch/webauthn.rb
stytch-3.13.0 lib/stytch/webauthn.rb
stytch-3.12.0 lib/stytch/webauthn.rb
stytch-3.11.0 lib/stytch/webauthn.rb
stytch-3.10.0 lib/stytch/webauthn.rb
stytch-3.9.0 lib/stytch/webauthn.rb
stytch-3.8.0 lib/stytch/webauthn.rb