Skip to content

Commit

Permalink
Ajout du paramètre 'callback' dans 'auth_hash'
Browse files Browse the repository at this point in the history
  • Loading branch information
tnicolas1 committed Feb 4, 2025
1 parent e30b591 commit d2993d0
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 20 deletions.
3 changes: 2 additions & 1 deletion app/controllers/concerns/developer_oidc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def static_info(attrs)
"info" => {
"name" => "Developer Account",
"email" => attrs["info"]["email"]
}
},
"callback" => attrs["info"]["insider"]
}
end

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/insider/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ApplicationController < ActionController::Base

helper_method :current_user, :current_establishment

def home; end

def login; end

def logout
Expand Down
38 changes: 22 additions & 16 deletions app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@ def asp
redirect_to asp_schoolings_path
end

def insider
@insider_login = true
@insider_user = Insider::User.from_oidc(auth_hash).tap(&:save!)

# Check limited access to this part ?

sign_in(:insider_user, @insider_user)
def developer
oidcize_dev_hash(auth_hash)

redirect_to insider_home_path
oidc
end

def developer
oidcize_dev_hash(auth_hash)
def masa
oidc
end

def fim
oidc
end

def oidc
return insider if params[:callback].eql?("insider") # TODO: Modifier ou compléter
if auth_hash.info.callback.to_sym.eql?(:insider)
oidc_insider
else
oidc_aplypro
end
end

def oidc_aplypro
parse_identity

@user.save!
Expand All @@ -55,12 +58,15 @@ def oidc
choose_redirect_page!
end

def masa
oidc
end
def oidc_insider
@insider_login = true
@insider_user = Insider::User.from_oidc(auth_hash).tap(&:save!)

def fim
oidc
# TODO: Check limited access to this part ?

sign_in(:insider_user, @insider_user)

redirect_to insider_home_path
end

def failure
Expand Down
3 changes: 3 additions & 0 deletions app/views/insider/application/home.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.home.fr-container
.fr-grid-row.fr-grid-row--center
%p Bonjour
3 changes: 2 additions & 1 deletion app/views/insider/application/login.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
name: t("omniauth.#{provider}.title"),
description: t("omniauth.#{provider}.description"),
button: t("omniauth.#{provider}.button"),
path: "/users/auth/#{provider}"
path: "/users/auth/#{provider}",
callback: :insider
3 changes: 2 additions & 1 deletion config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
:uai,
:email,
{ "Portail de connexion" => portals },
{ "Role assumé" => ["Personnel de direction", "Personnel autorisé"] }
{ "Role assumé" => ["Personnel de direction", "Personnel autorisé"] },
callback: %w[aplypro insider]
]
end

Expand Down
1 change: 1 addition & 0 deletions config/initializers/omniauth_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def request_phase
form.to_response
end

# NOTE: Compose les champs de `auth_hash` utilisé dans `omniauth_callbacks_controller`
info do
options.fields.each_with_object({}) do |field, hash|
if field.is_a? Hash
Expand Down
1 change: 1 addition & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ fr:
insider:
application:
login: Connexion à APLyPro
home : Accueil
stats:
index: Statistiques
school_years:
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
delete "asp/logout", to: "asp/application#logout", as: :destroy_asp_user_session

namespace :insider do
get "home"
get "home", to: "application#home"

devise_for :users, skip: :all, class_name: "Insider::User"
end
Expand Down

0 comments on commit d2993d0

Please sign in to comment.