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: https://github.com/discourse/discourse/commit/13d2a1f82c25e16f96ac3bdad67f4369e3d43a61#diff-91c0e802001330ccbdee18eeee6f7161d6eb8751299520fb03a4c74a3aa39fef
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
I see, so you’ve copied the contents of single_sign_on.rb? I guess we might need a documentation update here. Can you try adding a new function inside the SingleSignOn
class in your single_sign_on.rb
file?
def initialize(**kwargs)
end
I think that should resolve the error you’re seeing.
Can you also confirm what version of Ruby you’re using?
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
Ok, I just ran into this myself.
It seems the reference implementation uses a feature that works on 2.7+ which is instantiating an object with an empty hash reference.
args = {}
class A; end
A.new(**args) #=> works only if ruby >= 2.7
Even in ruby >= 2.7 the reference code (lib/single_sign_on.rb) will raise an error if you were to pass a hash in when calling #parse
because on lib/single_sign_on.rb:65 it calls sso = new(**init_kwargs)
and #initialize(secure_session:)
is defined in app/models/discourse_single_sign_on.rb:28 even though DiscourseSingleSignOn
inherits from SingleSignOn
That wouldn’t help people using that code and either use ruby < 2.7 in their project or pass some kwargs.
So yes, at the very minimum I think SingleSignOn
should implement def initialize(**kwargs);end
@david the link for is broken single_sign_on.rb
I’ve updated it to be a permalink. The modern equivalent is discourse_connect_base.rb
Thanks! But, how can I set my user as admin after signing using SSO?
Please open a new support topic with information about what you’ve tried so far, and what the result has been