Sync_sso returns user info but doesn't update

(Jacob Loose) #1

Hello! I have been banging my head against this for the past couple days.

I have a Rails project that is tied into a discourse forum. I would like to use sync_sso to update the discourse data when a user levels up on my site.

I am using the following code:

groups = ["level-1", "level-2", etc]

client ="https://discourse-name")
client.api_key = "my_api_key"
client.api_username = "system"

  sso_secret: "my secret via an ENV-variable",
  username: current_user.username,
  add_groups: "level-#{current_user.level}",
  remove_groups: (groups - ["level-#{current_user.level}"]).join(",") 

When the code is executed, it returns the discourse user information but the group the user should be in is not updated. Normal SSO is set up for login and updates the groups without a problem.

Is there something I am missing here?

(Simon Cossar) #2

It is possible to add users to groups by calling the Discourse sync_sso route, but it doesn’t look like the Discourse API sync_sso method accepts the add_groups or remove_groups parameters: discourse_api/sso.rb at master · discourse/discourse_api · GitHub. It could be updated to handle adding and removing users from groups.

(Jacob Loose) #3

Ah I see! That makes sense. Thank you for the reply.

I will give the API sync_sso a look.

(Jacob Loose) #4

I am having trouble figuring out exactly how to make this API request using rails. I have looked at the PHP example on the forums here but I can’t figure out how to translate that into Rails.

(Simon Cossar) #5

The add_groups and remove_groups params have been added to the Discourse API sync_sso method.

You’ll need to use version 0.29.0 of the gem to get the updated code.