Sha256: 5533fdaf75898b9cfc3dfccb11fc652dadd96c0124364b52868e371d9feb2e97

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

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] }

    ##
    # 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

4 entries across 4 versions & 1 rubygems

Version Path
solidus_jwt-0.1.0 lib/solidus_jwt/preferences.rb
solidus_jwt-0.0.2 lib/solidus_jwt/preferences.rb
solidus_jwt-0.0.1 lib/solidus_jwt/preferences.rb
solidus_jwt-0.0.1.pre lib/solidus_jwt/preferences.rb