Errore ArgumentError in DiscourseSsoController#sso, numero errato di argomenti (dato 1, previsto 0)

Following the guide DiscourseConnect - Official Single-Sign-On for Discourse (sso) I’ve enabled Discourse SSO to share login with my existing RoR application, but I get “Error ArgumentError in DiscourseSsoController#sso, wrong number of arguments (given 1, expected 0)” after being redirected to my website and having done login.

Looking at the screenshot, that error appears to be coming from your custom rails app, rather than Discourse. Is that correct? I don’t think Discourse has a DiscourseSsoController#sso method, and the backtrace doesn’t look like Discourse either.

How have you implemented that method in your rails app? Have you imported some parts of the code from Discourse’s codebase? If so, your imports might be affected by this change: SECURITY: Attach DiscourseConnect (SSO) nonce to current session (#12… · discourse/discourse@13d2a1f · GitHub

1 Mi Piace

This class is in my application, but it’s official code from DiscourseConnect - Official Single-Sign-On for Discourse (sso) that I’ve putted in my application to manage SSO

Followed also Incorporating Discourse SSO with Existing Rails Site with Devise - Stack Overflow

Capisco, quindi hai copiato il contenuto di single_sign_on.rb? Immagino che qui potrebbe essere necessario un aggiornamento della documentazione. Puoi provare ad aggiungere una nuova funzione all’interno della classe SingleSignOn nel tuo file single_sign_on.rb?

def initialize(**kwargs)
end

Penso che questo dovrebbe risolvere l’errore che stai riscontrando.

Puoi anche confermare quale versione di Ruby stai utilizzando?

1 Mi Piace

Yes, I’ve copied the contents of single_sign_on.rb

I’m using Ruby 2.4.6

After adding initialize the error changed

Did you restart the server? I can’t think why an error would be raised on an end line, so I suspect the running code does not match what’s on the filesystem?

That could well be part of the problem. Discourse code is all written for 2.7+

Excuse me my fault, I did not restart the server, having no noticed the modification was on initializer
Having Devise with CanCanCan I had to do also this: comment before_action and add skip_authorization_check:

class DiscourseSsoController < ApplicationController
   skip_authorization_check
   #before_action :authenticate_user! # ensures user must login
1 Mi Piace

Ok, mi sono imbattuto proprio in questo.
Sembra che l’implementazione di riferimento utilizzi una funzionalità che funziona dalla versione 2.7 in poi, ovvero l’istanziazione di un oggetto con un riferimento a un hash vuoto.

args = {}
class A; end
A.new(**args) #= works only if ruby >= 2.7

Anche in Ruby >= 2.7, il codice di riferimento (lib/single_sign_on.rb) genererà un errore se si passa un hash durante la chiamata a #parse, perché su lib/single_sign_on.rb:65 viene chiamato sso = new(**init_kwargs) e #initialize(secure_session:) è definito in app/models/discourse_single_sign_on.rb:28, anche se DiscourseSingleSignOn eredita da SingleSignOn.

Questo non aiuterebbe chi utilizza quel codice e usa Ruby < 2.7 nel proprio progetto o passa alcuni keyword arguments.
Quindi sì, almeno SingleSignOn dovrebbe implementare def initialize(**kwargs);end.

@david il link per è interrotto single_sign_on.rb

L’ho aggiornato per essere un permalink. L’equivalente moderno è discourse_connect_base.rb

1 Mi Piace

Grazie! Ma come posso impostare il mio utente come amministratore dopo l’accesso tramite SSO?

Apri un nuovo argomento Support con informazioni su ciò che hai provato finora e quale è stato il risultato.

2 Mi Piace