forked from External/greenlight
omniauth strategy
This commit is contained in:
parent
c32b48213a
commit
0d73a77f1f
2
Gemfile
2
Gemfile
|
@ -47,5 +47,5 @@ end
|
||||||
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
||||||
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
||||||
|
|
||||||
|
gem 'omniauth'
|
||||||
gem 'bigbluebutton-api-ruby'
|
gem 'bigbluebutton-api-ruby'
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ GEM
|
||||||
ffi (1.9.14)
|
ffi (1.9.14)
|
||||||
globalid (0.3.7)
|
globalid (0.3.7)
|
||||||
activesupport (>= 4.1.0)
|
activesupport (>= 4.1.0)
|
||||||
|
hashie (3.4.6)
|
||||||
i18n (0.7.0)
|
i18n (0.7.0)
|
||||||
jbuilder (2.6.0)
|
jbuilder (2.6.0)
|
||||||
activesupport (>= 3.0.0, < 5.1)
|
activesupport (>= 3.0.0, < 5.1)
|
||||||
|
@ -82,6 +83,9 @@ GEM
|
||||||
nio4r (1.2.1)
|
nio4r (1.2.1)
|
||||||
nokogiri (1.6.8.1)
|
nokogiri (1.6.8.1)
|
||||||
mini_portile2 (~> 2.1.0)
|
mini_portile2 (~> 2.1.0)
|
||||||
|
omniauth (1.3.1)
|
||||||
|
hashie (>= 1.2, < 4)
|
||||||
|
rack (>= 1.0, < 3)
|
||||||
puma (3.6.0)
|
puma (3.6.0)
|
||||||
rack (2.0.1)
|
rack (2.0.1)
|
||||||
rack-test (0.6.3)
|
rack-test (0.6.3)
|
||||||
|
@ -163,6 +167,7 @@ DEPENDENCIES
|
||||||
jbuilder (~> 2.5)
|
jbuilder (~> 2.5)
|
||||||
jquery-rails
|
jquery-rails
|
||||||
listen (~> 3.0.5)
|
listen (~> 3.0.5)
|
||||||
|
omniauth
|
||||||
puma (~> 3.0)
|
puma (~> 3.0)
|
||||||
rails (~> 5.0.0, >= 5.0.0.1)
|
rails (~> 5.0.0, >= 5.0.0.1)
|
||||||
sass-rails (~> 5.0)
|
sass-rails (~> 5.0)
|
||||||
|
@ -175,4 +180,4 @@ DEPENDENCIES
|
||||||
web-console
|
web-console
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.13.2
|
1.13.4
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
protect_from_forgery with: :exception
|
protect_from_forgery with: :exception
|
||||||
|
|
||||||
|
def current_user
|
||||||
|
@current_user ||= User.find_by(id: session[:user_id])
|
||||||
|
end
|
||||||
|
helper_method :current_user
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
class SessionsController < ApplicationController
|
||||||
|
def create
|
||||||
|
@user = User.from_omniauth(request.env['omniauth.auth'])
|
||||||
|
session[:user_id] = @user.id
|
||||||
|
rescue => e
|
||||||
|
logger.error "Error authenticating via omniauth: #{e}"
|
||||||
|
ensure
|
||||||
|
redirect_to root_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if current_user
|
||||||
|
session.delete(:user_id)
|
||||||
|
end
|
||||||
|
redirect_to root_path
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
class User < ApplicationRecord
|
||||||
|
|
||||||
|
def self.from_omniauth(auth_hash)
|
||||||
|
user = find_or_create_by(uid: auth_hash['uid'], provider: auth_hash['provider'])
|
||||||
|
user.name = auth_hash['info']['name']
|
||||||
|
user.save!
|
||||||
|
user
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,7 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
get 'meeting(/:id)', to: 'landing#index'
|
get 'meeting(/:id)', to: 'landing#index'
|
||||||
|
get '/auth/:provider/callback', to: 'sessions#create'
|
||||||
|
get '/logout', to: 'sessions#destroy'
|
||||||
|
|
||||||
root to: 'landing#index'
|
root to: 'landing#index'
|
||||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
class CreateUsers < ActiveRecord::Migration[5.0]
|
||||||
|
def change
|
||||||
|
create_table :users do |t|
|
||||||
|
t.string :provider, null: false
|
||||||
|
t.string :uid, null: false
|
||||||
|
t.string :name
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :users, :provider
|
||||||
|
add_index :users, :uid
|
||||||
|
add_index :users, [:provider, :uid], unique: true
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,26 @@
|
||||||
|
# This file is auto-generated from the current state of the database. Instead
|
||||||
|
# of editing this file, please use the migrations feature of Active Record to
|
||||||
|
# incrementally modify your database, and then regenerate this schema definition.
|
||||||
|
#
|
||||||
|
# Note that this schema.rb definition is the authoritative source for your
|
||||||
|
# database schema. If you need to create the application database on another
|
||||||
|
# system, you should be using db:schema:load, not running all the migrations
|
||||||
|
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||||
|
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||||
|
#
|
||||||
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
|
ActiveRecord::Schema.define(version: 20161017160526) do
|
||||||
|
|
||||||
|
create_table "users", force: :cascade do |t|
|
||||||
|
t.string "provider", null: false
|
||||||
|
t.string "uid", null: false
|
||||||
|
t.string "name"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["provider", "uid"], name: "index_users_on_provider_and_uid", unique: true
|
||||||
|
t.index ["provider"], name: "index_users_on_provider"
|
||||||
|
t.index ["uid"], name: "index_users_on_uid"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,11 @@
|
||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
provider: MyString
|
||||||
|
uid: MyString
|
||||||
|
name: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
provider: MyString
|
||||||
|
uid: MyString
|
||||||
|
name: MyString
|
|
@ -0,0 +1,7 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class UserTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Reference in New Issue