Skip to content

Commit

Permalink
Merge pull request lynndylanhurley#26 from hannahhoward/master
Browse files Browse the repository at this point in the history
Remove OmniAuth dependency
  • Loading branch information
lynndylanhurley committed Sep 11, 2014
2 parents 4e28078 + 17637c5 commit 463ead1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 3 additions & 1 deletion config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@

# mounted routes will point to this
Rails.application.config.after_initialize do
::OmniAuth::config.path_prefix = config.omniauth_path_prefix = DeviseTokenAuth.omniauth_prefix
if defined?(::OmniAuth)
::OmniAuth::config.path_prefix = config.omniauth_path_prefix = DeviseTokenAuth.omniauth_prefix
end
end
end
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Rails.application.routes.draw do
get "#{::OmniAuth::config.path_prefix}/:provider/callback", to: 'devise_token_auth/auth#omniauth_success'
if defined?(::OmniAuth)
get "#{::OmniAuth::config.path_prefix}/:provider/callback", to: 'devise_token_auth/auth#omniauth_success'
end
end
28 changes: 15 additions & 13 deletions lib/devise_token_auth/rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@ def mount_devise_token_auth_for(resource, opts)

devise_scope resource.underscore.to_sym do
get "validate_token", to: "devise_token_auth/auth#validate_token"
get "failure", to: "devise_token_auth/auth#omniauth_failure"
get ":provider/callback", to: "devise_token_auth/auth#omniauth_success"
post ":provider/callback", to: "devise_token_auth/auth#omniauth_success"
if defined?(::OmniAuth)
get "failure", to: "devise_token_auth/auth#omniauth_failure"
get ":provider/callback", to: "devise_token_auth/auth#omniauth_success"
post ":provider/callback", to: "devise_token_auth/auth#omniauth_success"

# preserve the resource class thru oauth authentication by setting name of
# resource as "resource_class" param
match ":provider", to: redirect{|params, request|
# get the current querystring
qs = CGI::parse(request.env["QUERY_STRING"])
# preserve the resource class thru oauth authentication by setting name of
# resource as "resource_class" param
match ":provider", to: redirect{|params, request|
# get the current querystring
qs = CGI::parse(request.env["QUERY_STRING"])

# append name of current resource
qs["resource_class"] = [resource]
# append name of current resource
qs["resource_class"] = [resource]

# re-construct the path for omniauth
"#{::OmniAuth::config.path_prefix}/#{params[:provider]}?#{{}.tap {|hash| qs.each{|k, v| hash[k] = v.first}}.to_param}"
}, via: [:get]
# re-construct the path for omniauth
"#{::OmniAuth::config.path_prefix}/#{params[:provider]}?#{{}.tap {|hash| qs.each{|k, v| hash[k] = v.first}}.to_param}"
}, via: [:get]
end
end
end
end
Expand Down

0 comments on commit 463ead1

Please sign in to comment.