diff --git a/Gemfile b/Gemfile index 7970b237..2c46197f 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 2de943aa..4c518926 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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/ @@ -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) @@ -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) @@ -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 @@ -469,6 +481,8 @@ DEPENDENCIES memcachier meta_request mocha + omniauth-github + omniauth-oauth2 pdfkit private_pub (= 1.0.3) pry-byebug @@ -492,5 +506,7 @@ DEPENDENCIES stripe-rails sucker_punch uglifier (>= 1.3.0) - warden-github wkhtmltopdf-heroku + +BUNDLED WITH + 1.11.0 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fb92c82e..ec422c15 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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' } @@ -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 diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 80033467..598243bf 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -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 diff --git a/app/controllers/login_controller.rb b/app/controllers/login_controller.rb index c47c3555..7626fc2b 100644 --- a/app/controllers/login_controller.rb +++ b/app/controllers/login_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8d75f3c8..2397010f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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? diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb new file mode 100644 index 00000000..c7cc6903 --- /dev/null +++ b/config/initializers/omniauth.rb @@ -0,0 +1,3 @@ +Rails.application.config.middleware.use OmniAuth::Builder do + provider :github, ENV['GITHUB_CLIENT_ID'], ENV['GITHUB_SECRET'] +end diff --git a/config/routes.rb b/config/routes.rb index 58ce4841..e9586b26 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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'