Sha256: 73e52cce8d6fe65dd562b4e4cee5d434361d5e7e765d430ae2ea13acc8672e0d

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require 'spree/preferences/configuration'

module SolidusJwt
  class Preferences < Spree::Preferences::Configuration
    ##
    # Provide your own secret when creating json web tokens
    # @attr_writer jwt_secret [String] The secret to encrypt web tokens with.
    #
    attr_writer :jwt_secret

    ##
    # @!attribute [rw] allow_spree_api_key
    #   @return [String] Allow spree_api_key to still be used. (default true)
    #
    preference :allow_spree_api_key, :boolean, default: true

    ##
    # @see https://github.com/jwt/ruby-jwt#algorithms-and-usage
    # @!attribute [rw] jwt_algorithm
    #   @return [String] The hashing algorithm to use. (default 'HS256')
    #
    preference :jwt_algorithm, :string, default: 'HS256'

    # @!attribute [rw] jwt_expiration
    #   @return [String] How long until the token expires in seconds.
    #   (default: +3600+)
    #
    preference :jwt_expiration, :integer, default: 3600

    # @see https://github.com/jwt/ruby-jwt#algorithms-and-usage
    # @!attribute [rw] jwt_options
    #   @return [String] The options to pass into `Spree::User#as_json` when
    #   when creating the jwt payload. (default: `{ only: %i[email first_name id last_name] }`)
    #
    preference :jwt_options, :hash, default: { only: %i[email first_name id last_name] }

    # @!attribute [rw] refresh_expriation
    #   @return [String] How long until the refresh token expires in seconds
    #   (default: +2592000+)
    #
    preference :refresh_expiration, :integer, default: 2_592_000

    ##
    # Get the secret token to encrypt json web tokens with.
    # @return [String] The secret used to encrypt json web tokens
    #
    #
    def jwt_secret
      # Account for different rails versions
      @jwt_secret ||= ENV['SECRET_KEY_BASE'] || Rails.application.secret_key_base
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_jwt-1.2.2 lib/solidus_jwt/preferences.rb
solidus_jwt-1.2.1 lib/solidus_jwt/preferences.rb
solidus_jwt-1.2.0 lib/solidus_jwt/preferences.rb