Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local login strategy to develop without Keycloak #464

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
redirect_to user_path user
end

def create_developer # rubocop: disable Metrics/AbcSize
user = User.find_or_create_by!(

Check warning on line 12 in app/controllers/sessions_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/sessions_controller.rb#L12

Added line #L12 was not covered by tests
email: params[:email]
) do |u|
u.firstname = params[:firstname]
u.lastname = params[:lastname]
u.room = params[:room]

Check warning on line 17 in app/controllers/sessions_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/sessions_controller.rb#L15-L17

Added lines #L15 - L17 were not covered by tests
end
user.groups = params[:groups].split(',')
log_in user
flash[:success] = 'You are now logged in (using developer method)!'
redirect_to user

Check warning on line 22 in app/controllers/sessions_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/sessions_controller.rb#L19-L22

Added lines #L19 - L22 were not covered by tests
end

def destroy
log_out
flash[:success] = 'You are now logged out!'
Expand Down
9 changes: 9 additions & 0 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
'aria-label': "Log in",
data: { turbo: false }
) %>
<% if Rails.env.development? %>
<%= button_to(
"Login (developer)",
"/auth/developer",
class: "login_button",
'aria-label': "Log in (developer)",
data: { turbo: false }
) %>
<% end %>
<% else %>
<%= button_to(
"Logout",
Expand Down
32 changes: 20 additions & 12 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
# frozen_string_literal: true

Rails.application.config.middleware.use OmniAuth::Builder do
if Rails.env.production?
client_options = {
identifier: Rails.application.credentials.sso_id!,
secret: Rails.application.credentials.sso_secret!,
redirect_uri: "https://lea5.rezoleo.fr/#{AUTH_CALLBACK_PATH}"
}
elsif Rails.env.development?
client_options = {
identifier: Rails.application.credentials.sso_id!,
secret: Rails.application.credentials.sso_secret!,
redirect_uri: "http://127.0.0.1:3000/#{AUTH_CALLBACK_PATH}"
if Rails.env.development?
provider :developer, {
fields: [:firstname, :lastname, :email, :room, :groups]
}
end

Expand All @@ -25,6 +17,22 @@
issuer: 'https://auth.rezoleo.fr/realms/rezoleo',
discovery: true,
pkce: true,
client_options: client_options
client_options: oidc_client_options
}
end

def oidc_client_options
if Rails.env.production?
{
identifier: Rails.application.credentials.sso_id!,
secret: Rails.application.credentials.sso_secret!,
redirect_uri: "https://lea5.rezoleo.fr/#{AUTH_CALLBACK_PATH}"
}
elsif Rails.env.development?
{
identifier: Rails.application.credentials.sso_id!,
secret: Rails.application.credentials.sso_secret!,
redirect_uri: "http://127.0.0.1:3000/#{AUTH_CALLBACK_PATH}"
}
end
end
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
get AUTH_CALLBACK_PATH, to: 'sessions#create', as: 'auth_callback'
if Rails.env.development?
get '/auth/developer/callback', to: 'sessions#create_developer', as: 'auth_callback_developer'
end

delete '/logout', to: 'sessions#destroy', as: 'logout'
root 'static_pages#home'

Expand Down