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

WIP: Remove use of warden and use omniauth-github in preparation for supporting GitLab #157

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ gem 'dotenv-rails', '~> 2.0.0', :require => 'dotenv/rails-now'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'omniauth-oauth2'
gem 'omniauth-github'
# gem 'therubyracer', platforms: :ruby
gem "ember-cli-rails", '0.1.13', require: nil
gem 'ember-rails-assets'
#gem "warden-github-rails" , github: "huboard/warden-github-rails"
gem 'warden-github'
# TODO: replace this
gem 'sinatra_auth_github'
gem 'rails_12factor', group: :production
Expand Down
26 changes: 21 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ PATH
remote: vendor/engines/saas
specs:
saas (0.0.1)
analytics-ruby
rails (~> 4.2.0)

PATH
remote: vendor/gems/faye_extensions
specs:
faye_extensions (0.0.1)
rails (~> 4.2.0)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -51,7 +48,6 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.3.7)
analytics-ruby (2.0.13)
annotate (2.6.8)
activerecord (>= 3.2, <= 4.3)
rake (~> 10.4)
Expand Down Expand Up @@ -258,6 +254,7 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.3)
jwt (1.5.2)
kgio (2.9.3)
loofah (2.0.1)
nokogiri (>= 1.5.9)
Expand All @@ -284,8 +281,23 @@ GEM
netrc (0.10.3)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
oauth2 (1.0.0)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
octokit (3.8.0)
sawyer (~> 0.6.0, >= 0.5.3)
omniauth (1.2.2)
hashie (>= 1.2, < 4)
rack (~> 1.0)
omniauth-github (1.1.2)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.1)
omniauth-oauth2 (1.4.0)
oauth2 (~> 1.0)
omniauth (~> 1.2)
pdfkit (0.6.2)
private_pub (1.0.3)
faye
Expand Down Expand Up @@ -469,6 +481,8 @@ DEPENDENCIES
memcachier
meta_request
mocha
omniauth-github
omniauth-oauth2
pdfkit
private_pub (= 1.0.3)
pry-byebug
Expand All @@ -492,5 +506,7 @@ DEPENDENCIES
stripe-rails
sucker_punch
uglifier (>= 1.3.0)
warden-github
wkhtmltopdf-heroku

BUNDLED WITH
1.11.0
6 changes: 5 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ApplicationController < ActionController::Base

protected
def ghee_unauthorized
request.env['warden'].logout
omniauth_logout
respond_to do |format|
format.json { render json: {error: 'GitHub token is expired'}, status: 422}
format.html { redirect_to '/login' }
Expand Down Expand Up @@ -49,4 +49,8 @@ def queue_job
def not_found
raise ActionController::RoutingError.new 'Not found'
end

def omniauth_logout
request.env['omniauth.auth'] = nil
end
end
2 changes: 1 addition & 1 deletion app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def private
end
:protected
def login
request.env['warden'].logout if github_authenticated? :default
omniauth_logout if github_authenticated? :default
github_authenticate! :private
end

Expand Down
8 changes: 3 additions & 5 deletions app/controllers/login_controller.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
class LoginController < ApplicationController
layout false
def logout
request.env['warden'].logout
omniauth_logout
redirect_to "/"
end
def public
request.env['warden'].logout if github_authenticated? :private
omniauth_logout if github_authenticated? :private
github_authenticate! :default
redirect_to params[:redirect_to] || "/"
end
def private
request.env['warden'].logout if github_authenticated? :default
omniauth_logout if github_authenticated? :default
github_authenticate! :private
redirect_to params[:redirect_to] || "/"
end
end
10 changes: 5 additions & 5 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ def couch
# Initiates the OAuth flow if not already authenticated for the
# # specified scope.
def github_authenticate!(scope=:default)
request.env['warden'].authenticate!(scope: scope)
redirect_to '/auth/github'
end

# Logs out a user if currently logged in for the specified scope.
def github_logout(scope=:default)
request.env['warden'].logout(scope)
request.env['omniauth.auth'] = nil
end
def github_authenticated?(scope=:default)
request.env['warden'].authenticated?(scope)
request.env['omniauth.auth'].present? && request.env['omniauth.auth'].try('provider') == 'github'
end

def github_user(scope=:default)
request.env['warden'].user(scope)
request.env['omniauth.auth'].try('info').try('user')
end
def github_session(scope=:default)
request.env['warden'].session(scope) if github_authenticated?(scope)
raise NotImplemented
end
def is_collaborator?(repo)
repo['permissions'] && repo['permissions']['push'] && logged_in?
Expand Down
3 changes: 3 additions & 0 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Rails.application.config.middleware.use OmniAuth::Builder do
provider :github, ENV['GITHUB_CLIENT_ID'], ENV['GITHUB_SECRET']
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
get 'login/public' => 'login#public'
get 'login/private' => 'login#private'

match 'auth/:provider/callback' => 'dashboard#index', via: [:get, :post]

get '/repositories/private/:user' => 'dashboard#private', as: 'repositories_private'

get '/repositories/public/:user' => 'dashboard#public', as: 'repositories_public'
Expand Down