# Error ArgumentError in DiscourseSsoController#sso, wrong number of arguments (given 1, expected 0)

**URL:** https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274
**Category:** SSO
**Created:** [March 24, 2021, 9:36am UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274 "2021-03-24T09:36:49Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Andrea\_Giovacchini](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andrea_giovacchini/32/213224_2.png) [@Andrea\_Giovacchini](https://meta.discourse.org/u/Andrea_Giovacchini)
#### Post date: [March 24, 2021, 9:36am UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274/1 "2021-03-24T09:36:49Z")

</div>

Following the guide [Setup DiscourseConnect - Official Single-Sign-On for Discourse (sso)](https://meta.discourse.org/t/discourseconnect-official-single-sign-on-for-discourse-sso/13045) I’ve enabled [Discourse SSO](https://meta.discourse.org/t/13045?silent=true) 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.

 ![image](https://global.discourse-cdn.com/meta/original/3X/8/8/88b9a375cac829704efcefbee5e713ce168fcac7.png)

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [March 24, 2021, 9:55am UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274/2 "2021-03-24T09:55:52Z")

</div>

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](https://github.com/discourse/discourse/commit/13d2a1f82c25e16f96ac3bdad67f4369e3d43a61#diff-91c0e802001330ccbdee18eeee6f7161d6eb8751299520fb03a4c74a3aa39fef)

---

<div class="post-metadata">

### Author: ![Andrea\_Giovacchini](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andrea_giovacchini/32/213224_2.png) [@Andrea\_Giovacchini](https://meta.discourse.org/u/Andrea_Giovacchini)
#### Post date: [March 24, 2021, 10:46am UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274/3 "2021-03-24T10:46:23Z")

</div>

This class is in my application, but it’s official code from [Setup DiscourseConnect - Official Single-Sign-On for Discourse (sso)](https://meta.discourse.org/t/discourseconnect-official-single-sign-on-for-discourse-sso/13045) that I’ve putted in my application to manage SSO

Followed also [https://stackoverflow.com/questions/25478510/incorporating-discourse-sso-with-existing-rails-site-with-devise](https://stackoverflow.com/questions/25478510/incorporating-discourse-sso-with-existing-rails-site-with-devise)

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [March 24, 2021, 11:05am UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274/4 "2021-03-24T11:05:36Z")

</div>

I see, so you’ve copied the contents of [single\_sign\_on.rb](https://github.com/discourse/discourse/blob/7db3888f17ec07800e1aba0b5470bb9efe73a670/lib/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?

```plaintext
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?

---

<div class="post-metadata">

### Author: ![Andrea\_Giovacchini](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andrea_giovacchini/32/213224_2.png) [@Andrea\_Giovacchini](https://meta.discourse.org/u/Andrea_Giovacchini)
#### Post date: [March 24, 2021, 11:09am UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274/5 "2021-03-24T11:09:35Z")

</div>

Yes, I’ve copied the contents of [single\_sign\_on.rb](https://github.com/discourse/discourse/blob/master/lib/single_sign_on.rb)

I’m using Ruby 2.4.6

After adding initialize the error changed

 ![image](https://global.discourse-cdn.com/meta/original/3X/a/c/ac76caf884e491e5ff4837cb0f371e5326d3ff5f.png)

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [March 24, 2021, 11:11am UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274/6 "2021-03-24T11:11:59Z")

</div>

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?

> [@Andrea\_Giovacchini](#):
>
> Ruby 2.4.6

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

---

<div class="post-metadata">

### Author: ![Andrea\_Giovacchini](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andrea_giovacchini/32/213224_2.png) [@Andrea\_Giovacchini](https://meta.discourse.org/u/Andrea_Giovacchini)
#### Post date: [March 24, 2021, 11:16am UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274/7 "2021-03-24T11:16:42Z")

</div>

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

```

---

<div class="post-metadata">

### Author: ![dscat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dscat/32/203656_2.png) [@dscat](https://meta.discourse.org/u/dscat)
#### Post date: [October 21, 2021, 8:42pm UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274/8 "2021-10-21T20:42:52Z")

</div>

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.

```plaintext
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`

---

<div class="post-metadata">

### Author: ![Samir\_Sabri](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/samir_sabri/32/287380_2.png) [@Samir\_Sabri](https://meta.discourse.org/u/Samir_Sabri)
#### Post date: [December 30, 2022, 7:33pm UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274/9 "2022-12-30T19:33:28Z")

</div>

@david the link for is broken [single\_sign\_on.rb](https://github.com/discourse/discourse/blob/master/lib/single_sign_on.rb)

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [December 30, 2022, 7:55pm UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274/10 "2022-12-30T19:55:17Z")

</div>

I’ve updated it to be a permalink. The modern equivalent is [`discourse_connect_base.rb`](https://github.com/discourse/discourse/blob/6f570752abfd4fe6e1fd705ecdf43f257509cb83/lib/discourse_connect_base.rb)

---

<div class="post-metadata">

### Author: ![Samir\_Sabri](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/samir_sabri/32/287380_2.png) [@Samir\_Sabri](https://meta.discourse.org/u/Samir_Sabri)
#### Post date: [December 30, 2022, 8:46pm UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274/11 "2022-12-30T20:46:16Z")

</div>

Thanks! But, how can I set my user as admin after signing using SSO?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [December 30, 2022, 9:54pm UTC](https://meta.discourse.org/t/error-argumenterror-in-discoursessocontroller-sso-wrong-number-of-arguments-given-1-expected-0/184274/12 "2022-12-30T21:54:06Z")

</div>

Please open a new #Support topic with information about what you’ve tried so far, and what the result has been
