From e3e32365d0aa7a0da95df79ddb1f298dccc27ef1 Mon Sep 17 00:00:00 2001 From: bruckwubete Date: Fri, 29 Jun 2018 10:07:06 -0400 Subject: [PATCH] able to handle launcher login --- .gitignore | 4 +++ Dockerfile | 1 + Gemfile | 3 ++- Gemfile.lock | 28 +++++++++++++++----- app/controllers/application_controller.rb | 1 + app/controllers/main_controller.rb | 8 ++++++ app/models/user.rb | 16 ++++++++++++ config/application.rb | 31 ++++++++--------------- config/initializers/omniauth.rb | 6 ++++- 9 files changed, 69 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 51f1d350..d4eff4a2 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,7 @@ # Ignore environment configuration. .env + +# IDEs +.idea +.idea/** diff --git a/Dockerfile b/Dockerfile index 1155f08e..1d3cc9dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs # Set an environment variable for the install location. ENV RAILS_ROOT /usr/src/app +RUN bundle config github.com 0e54e86c4228294d867a0831bff53f95a31d4af2:x-oauth-basic # Make the directory and set as working. RUN mkdir -p $RAILS_ROOT diff --git a/Gemfile b/Gemfile index 97df7455..95d85691 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,7 @@ gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.2' # See https://github.com/rails/execjs#readme for more supported runtimes -# gem 'therubyracer', platforms: :ruby +gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' @@ -47,6 +47,7 @@ gem 'bcrypt', '~> 3.1.7' gem 'omniauth' gem 'omniauth-twitter' gem 'omniauth-google-oauth2' +gem "omniauth-bn-launcher", git: "https://github.com/blindsidenetworks/omniauth-bn-launcher.git" # BigBlueButton API wrapper. gem 'bigbluebutton-api-ruby' diff --git a/Gemfile.lock b/Gemfile.lock index fe663602..14e4fa5b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,10 @@ +GIT + remote: https://github.com/blindsidenetworks/omniauth-bn-launcher.git + revision: 52fbc3ff40c64ad5eef51f7e6c0beba2c666356f + specs: + omniauth-bn-launcher (0.1.0) + omniauth (~> 1.3, >= 1.3.2) + GEM remote: https://rubygems.org/ specs: @@ -42,7 +49,7 @@ GEM tzinfo (~> 1.1) arel (7.1.4) ast (2.4.0) - autoprefixer-rails (8.6.2) + autoprefixer-rails (8.6.4) execjs bcrypt (3.1.12) bigbluebutton-api-ruby (1.6.0) @@ -64,9 +71,9 @@ GEM concurrent-ruby (1.0.5) crass (1.0.4) diff-lcs (1.3) - dotenv (2.4.0) - dotenv-rails (2.4.0) - dotenv (= 2.4.0) + dotenv (2.5.0) + dotenv-rails (2.5.0) + dotenv (= 2.5.0) railties (>= 3.2, < 6.0) erubis (2.7.0) execjs (2.7.0) @@ -94,6 +101,7 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) jwt (1.5.6) + libv8 (3.16.14.19) listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -110,7 +118,7 @@ GEM multi_xml (0.6.0) multipart-post (2.0.0) nio4r (2.3.1) - nokogiri (1.8.2) + nokogiri (1.8.3) mini_portile2 (~> 2.3.0) oauth (0.5.4) oauth2 (1.4.0) @@ -178,6 +186,7 @@ GEM rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) redis (3.3.5) + ref (2.0.0) rspec-core (3.7.1) rspec-support (~> 3.7.0) rspec-expectations (3.7.0) @@ -222,7 +231,7 @@ GEM spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) - sprockets (3.7.1) + sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.1) @@ -232,6 +241,9 @@ GEM sqlite3 (1.3.13) tabler-rubygem (0.1.2) autoprefixer-rails (>= 6.0.3) + therubyracer (0.12.3) + libv8 (~> 3.16.14.15) + ref thor (0.20.0) thread_safe (0.3.6) tilt (2.0.8) @@ -240,7 +252,7 @@ GEM turbolinks-source (5.1.0) tzinfo (1.2.5) thread_safe (~> 0.1) - uglifier (4.1.11) + uglifier (4.1.12) execjs (>= 0.3.0, < 3) unicode-display_width (1.4.0) web-console (3.6.2) @@ -270,6 +282,7 @@ DEPENDENCIES jquery-rails listen (~> 3.0.5) omniauth + omniauth-bn-launcher! omniauth-google-oauth2 omniauth-twitter pg (~> 0.18) @@ -285,6 +298,7 @@ DEPENDENCIES spring-watcher-listen (~> 2.0.0) sqlite3 tabler-rubygem + therubyracer turbolinks (~> 5) tzinfo-data uglifier (>= 1.3.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0f07f83b..1b90905b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base include SessionsHelper protect_from_forgery with: :exception + skip_before_filter :verify_authenticity_token MEETING_NAME_LIMIT = 90 USER_NAME_LIMIT = 30 diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index b7f7ff97..9bdb2e59 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -5,6 +5,14 @@ class MainController < ApplicationController # GET / def index + if current_user + # Redirect authenticated users to their room. + redirect_to room_path(current_user.room) + else + # Redirect unauthenticated users to root. + #TODO use env? for launcher login endpoint + redirect_to "#{Rails.configuration.relative_url_root}/auth/bn_launcher" + end end private diff --git a/app/models/user.rb b/app/models/user.rb index a89becb2..b45fe32a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -65,6 +65,22 @@ class User < ApplicationRecord def google_image(auth) auth['info']['image'] end + + def bn_launcher_name(auth) + auth['user_info']['username'] + end + + def bn_launcher_username(auth) + auth['user_info']['username'] + end + + def bn_launcher_email(auth) + auth['user_info']['email'] + end + + def bn_launcher_image(auth) + "" + end end # Retrives a list of all a users rooms that are not the main room, sorted by last session date. diff --git a/config/application.rb b/config/application.rb index ae323d4d..a7548614 100644 --- a/config/application.rb +++ b/config/application.rb @@ -19,29 +19,20 @@ module Greenlight config.loadbalanced_configuration = (ENV["USE_LOADBALANCED_CONFIGURATION"] == "true") - # Setup BigBlueButton configuration. - if config.loadbalanced_configuration - # Fetch credentials from a loadbalancer based on provider. - config.loadbalancer_endpoint = ENV["LOADBALANCER_ENDPOINT"] - config.loadbalancer_secret = ENV["LOADBALANCER_SECRET"] - else - # Default credentials (test-install.blindsidenetworks.com/bigbluebutton). - config.bigbluebutton_endpoint_default = "http://test-install.blindsidenetworks.com/bigbluebutton/api/" - config.bigbluebutton_secret_default = "8cd8ef52e8e101574e400365b55e11a6" - # Use standalone BigBlueButton server. - config.bigbluebutton_endpoint = ENV["BIGBLUEBUTTON_ENDPOINT"] - config.bigbluebutton_secret = ENV["BIGBLUEBUTTON_SECRET"] + # Default credentials (test-install.blindsidenetworks.com/bigbluebutton). + config.bigbluebutton_endpoint_default = "http://test-install.blindsidenetworks.com/bigbluebutton/api" + config.bigbluebutton_secret_default = "8cd8ef52e8e101574e400365b55e11a6" - # Fallback to testing credentails. - if config.bigbluebutton_endpoint.blank? - config.bigbluebutton_endpoint = config.bigbluebutton_endpoint_default - config.bigbluebutton_secret = config.bigbluebutton_secret_default - end - # Fix endpoint format if required. - config.bigbluebutton_endpoint += "api/" unless config.bigbluebutton_endpoint.ends_with?('api/') - end + # Fetch credentials from a loadbalancer based on provider. + config.loadbalancer_endpoint = ENV["LOADBALANCER_ENDPOINT"] + config.loadbalancer_secret = ENV["LOADBALANCER_SECRET"] + + # Use standalone BigBlueButton server. + config.bigbluebutton_endpoint = ENV["BIGBLUEBUTTON_ENDPOINT"] || config.bigbluebutton_endpoint_default + config.bigbluebutton_endpoint += "api" unless config.bigbluebutton_endpoint.ends_with?('api') + config.bigbluebutton_secret = ENV["BIGBLUEBUTTON_SECRET"] || config.bigbluebutton_secret_default # Determine if GreenLight should allow non-omniauth signup/login. config.allow_user_signup = (ENV['ALLOW_GREENLIGHT_ACCOUNTS'] == "true") diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 16f154ad..9b0ff26e 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,14 +1,18 @@ # frozen_string_literal: true # List of supported Omniauth providers. -Rails.application.config.providers = [:google, :twitter] +Rails.application.config.providers = [:google, :twitter, :bn_launcher] # Set which providers are configured. Rails.application.config.omniauth_google = ENV['GOOGLE_OAUTH2_ID'].present? && ENV['GOOGLE_OAUTH2_SECRET'].present? Rails.application.config.omniauth_twitter = ENV['TWITTER_ID'].present? && ENV['TWITTER_SECRET'].present? +Rails.application.config.omniauth_bn_launcher = (ENV["USE_LOADBALANCED_CONFIGURATION"] == "true") # Setup the Omniauth middleware. Rails.application.config.middleware.use OmniAuth::Builder do + + provider :bn_launcher, ENV['LAUNCHER_SECRET'], (ENV['LAUNCHER_RELATIVE_URL_ROOT'] || '' + '/login') + provider :twitter, ENV['TWITTER_ID'], ENV['TWITTER_SECRET'] provider :google_oauth2, ENV['GOOGLE_OAUTH2_ID'], ENV['GOOGLE_OAUTH2_SECRET'],