Sha256: fb551d838c2bc233a35b034200d82c18720b2c7e3fcdddf94a186167982b6a40

Contents?: true

Size: 1.93 KB

Versions: 23

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

require_relative 'request_helper'

module Stytch
  class TOTPs
    include Stytch::RequestHelper

    PATH = '/v1/totps'

    def initialize(connection)
      @connection = connection
    end

    def create(
      user_id:,
      expiration_minutes: nil
    )
      request = {
        user_id: user_id
      }

      request[:expiration_minutes] = expiration_minutes unless expiration_minutes.nil?

      post_request(PATH, request)
    end

    def authenticate(
      user_id:,
      totp_code:,
      session_token: nil,
      session_jwt: nil,
      session_duration_minutes: nil,
      session_custom_claims: nil
    )
      request = {
        user_id: user_id,
        totp_code: totp_code
      }

      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

    def recovery_codes(
      user_id:
    )
      request = {
        user_id: user_id
      }

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

    def recover(
      user_id:,
      recovery_code:,
      session_token: nil,
      session_jwt: nil,
      session_duration_minutes: nil,
      session_custom_claims: nil
    )
      request = {
        user_id: user_id,
        recovery_code: recovery_code
      }

      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}/recover", request)
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

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