-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from pulibrary/cas
Add CAS login
- Loading branch information
Showing
16 changed files
with
117 additions
and
15 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
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
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,10 @@ | ||
# frozen_string_literal: true | ||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | ||
def cas | ||
# You need to implement the method below in your model (e.g. app/models/user.rb) | ||
@user = User.from_omniauth(request.env["omniauth.auth"]) | ||
|
||
sign_in_and_redirect @user, event: :authentication # this will throw if @user is not activated | ||
set_flash_message(:notice, :success, kind: "CAS") if is_navigational_format? | ||
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
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,10 +1,11 @@ | ||
development: | ||
admin: | ||
- admin@example.com | ||
- admin | ||
- tpend | ||
|
||
test: | ||
admin: | ||
- admin@example.com | ||
- admin | ||
|
||
production: | ||
# Add roles for users here. |
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,9 @@ | ||
# frozen_string_literal: true | ||
class AddCasToUsers < ActiveRecord::Migration[5.1] | ||
def change | ||
add_column :users, :provider, :string | ||
add_index :users, :provider | ||
add_column :users, :uid, :string | ||
add_index :users, :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
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,11 +1,12 @@ | ||
# frozen_string_literal: true | ||
FactoryGirl.define do | ||
factory :user do | ||
sequence(:email) { |_n| "email-#{srand}@example.com" } | ||
password 'a password' | ||
password_confirmation 'a password' | ||
sequence(:email) { |_n| "#{srand}@princeton.edu" } | ||
sequence(:uid) { |_n| "#{srand}@princeton.edu" } | ||
provider 'cas' | ||
end | ||
factory :admin, parent: :user do | ||
email "admin@example.com" | ||
uid 'admin' | ||
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,13 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
RSpec.describe "Home Page" do | ||
let(:user) { FactoryGirl.create(:admin) } | ||
before do | ||
sign_in user | ||
end | ||
|
||
it "displays creation links for administrators" do | ||
expect(page).to have_link "New Scanned Resource" | ||
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
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,18 @@ | ||
module Features | ||
# Provides methods for login and logout within Feature Tests | ||
module SessionHelpers | ||
# Use this in feature tests | ||
def sign_in(who = :user) | ||
user = if who.instance_of?(User) | ||
who.uid | ||
else | ||
FactoryGirl.create(:user).uid | ||
end | ||
OmniAuth.config.add_mock(:cas, uid: user) | ||
visit user_cas_omniauth_authorize_path | ||
end | ||
end | ||
end | ||
RSpec.configure do |config| | ||
config.include Features::SessionHelpers, type: :feature | ||
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,8 @@ | ||
OmniAuth.config.test_mode = true | ||
RSpec.configure do |config| | ||
config.before(:each) do | ||
OmniAuth.config.mock_auth[:cas] = nil | ||
Rails.application.env_config["devise.mapping"] = Devise.mappings[:user] # If using Devise | ||
Rails.application.env_config["omniauth.auth"] = OmniAuth.config.mock_auth[:twitter] | ||
end | ||
end |