Allow user to disconnect OIDC account

This makes testing much easier. But probably also good for users to
revoke any access via OIDC apps. It also enables users to then connect
to a different account, or just renew the current connection.
This commit is contained in:
Maikel Linke
2024-02-14 17:02:52 +11:00
parent 4f3ae4f2a4
commit a89b22e397
6 changed files with 20 additions and 7 deletions

View File

@@ -2,6 +2,13 @@
module Admin
class OidcSettingsController < Spree::Admin::BaseController
def index; end
def index
@account = spree_current_user.oidc_account
end
def destroy
spree_current_user.oidc_account&.destroy
redirect_to admin_oidc_settings_path
end
end
end

View File

@@ -42,6 +42,7 @@ module Spree
has_many :credit_cards, dependent: :destroy
has_many :report_rendering_options, class_name: "::ReportRenderingOptions", dependent: :destroy
has_many :webhook_endpoints, dependent: :destroy
has_one :oidc_account, dependent: :destroy
accepts_nested_attributes_for :enterprise_roles, allow_destroy: true
accepts_nested_attributes_for :webhook_endpoints

View File

@@ -7,16 +7,17 @@
%h2= t(".connect")
%br
- # I'll refactor this later:
- account = OidcAccount.find_by(provider: "openid_connect", user: spree_current_user)
- if account
- if @account
= t(".already_connected")
= account.uid
= @account.uid
%br
%br
= t(".view_account")
= link_to t(".les_communs_link"), "#{ Devise.omniauth_configs[:openid_connect].options[:issuer] }/account"
%br
%br
= button_to t(".disconnect"), admin_oidc_setting_path(@account), method: :delete
- else
= t(".link_your_account")

View File

@@ -1712,6 +1712,7 @@ en:
index:
title: "OIDC Settings"
connect: "Connect Your Account"
disconnect: "Disconnect"
already_connected: "Your account is already linked to this DFC authorization account:"
les_communs_link: "Les Communs Open ID server"
link_your_account: "You need first to link your account with the authorization provider used by DFC (Les Communs Open ID Connect)."

View File

@@ -113,7 +113,7 @@ Openfoodnetwork::Application.routes.draw do
put :unpause, on: :member
end
resources :oidc_settings, only: :index
resources :oidc_settings, only: [:index, :destroy]
resources :subscription_line_items, only: [], format: :json do
post :build, on: :collection

View File

@@ -17,10 +17,13 @@ describe "OIDC Settings" do
login_as user
end
it "allows you to connect to an account" do
it "allows you to connect to an account and disconnect again" do
visit admin_oidc_settings_path
click_button "Link your Les Communs OIDC Account"
expect(page).to have_content "Your account is already linked"
click_button "Disconnect"
expect(page).to have_button "Link your Les Communs OIDC Account"
end
end
end