Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated dependencies in ror api example. Fix #75 #77

Merged
merged 1 commit into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions examples/ruby-on-rails-api/Gemfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5.1'
gem 'rails', '5.0.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', groups: [:development, :test]

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

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

# Dot env
gem 'dotenv-rails', groups: [:development, :test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Secured ping Controller
class SecuredPingController < ApplicationController
before_action :authenticate
before_action :authenticate_user

def ping
render json: {
message: "All good. You only get this message if you're authenticated.",
user: @current_user
user: current_user
}
end
end
5 changes: 5 additions & 0 deletions examples/ruby-on-rails-api/app/models/User.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class User < ActiveRecord::Base
def self.from_token_payload payload
payload["sub"]
end
end
22 changes: 2 additions & 20 deletions examples/ruby-on-rails-api/config/initializers/knock.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
require 'base64'
Knock.setup do |config|
## Current user retrieval when validating token
## --------------------------------------------
##
## This is how you can tell Knock how to retrieve the current_user.
## By default, it assumes you have a model called `User` and that
## the user_id is stored in the 'sub' claim.
##
## Default:
# config.current_user_from_token = -> (claims) { User.find claims['sub'] }

# !!!
# This is only to make the example test cases pass, you should use a real
# user model in your app instead.
config.current_user_from_token = -> (claims) { { id: claims['sub'] } }

## Expiration claim
## ----------------
Expand Down Expand Up @@ -44,10 +30,6 @@
# config.token_secret_signature_key = -> { Rails.application.secrets.secret_key_base }

## If using Auth0, uncomment the line below
# config.token_secret_signature_key = -> { JWT.base64url_decode Rails.application.secrets.auth0_client_secret }
config.token_secret_signature_key = lambda {
secret = Rails.application.secrets.auth0_client_secret
secret += '=' * (4 - secret.length.modulo(4))
Base64.decode64(secret.tr('-_', '+/'))
}
config.token_secret_signature_key = -> { JWT.base64url_decode Rails.application.secrets.auth0_client_secret }

end