jwt_keeper 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/.travis.yml +4 -3
- data/README.md +6 -4
- data/Rakefile +3 -1
- data/example/.gitignore +15 -0
- data/example/Gemfile +15 -0
- data/example/Rakefile +6 -0
- data/example/app/controllers/application_controller.rb +27 -0
- data/example/app/controllers/sessions_controller.rb +52 -0
- data/example/bin/bundle +3 -0
- data/example/bin/rails +9 -0
- data/example/bin/rake +9 -0
- data/example/bin/setup +29 -0
- data/example/bin/spring +15 -0
- data/example/config/application.rb +32 -0
- data/example/config/boot.rb +3 -0
- data/example/config/environment.rb +5 -0
- data/example/config/environments/development.rb +24 -0
- data/example/config/environments/production.rb +63 -0
- data/example/config/environments/test.rb +42 -0
- data/example/config/initializers/backtrace_silencer.rb +1 -0
- data/example/config/initializers/cookies_serializer.rb +3 -0
- data/example/config/initializers/filter_parameter_logging.rb +4 -0
- data/example/config/initializers/jwt_keeper.rb +11 -0
- data/example/config/initializers/session_store.rb +3 -0
- data/example/config/initializers/wrap_parameters.rb +9 -0
- data/example/config/locales/en.yml +23 -0
- data/example/config/routes.rb +3 -0
- data/example/config/secrets.yml +22 -0
- data/example/config.ru +4 -0
- data/example/example.env +1 -0
- data/example/log/.keep +0 -0
- data/lib/generators/{keeper → jwt_keeper}/install/install_generator.rb +1 -1
- data/lib/generators/templates/jwt_keeper.rb +13 -2
- data/lib/jwt_keeper/configuration.rb +13 -1
- data/lib/jwt_keeper/controller.rb +52 -49
- data/lib/jwt_keeper/engine.rb +1 -1
- data/lib/jwt_keeper/token.rb +27 -12
- data/lib/jwt_keeper/version.rb +1 -1
- data/spec/lib/{keeper → jwt_keeper}/configuration_spec.rb +0 -0
- data/spec/lib/{keeper → jwt_keeper}/controller_spec.rb +38 -50
- data/spec/lib/{keeper → jwt_keeper}/datastore_spec.rb +0 -0
- data/spec/lib/{keeper → jwt_keeper}/token_spec.rb +35 -4
- data/spec/lib/jwt_keeper_spec.rb +29 -0
- data/spec/spec_helper.rb +5 -3
- metadata +41 -13
- data/spec/lib/keeper_spec.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82b55239d3d3c73d4308ffe4deae76f9946c5f69
|
4
|
+
data.tar.gz: 524f61adf98731f7c9b8a23d54188c86d433b70e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be39c5cf7875634fb3140d6b76e78bbc46b9c3978799e3e9cf2bc394de49c7f814052e7bdfddad25c5fa1497a84b9de6db89b41ba098207b76f374038b0fa65e
|
7
|
+
data.tar.gz: f8903ede2c42bee6eb3135d14d3b98ee22cf4e1dd8a1e818bd4c6d3be5ad470e5304e50515c59287af1e5194e05718b29a4d7899cceb675c72b9f66e32fad42a
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -8,9 +8,9 @@
|
|
8
8
|
An managing interface layer for handling the creation and validation of JWTs.
|
9
9
|
|
10
10
|
## Setup
|
11
|
-
- Add `gem 'jwt_keeper', '~>
|
11
|
+
- Add `gem 'jwt_keeper', '~> 3.0'` to Gemfile
|
12
12
|
- Run `rails generate keeper:install`
|
13
|
-
- Configure `config/initializers/
|
13
|
+
- Configure `config/initializers/jwt_keeper.rb`
|
14
14
|
- Done
|
15
15
|
|
16
16
|
## Basic Usage
|
@@ -29,8 +29,7 @@ raw_token_string = token.to_jwt
|
|
29
29
|
|
30
30
|
## Rails Usage
|
31
31
|
The designed rails token flow is to receive and respond to requests with the token being present in the `Authorization` part of the header. This is to allow us to seamlessly rotate the tokens on the fly without having to rebuff the request as part of the user flow. Automatic rotation happens as part of the `require_authentication` action, meaning that you will always get the latest token data as
|
32
|
-
created by `generate_claims` in your controllers. This new token is added to the response with
|
33
|
-
the `respond_with_authentication` action.
|
32
|
+
created by `generate_claims` in your controllers. This new token is added to the response with the `respond_with_authentication` action.
|
34
33
|
|
35
34
|
```ruby
|
36
35
|
class ApplicationController < ActionController::Base
|
@@ -81,3 +80,6 @@ Hard Invalidation is a permanent revocation of the token. The primary cases of t
|
|
81
80
|
|
82
81
|
### Soft Invalidation
|
83
82
|
Soft Invalidation is the process of triggering a rotation upon the next time a token is seen in a request. On the global scale this is done when there is a version mismatch in the config. Utilizing the rails controller flow, this method works even if you have two different versions of your app deployed and requests bounce back and forth; Making rolling deployments and rollbacks completely seamless. To rotate a single token, like in the case of a change of user permissions, simply use the class(`Token.rotate`) method to flag the token for regeneration.
|
83
|
+
|
84
|
+
## Cookie Locking
|
85
|
+
Cookie locking is the practice of securing the JWT by pairing it with a secure/httponly cookie. When a JWT is created, part of the secret used to sign it is a one time generated key that is stored in a matching cookie. The cookie and JWT thus must be sent together to be considered valid. The effective result makes it extremely hard to hijack a session by stealing the JWT. This reduces the surface area of XSS considerably.
|
data/Rakefile
CHANGED
data/example/.gitignore
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore all logfiles and tempfiles.
|
11
|
+
/log/*
|
12
|
+
!/log/.keep
|
13
|
+
/tmp
|
14
|
+
|
15
|
+
.env
|
data/example/Gemfile
ADDED
data/example/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
protect_from_forgery with: :exception
|
3
|
+
skip_before_action :verify_authenticity_token
|
4
|
+
|
5
|
+
before_action :default_format_json
|
6
|
+
before_action :require_authentication
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def default_format_json
|
11
|
+
request.format ||= 'json'
|
12
|
+
end
|
13
|
+
|
14
|
+
def not_authenticated
|
15
|
+
respond_to do |format|
|
16
|
+
format.json { head :unauthorized }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def authenticated(decoded_token)
|
21
|
+
@current_user_id = decoded_token.claims[:uid] # Hold off on database calls until necessary
|
22
|
+
end
|
23
|
+
|
24
|
+
def current_user
|
25
|
+
@current_user ||= { id: @current_user_id }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class SessionsController < ApplicationController
|
2
|
+
skip_before_action :require_authentication, only: :create
|
3
|
+
|
4
|
+
# GET /session
|
5
|
+
def show
|
6
|
+
token = read_authentication_token
|
7
|
+
|
8
|
+
respond_to do |format|
|
9
|
+
format.json { render json: token }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# POST /session
|
14
|
+
def create
|
15
|
+
@user = { id: 1 }
|
16
|
+
|
17
|
+
respond_to do |format|
|
18
|
+
if @user
|
19
|
+
write_authentication_token(JWTKeeper::Token.create(uid: @user[:id]))
|
20
|
+
format.json { head :created }
|
21
|
+
else
|
22
|
+
clear_authentication_token
|
23
|
+
format.json { head :unauthorized }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# PATCH/PUT /session
|
29
|
+
def update
|
30
|
+
token = read_authentication_token
|
31
|
+
|
32
|
+
respond_to do |format|
|
33
|
+
if token.rotate
|
34
|
+
write_authentication_token(token)
|
35
|
+
format.json { head :created }
|
36
|
+
else
|
37
|
+
clear_authentication_token
|
38
|
+
format.json { head :unauthorized }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# DELETE /session
|
44
|
+
def destroy
|
45
|
+
read_authentication_token.revoke
|
46
|
+
|
47
|
+
respond_to do |format|
|
48
|
+
clear_authentication_token
|
49
|
+
format.json { head :no_content }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/example/bin/bundle
ADDED
data/example/bin/rails
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
begin
|
3
|
+
load File.expand_path('../spring', __FILE__)
|
4
|
+
rescue LoadError => e
|
5
|
+
raise unless e.message.include?('spring')
|
6
|
+
end
|
7
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
8
|
+
require_relative '../config/boot'
|
9
|
+
require 'rails/commands'
|
data/example/bin/rake
ADDED
data/example/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
# path to your application root.
|
5
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
6
|
+
|
7
|
+
Dir.chdir APP_ROOT do
|
8
|
+
# This script is a starting point to setup your application.
|
9
|
+
# Add necessary setup steps to this file:
|
10
|
+
|
11
|
+
puts '== Installing dependencies =='
|
12
|
+
system 'gem install bundler --conservative'
|
13
|
+
system 'bundle check || bundle install'
|
14
|
+
|
15
|
+
# puts "\n== Copying sample files =="
|
16
|
+
# unless File.exist?("config/database.yml")
|
17
|
+
# system "cp config/database.yml.sample config/database.yml"
|
18
|
+
# end
|
19
|
+
|
20
|
+
puts "\n== Preparing database =="
|
21
|
+
system 'bin/rake db:setup'
|
22
|
+
|
23
|
+
puts "\n== Removing old logs and tempfiles =="
|
24
|
+
system 'rm -f log/*'
|
25
|
+
system 'rm -rf tmp/cache'
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system 'touch tmp/restart.txt'
|
29
|
+
end
|
data/example/bin/spring
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This file loads spring without using Bundler, in order to be fast.
|
4
|
+
# It gets overwritten when you run the `spring binstub` command.
|
5
|
+
|
6
|
+
unless defined?(Spring)
|
7
|
+
require 'rubygems'
|
8
|
+
require 'bundler'
|
9
|
+
|
10
|
+
if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m))
|
11
|
+
Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(Gem.path_separator) }
|
12
|
+
gem 'spring', match[1]
|
13
|
+
require 'spring/binstub'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails'
|
4
|
+
# Pick the frameworks you want:
|
5
|
+
# require "active_model/railtie"
|
6
|
+
# require "active_job/railtie"
|
7
|
+
# require "active_record/railtie"
|
8
|
+
require 'action_controller/railtie'
|
9
|
+
# require "action_mailer/railtie"
|
10
|
+
require 'action_view/railtie'
|
11
|
+
# require "sprockets/railtie"
|
12
|
+
# require "rails/test_unit/railtie"
|
13
|
+
|
14
|
+
# Require the gems listed in Gemfile, including any gems
|
15
|
+
# you've limited to :test, :development, or :production.
|
16
|
+
Bundler.require(*Rails.groups)
|
17
|
+
|
18
|
+
module Example
|
19
|
+
class Application < Rails::Application
|
20
|
+
# Settings in config/environments/* take precedence over those specified here.
|
21
|
+
# Application configuration should go into files in config/initializers
|
22
|
+
# -- all .rb files in that directory are automatically loaded.
|
23
|
+
|
24
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
25
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
26
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
27
|
+
|
28
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
29
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
30
|
+
# config.i18n.default_locale = :de
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Do not eager load code on boot.
|
10
|
+
config.eager_load = false
|
11
|
+
|
12
|
+
# Show full error reports and disable caching.
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send.
|
17
|
+
# config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger.
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Raises error for missing translations
|
23
|
+
# config.action_view.raise_on_missing_translations = true
|
24
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# Code is not reloaded between requests.
|
5
|
+
config.cache_classes = true
|
6
|
+
|
7
|
+
# Eager load code on boot. This eager loads most of Rails and
|
8
|
+
# your application in memory, allowing both threaded web servers
|
9
|
+
# and those relying on copy on write to perform better.
|
10
|
+
# Rake tasks automatically ignore this option for performance.
|
11
|
+
config.eager_load = true
|
12
|
+
|
13
|
+
# Full error reports are disabled and caching is turned on.
|
14
|
+
config.consider_all_requests_local = false
|
15
|
+
config.action_controller.perform_caching = true
|
16
|
+
|
17
|
+
# Enable Rack::Cache to put a simple HTTP cache in front of your application
|
18
|
+
# Add `rack-cache` to your Gemfile before enabling this.
|
19
|
+
# For large-scale production use, consider using a caching reverse proxy like
|
20
|
+
# NGINX, varnish or squid.
|
21
|
+
# config.action_dispatch.rack_cache = true
|
22
|
+
|
23
|
+
# Disable serving static files from the `/public` folder by default since
|
24
|
+
# Apache or NGINX already handles this.
|
25
|
+
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
26
|
+
|
27
|
+
# Specifies the header that your server uses for sending files.
|
28
|
+
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
|
29
|
+
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
|
30
|
+
|
31
|
+
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
32
|
+
# config.force_ssl = true
|
33
|
+
|
34
|
+
# Use the lowest log level to ensure availability of diagnostic information
|
35
|
+
# when problems arise.
|
36
|
+
config.log_level = :debug
|
37
|
+
|
38
|
+
# Prepend all log lines with the following tags.
|
39
|
+
# config.log_tags = [ :subdomain, :uuid ]
|
40
|
+
|
41
|
+
# Use a different logger for distributed setups.
|
42
|
+
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
|
43
|
+
|
44
|
+
# Use a different cache store in production.
|
45
|
+
# config.cache_store = :mem_cache_store
|
46
|
+
|
47
|
+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
|
48
|
+
# config.action_controller.asset_host = 'http://assets.example.com'
|
49
|
+
|
50
|
+
# Ignore bad email addresses and do not raise email delivery errors.
|
51
|
+
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
|
52
|
+
# config.action_mailer.raise_delivery_errors = false
|
53
|
+
|
54
|
+
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
|
55
|
+
# the I18n.default_locale when a translation cannot be found).
|
56
|
+
config.i18n.fallbacks = true
|
57
|
+
|
58
|
+
# Send deprecation notices to registered listeners.
|
59
|
+
config.active_support.deprecation = :notify
|
60
|
+
|
61
|
+
# Use default logging formatter so that PID and timestamp are not suppressed.
|
62
|
+
config.log_formatter = ::Logger::Formatter.new
|
63
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Do not eager load code on boot. This avoids loading your whole application
|
11
|
+
# just for the purpose of running a single test. If you are using a tool that
|
12
|
+
# preloads Rails for running tests, you may have to set it to true.
|
13
|
+
config.eager_load = false
|
14
|
+
|
15
|
+
# Configure static file server for tests with Cache-Control for performance.
|
16
|
+
config.serve_static_files = true
|
17
|
+
config.static_cache_control = 'public, max-age=3600'
|
18
|
+
|
19
|
+
# Show full error reports and disable caching.
|
20
|
+
config.consider_all_requests_local = true
|
21
|
+
config.action_controller.perform_caching = false
|
22
|
+
|
23
|
+
# Raise exceptions instead of rendering exception templates.
|
24
|
+
config.action_dispatch.show_exceptions = false
|
25
|
+
|
26
|
+
# Disable request forgery protection in test environment.
|
27
|
+
config.action_controller.allow_forgery_protection = false
|
28
|
+
|
29
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
30
|
+
# The :test delivery method accumulates sent emails in the
|
31
|
+
# ActionMailer::Base.deliveries array.
|
32
|
+
# config.action_mailer.delivery_method = :test
|
33
|
+
|
34
|
+
# Randomize the order test cases are executed.
|
35
|
+
config.active_support.test_order = :random
|
36
|
+
|
37
|
+
# Print deprecation notices to the stderr.
|
38
|
+
config.active_support.deprecation = :stderr
|
39
|
+
|
40
|
+
# Raises error for missing translations
|
41
|
+
# config.action_view.raise_on_missing_translations = true
|
42
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Rails.backtrace_cleaner.remove_silencers!
|
@@ -0,0 +1,11 @@
|
|
1
|
+
JWTKeeper.configure do |config|
|
2
|
+
config.expiry = 1.hour
|
3
|
+
config.algorithm = 'HS512'
|
4
|
+
config.secret = 'secret'
|
5
|
+
config.issuer = '.localhost'
|
6
|
+
config.audience = 'localhost'
|
7
|
+
config.redis_connection = Redis.new(url: ENV['REDIS_URL'])
|
8
|
+
config.version = 1
|
9
|
+
config.cookie_lock = true
|
10
|
+
config.cookie_secure = !(Rails.env.test? || Rails.env.development?)
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# This file contains settings for ActionController::ParamsWrapper which
|
4
|
+
# is enabled by default.
|
5
|
+
|
6
|
+
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
|
9
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
+
# than English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t 'hello'
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t('hello') %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# To learn more, please read the Rails Internationalization guide
|
20
|
+
# available at http://guides.rubyonrails.org/i18n.html.
|
21
|
+
|
22
|
+
en:
|
23
|
+
hello: "Hello world"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rake secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure the secrets in this file are kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
|
13
|
+
development:
|
14
|
+
secret_key_base: 82e9f5f97a6b624896c35b930acb75d5d5d9df9aa363a21b4173e8a370480ffd7f329a280223a22f03fc07afd2d28c15fae09087eef781506ffea4954e16e12f
|
15
|
+
|
16
|
+
test:
|
17
|
+
secret_key_base: 516e709c30b7198b27d1b2c724e6eaffb13ac2ef0b7d22da67771afdf36f0c6d995e788d12e1da042e739be29d4b2c29ced96d6153f0ad296749570689d9bb4e
|
18
|
+
|
19
|
+
# Do not keep production secrets in the repository,
|
20
|
+
# instead read values from the environment.
|
21
|
+
production:
|
22
|
+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
data/example/config.ru
ADDED
data/example/example.env
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
REDIS_URL=redis://:password@localhost:port
|
data/example/log/.keep
ADDED
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
JWTKeeper.configure do |config|
|
2
2
|
# The time to expire for the tokens
|
3
|
-
# config.expiry =
|
3
|
+
# config.expiry = 1.hour
|
4
4
|
|
5
5
|
# The hashing method to for the tokens
|
6
6
|
# Options:
|
@@ -28,5 +28,16 @@ JWTKeeper.configure do |config|
|
|
28
28
|
# config.redis_connection = Redis.new(connection_options)
|
29
29
|
|
30
30
|
# A unique idenfitier for the token version.
|
31
|
-
# config.version
|
31
|
+
# config.version = 1
|
32
|
+
|
33
|
+
# Use a httponly/secure cookie secret to prevent session hijacking
|
34
|
+
# config.cookie_lock = true
|
35
|
+
|
36
|
+
# Used to turn off TLS only mode on the cookie, for development mode. Defaults to true
|
37
|
+
# config.cookie_secure = !(Rails.env.test? || Rails.env.development?)
|
38
|
+
|
39
|
+
# Used to limit or lock down the allowed domains for the jwt/cookie
|
40
|
+
# http://api.rubyonrails.org/classes/ActionDispatch/Cookies.html
|
41
|
+
# Defaults the value of :all
|
42
|
+
# config.cookie_domain = :all
|
32
43
|
end
|
@@ -7,7 +7,10 @@ module JWTKeeper
|
|
7
7
|
issuer: 'api.example.com',
|
8
8
|
audience: 'example.com',
|
9
9
|
redis_connection: nil,
|
10
|
-
version: nil
|
10
|
+
version: nil,
|
11
|
+
cookie_lock: false,
|
12
|
+
cookie_secure: true,
|
13
|
+
cookie_domain: :all
|
11
14
|
}.freeze
|
12
15
|
|
13
16
|
# Creates a new Configuration from the passed in parameters
|
@@ -26,5 +29,14 @@ module JWTKeeper
|
|
26
29
|
ver: JWTKeeper.configuration.version # Version
|
27
30
|
}
|
28
31
|
end
|
32
|
+
|
33
|
+
# @!visibility private
|
34
|
+
def cookie_options
|
35
|
+
{
|
36
|
+
domain: JWTKeeper.configuration.cookie_domain,
|
37
|
+
secure: JWTKeeper.configuration.cookie_secure,
|
38
|
+
httponly: true
|
39
|
+
}
|
40
|
+
end
|
29
41
|
end
|
30
42
|
end
|