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

Add config to not create new clients on standard Devise requests #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module DeviseTokenAuth::Concerns::SetUserByToken
def set_request_start
@request_started_at = Time.zone.now
@used_auth_by_token = true
@standard_devise_dont_create_new_client = false

# initialize instance variables
@token ||= DeviseTokenAuth::TokenFactory.new
Expand Down Expand Up @@ -58,6 +59,7 @@ def set_user_by_token(mapping = nil)
devise_warden_user = warden.user(mapping)
if devise_warden_user && devise_warden_user.tokens[@token.client].nil?
@used_auth_by_token = false
@standard_devise_dont_create_new_client = true
@resource = devise_warden_user
# REVIEW: The following line _should_ be safe to remove;
# the generated token does not get used anywhere.
Expand Down Expand Up @@ -94,6 +96,10 @@ def set_user_by_token(mapping = nil)
end

def update_auth_header
if DeviseTokenAuth.standard_devise_dont_create_new_client && @standard_devise_dont_create_new_client
return
end

# cannot save object if model has invalid params
return unless @resource && @token.client

Expand Down
2 changes: 2 additions & 0 deletions lib/devise_token_auth/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Engine < ::Rails::Engine
:redirect_whitelist,
:check_current_password_before_update,
:enable_standard_devise_support,
:standard_devise_dont_create_new_client,
:remove_tokens_after_password_reset,
:default_callbacks,
:headers_names,
Expand All @@ -43,6 +44,7 @@ class Engine < ::Rails::Engine
self.redirect_whitelist = nil
self.check_current_password_before_update = false
self.enable_standard_devise_support = false
self.standard_devise_dont_create_new_client = false
self.remove_tokens_after_password_reset = false
self.default_callbacks = true
self.headers_names = { 'access-token': 'access-token',
Expand Down