Skip to content

Commit 436e0fa

Browse files
authored
Merge pull request #77 from Amialc/ror_api_dependencies
updated dependencies in ror api example. Fix #75
2 parents 95451a9 + 8e614f7 commit 436e0fa

File tree

4 files changed

+16
-29
lines changed

4 files changed

+16
-29
lines changed

examples/ruby-on-rails-api/Gemfile

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
source 'https://rubygems.org'
22

33
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
4-
gem 'rails', '4.2.5.1'
4+
gem 'rails', '5.0.0.1'
55
# Use sqlite3 as the database for Active Record
66
gem 'sqlite3', groups: [:development, :test]
77

88
gem 'pg'
99
# Use SCSS for stylesheets
10-
gem 'sass-rails', '~> 5.0.4'
10+
gem 'sass-rails', '~> 5.0.6'
1111
# Use Uglifier as compressor for JavaScript assets
12-
gem 'uglifier', '>= 2.7.2'
12+
gem 'uglifier', '>= 3.0.3'
1313
# Use CoffeeScript for .js.coffee assets and views
14-
gem 'coffee-rails', '~> 4.1.1'
14+
gem 'coffee-rails', '~> 4.2.1'
1515
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
1616
# gem 'therubyracer', platforms: :ruby
1717

@@ -20,11 +20,11 @@ gem 'jquery-rails'
2020
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
2121
gem 'turbolinks'
2222
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
23-
gem 'jbuilder', '~> 2.4.1'
23+
gem 'jbuilder', '~> 2.6.0'
2424
# bundle exec rake doc:rails generates the API under doc/api.
25-
gem 'sdoc', '~> 0.4.1', group: :doc
25+
gem 'sdoc', '~> 0.4.2', group: :doc
2626
# knock dependency
27-
gem 'knock', '~> 1.4.2'
27+
gem 'knock', '~> 2.0'
2828

2929
# Dot env
3030
gem 'dotenv-rails', groups: [:development, :test]
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Secured ping Controller
22
class SecuredPingController < ApplicationController
3-
before_action :authenticate
3+
before_action :authenticate_user
44

55
def ping
66
render json: {
77
message: "All good. You only get this message if you're authenticated.",
8-
user: @current_user
8+
user: current_user
99
}
1010
end
1111
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class User < ActiveRecord::Base
2+
def self.from_token_payload payload
3+
payload["sub"]
4+
end
5+
end

examples/ruby-on-rails-api/config/initializers/knock.rb

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
require 'base64'
22
Knock.setup do |config|
3-
## Current user retrieval when validating token
4-
## --------------------------------------------
5-
##
6-
## This is how you can tell Knock how to retrieve the current_user.
7-
## By default, it assumes you have a model called `User` and that
8-
## the user_id is stored in the 'sub' claim.
9-
##
10-
## Default:
11-
# config.current_user_from_token = -> (claims) { User.find claims['sub'] }
12-
13-
# !!!
14-
# This is only to make the example test cases pass, you should use a real
15-
# user model in your app instead.
16-
config.current_user_from_token = -> (claims) { { id: claims['sub'] } }
173

184
## Expiration claim
195
## ----------------
@@ -44,10 +30,6 @@
4430
# config.token_secret_signature_key = -> { Rails.application.secrets.secret_key_base }
4531

4632
## If using Auth0, uncomment the line below
47-
# config.token_secret_signature_key = -> { JWT.base64url_decode Rails.application.secrets.auth0_client_secret }
48-
config.token_secret_signature_key = lambda {
49-
secret = Rails.application.secrets.auth0_client_secret
50-
secret += '=' * (4 - secret.length.modulo(4))
51-
Base64.decode64(secret.tr('-_', '+/'))
52-
}
33+
config.token_secret_signature_key = -> { JWT.base64url_decode Rails.application.secrets.auth0_client_secret }
34+
5335
end

0 commit comments

Comments
 (0)