Sha256: 7d7b6d9e344f64352270ed87def324fe51ec9322110cedc884b58317c1871607

Contents?: true

Size: 1.79 KB

Versions: 4

Compression:

Stored size: 1.79 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] }

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

4 entries across 4 versions & 1 rubygems

Version Path
solidus_jwt-1.1.0 lib/solidus_jwt/preferences.rb
solidus_jwt-1.0.0 lib/solidus_jwt/preferences.rb
solidus_jwt-1.0.0.beta2 lib/solidus_jwt/preferences.rb
solidus_jwt-1.0.0.beta1 lib/solidus_jwt/preferences.rb