Skip to content

Commit

Permalink
do not use devise strategy for api auth
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Dec 25, 2023
1 parent 64c8707 commit 94a13ff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
11 changes: 11 additions & 0 deletions app/controllers/api/api_base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ def paginate(relation)
result
end

def authenticate_user!
@current_user ||=
if request.headers['X-Auth-Token'].present?
sha256 = Digest::SHA256.hexdigest(request.headers['X-Auth-Token'])

User.joins(:access_token).find_by(access_token: { sha256: })
end

render json: { error: 'Not authenticated' }, status: :unauthorized unless current_user
end

def current_account
current_user&.account
end
Expand Down
6 changes: 1 addition & 5 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# frozen_string_literal: true

require_relative '../../lib/auth_with_token_strategy'

Warden::Strategies.add(:auth_token, AuthWithTokenStrategy)

Devise.otp_allowed_drift = 60.seconds

# Assuming you have not yet modified this file, each configuration option below
Expand Down Expand Up @@ -279,7 +275,7 @@
#
config.warden do |manager|
# manager.intercept_401 = false
manager.default_strategies(scope: :user).unshift(:auth_token)
# manager.default_strategies(scope: :user).unshift(:auth_token)
end

# ==> Mountable engine configurations
Expand Down
19 changes: 0 additions & 19 deletions lib/auth_with_token_strategy.rb

This file was deleted.

0 comments on commit 94a13ff

Please sign in to comment.