-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add first version of OIDC login Co-authored-by: Alexander Sohn <[email protected]> * Fix rubocop issues Co-authored-by: Alexander Sohn <[email protected]> * Revert DB Schema changes Co-authored-by: Alexander Sohn <[email protected]> * Revert DB Schema changes - like, eally Co-authored-by: Alexander Sohn <[email protected]> * Add tests Co-authored-by: Alexander Sohn <[email protected]> * Fix linter issues Co-authored-by: Alexander Sohn <[email protected]> * Remove schema changes and remove CSRF on certain route * Update schema to current version on main * Remove unlocalized text Co-authored-by: Alexander Sohn <[email protected]>
- Loading branch information
Showing
9 changed files
with
176 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController | ||
# See https://github.com/omniauth/omniauth/wiki/FAQ#rails-session-is-clobbered-after-callback-on-developer-strategy | ||
skip_before_action :verify_authenticity_token, only: :openid_connect | ||
def openid_connect | ||
@user = User.from_omniauth(request.env["omniauth.auth"]) | ||
if @user.persisted? | ||
sign_in_and_redirect @user | ||
set_flash_message(:notice, :success, kind: "OpenID Connect") if is_navigational_format? | ||
else | ||
set_flash_message(:alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name), reason: failure_message) | ||
redirect_to root_path | ||
end | ||
end | ||
|
||
def failure | ||
set_flash_message(:alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name), reason: failure_message) | ||
redirect_to root_path | ||
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
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,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
describe "OpenId Connect Login", type: :feature do | ||
context "with a valid OIDC session returned" do | ||
before do | ||
OmniAuth.config.mock_auth[:openid_connect] = OmniAuth::AuthHash.new( | ||
provider: "openid_connect", | ||
uid: "test.user", | ||
info: { | ||
email: "[email protected]" | ||
} | ||
) | ||
|
||
visit new_user_session_path | ||
find_by_id('openid_connect-signin').click | ||
end | ||
|
||
it "redirects to dashboard path" do | ||
expect(page).to have_current_path(dashboard_path) | ||
end | ||
|
||
it "displays a success message" do | ||
expect(page).to have_css(".alert-success") | ||
end | ||
end | ||
|
||
context "with invalid oidc session returned" do | ||
before do | ||
@omniauth_logger = OmniAuth.config.logger | ||
# Change OmniAuth logger (default output to STDOUT) | ||
OmniAuth.config.logger = Rails.logger | ||
|
||
OmniAuth.config.mock_auth[:openid_connect] = :invalid_credentials | ||
visit new_user_session_path | ||
find_by_id('openid_connect-signin').click | ||
end | ||
|
||
it "redirects to login path" do | ||
expect(page).to have_current_path(new_user_session_path) | ||
end | ||
|
||
it "shows an error message" do | ||
expect(page).to have_css(".alert-danger") | ||
end | ||
|
||
end | ||
end |