-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replicate the bug disscussed in Sorcery/sorcery#6.
- Loading branch information
1 parent
e39ec2f
commit 7d08e40
Showing
13 changed files
with
99 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the Oauths controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class OauthsController < ApplicationController | ||
skip_before_filter :require_login | ||
|
||
# sends the user on a trip to the provider, | ||
# and after authorizing there back to the callback url. | ||
def oauth | ||
login_at(params[:provider]) | ||
end | ||
|
||
def callback | ||
provider = params[:provider] | ||
if @user = login_from(provider) | ||
redirect_to root_path, :notice => "Logged in from #{provider.titleize}!" | ||
else | ||
begin | ||
@user = create_from(provider) | ||
# NOTE: this is the place to add '@user.activate!' if you are using user_activation submodule | ||
|
||
reset_session # protect from session fixation attack | ||
auto_login(@user) | ||
redirect_to root_path, :notice => "Logged in from #{provider.titleize}!" | ||
rescue | ||
redirect_to root_path, :alert => "Failed to login from #{provider.titleize}!" | ||
end | ||
end | ||
end | ||
|
||
#example for Rails 4: add private method below and use "auth_params[:provider]" in place of | ||
#"params[:provider] above. | ||
|
||
private | ||
def auth_params | ||
params.permit(:code, :provider) | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module OauthsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Authentication < ActiveRecord::Base | ||
belongs_to :user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Oauths#callback</h1> | ||
<p>Find me in app/views/oauths/callback.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Oauths#oauth</h1> | ||
<p>Find me in app/views/oauths/oauth.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,18 @@ | ||
Rails.application.routes.draw do | ||
get 'oauths/oauth' | ||
|
||
get 'oauths/callback' | ||
|
||
root :to => 'users#index' | ||
resources :user_sessions | ||
resources :users | ||
|
||
get 'login' => 'user_sessions#new', :as => :login | ||
post 'logout' => 'user_sessions#destroy', :as => :logout | ||
# The priority is based upon order of creation: first created -> highest priority. | ||
# See how all your routes lay out with "rake routes". | ||
|
||
# You can have the root of your site routed with "root" | ||
# root 'welcome#index' | ||
|
||
# Example of regular route: | ||
# get 'products/:id' => 'catalog#view' | ||
|
||
# Example of named route that can be invoked with purchase_url(id: product.id) | ||
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase | ||
|
||
# Example resource route (maps HTTP verbs to controller actions automatically): | ||
# resources :products | ||
|
||
# Example resource route with options: | ||
# resources :products do | ||
# member do | ||
# get 'short' | ||
# post 'toggle' | ||
# end | ||
# | ||
# collection do | ||
# get 'sold' | ||
# end | ||
# end | ||
|
||
# Example resource route with sub-resources: | ||
# resources :products do | ||
# resources :comments, :sales | ||
# resource :seller | ||
# end | ||
|
||
# Example resource route with more complex sub-resources: | ||
# resources :products do | ||
# resources :comments | ||
# resources :sales do | ||
# get 'recent', on: :collection | ||
# end | ||
# end | ||
|
||
# Example resource route with concerns: | ||
# concern :toggleable do | ||
# post 'toggle' | ||
# end | ||
# resources :posts, concerns: :toggleable | ||
# resources :photos, concerns: :toggleable | ||
|
||
# Example resource route within a namespace: | ||
# namespace :admin do | ||
# # Directs /admin/products/* to Admin::ProductsController | ||
# # (app/controllers/admin/products_controller.rb) | ||
# resources :products | ||
# end | ||
# For external login (Now supports only twitter). | ||
post "oauth/callback" => "oauths#callback" | ||
get "oauth/callback" => "oauths#callback" | ||
get "oauth/:provider" => "oauths#oauth", :as => :auth_at_provider | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class SorceryExternal < ActiveRecord::Migration | ||
def change | ||
create_table :authentications do |t| | ||
t.integer :user_id, :null => false | ||
t.string :provider, :uid, :null => false | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :authentications, [:provider, :uid] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters