Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 28ffe4f

Browse files
author
Bill Heaton
committed
Gem updates, fixup controller before filter method call for auth
1 parent 4fc0ac8 commit 28ffe4f

7 files changed

Lines changed: 14 additions & 17 deletions

File tree

Gemfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GIT
22
remote: https://github.com/cerebris/jsonapi-resources.git
3-
revision: dee9666240ad8e9205a35987fff85ccab8153770
3+
revision: e385293a7b5bbf5a483a4bef9bf7f78dc174c49f
44
specs:
55
jsonapi-resources (0.3.3)
66
rails (>= 4.0)
@@ -46,7 +46,7 @@ GEM
4646
arel (6.0.0)
4747
bcrypt (3.1.10)
4848
builder (3.2.2)
49-
byebug (4.0.5)
49+
byebug (5.0.0)
5050
columnize (= 0.9.0)
5151
capistrano (3.4.0)
5252
i18n
@@ -74,15 +74,15 @@ GEM
7474
nokogiri (>= 1.5.9)
7575
mail (2.6.3)
7676
mime-types (>= 1.16, < 3)
77-
mime-types (2.5)
77+
mime-types (2.6.1)
7878
mini_portile (0.6.2)
79-
minitest (5.6.1)
79+
minitest (5.7.0)
8080
net-scp (1.2.1)
8181
net-ssh (>= 2.6.5)
8282
net-ssh (2.9.2)
8383
nokogiri (1.6.6.2)
8484
mini_portile (~> 0.6.0)
85-
pg (0.18.1)
85+
pg (0.18.2)
8686
rack (1.6.1)
8787
rack-test (0.6.3)
8888
rack (>= 1.0)
@@ -134,7 +134,7 @@ GEM
134134
spring (1.3.6)
135135
sprockets (3.1.0)
136136
rack (~> 1.0)
137-
sprockets-rails (2.3.0)
137+
sprockets-rails (2.3.1)
138138
actionpack (>= 3.0)
139139
activesupport (>= 3.0)
140140
sprockets (>= 2.8, < 4.0)

app/controllers/api/auth_controller.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
class Api::AuthController < ApplicationController
2-
32
skip_before_action :authenticate_request
43

54
def authenticate
@@ -19,7 +18,6 @@ def authenticate_commenter
1918
end
2019
if commenter.present?
2120
@current_user = commenter
22-
render json: { auth_token: commenter.generate_auth_token }
2321
render json: { auth_token: commenter.generate_auth_token, commenter_id: commenter.id }
2422
else
2523
render json: { error: 'Invalid name or email' }, status: :unauthorized

app/controllers/api/v1/authors_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Api::V1::AuthorsController < ApiControllerController
2-
skip_before_action :set_current_user, :authenticate_request, only: [:index, :show, :show_association, :get_related_resource]
2+
skip_before_action :authenticate_request, only: [:index, :show, :show_association, :get_related_resource]
33

44
private
55
def author_params

app/controllers/api/v1/commenters_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Api::V1::CommentersController < ApiControllerController
2-
skip_before_action :set_current_user, :authenticate_request, only: [:index, :show, :show_association, :get_related_resource]
2+
skip_before_action :authenticate_request, only: [:index, :show, :show_association, :get_related_resource]
33

44
private
55

app/controllers/api/v1/comments_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
class Api::V1::CommentsController < ApiControllerController
2-
skip_before_action :set_current_user, :authenticate_request, only: [:index, :show, :show_association, :get_related_resources]
3-
before_action :set_current_user
2+
skip_before_action :authenticate_request, only: [:index, :show, :show_association, :get_related_resources]
43

54
def current_user
65
@current_user
@@ -19,7 +18,6 @@ def set_current_user
1918
elsif decoded_auth_token.has_key? :user_id
2019
@current_user = User.find(decoded_auth_token[:user_id])
2120
end
22-
nil
2321
end
2422
end
2523

app/controllers/api/v1/posts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Api::V1::PostsController < ApiControllerController
2-
skip_before_action :set_current_user, :authenticate_request, only: [:index, :show, :show_association, :get_related_resources]
2+
skip_before_action :authenticate_request, only: [:index, :show, :show_association, :get_related_resources]
33

44
def index
55
sort_criteria = @request.sort_criteria

app/controllers/api_controller_controller.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'jsonapi/resource_controller'
22

33
class ApiControllerController < JSONAPI::ResourceController
4-
before_action :set_current_user, :authenticate_request
4+
before_action :authenticate_request
55

66
rescue_from NotAuthenticatedError do
77
render json: { error: 'Not Authorized' }, status: :unauthorized
@@ -25,6 +25,7 @@ def set_current_user
2525

2626
# Check to make sure the current user was set and the token is not expired
2727
def authenticate_request
28+
set_current_user
2829
if auth_token_expired?
2930
fail AuthenticationTimeoutError
3031
elsif !@current_user
@@ -45,8 +46,8 @@ def auth_token_expired?
4546
def http_auth_header_content
4647
return @http_auth_header_content if defined? @http_auth_header_content
4748
@http_auth_header_content = begin
48-
if request.headers['Authorization'].present?
49-
request.headers['Authorization'].split(' ').last
49+
if request.headers['HTTP_AUTHORIZATION'].present?
50+
request.headers['HTTP_AUTHORIZATION'].split(' ').last
5051
else
5152
nil
5253
end

0 commit comments

Comments
 (0)