Create SSO Users, Adding To Group, Subscribing to Category via API

AI-generated summary

In a discussion titled “Create SSO Users, Adding To Group, Subscribing to Category via API,” SwisherSweet seeks to automate user onboarding in Discourse via API for an external ASP.NET MVC app using SSO. The goals are: pre-creating users, assigning them to a security group, and subscribing them to a specific category for updates. Falco confirms this is possible using normal (not staged) users and outlines a 3-step API workflow: create user, add to group, and subscribe to categories. SwisherSweet asks for .NET examples or wrappers, referencing a prior thread about SSO user creation. Webmaster_ESN_Greece shares experience using SSO with PHP and the discourse-php helper, noting that groups can be configured to auto-watch categories via SSO parameters like add_groups. SwisherSweet asks for the specific API endpoint to make a user watch a category, as it’s not obvious in the docs. In post 6, they clarify confusion about setting default watched categories at the group level in Discourse’s UI, requesting more detail. The discussion highlights that while API calls for user/group management are well-documented, category subscription via API or SSO group defaults may require deeper exploration or configuration.

Hi,

Our external system needs to integrate with Discourse. Discourse is currently using SSO to authenticate against our external system with no issues. However, we need to automate a few things:

  1. External users need to be added in advanced of logging into Discourse.
  2. After being added, external users need to be added to a specific Security Group.
  3. External users need to be subscribed to receive updates from a specific Category.

Overall, the goal is as new users join the external system (an ASP.net MVC app) they also join Discourse and receive updates from a specific category.

Can all of this be done just using the API?

It’s my understanding that one can use the API to create a user as “Staged” via the API. However, I’m not sure this can be done on SSO users of if the users can receive email updates from subscribed categories.

I’m not sure if a user can be subscribed to receive updates from a specific category using the API or not.

Thank you.

This is all possible and I did exactly this years ago.

First, since you want users to receive updates before “creating the account” go with normal users and not staged.

When a user create a new account on your current app, you will

  1. Send API request to create a new user

  2. Send API requests to add it to groups

  3. Send API request to make it watch some categories

Thanks @Falco. I mentioned creating staged users because of what I read in this thread. Perhaps I misunderstand what the aforementioned thread was saying.

Did you also make calls with .Net? If so, do you know of any .Net API wrappers or know where I might find an example of calling the API with .Net to create a user using the API key?

Thanks again.

Hello, in ESN Greece (there is a cas server), so after the authentication, the user info is available in our PHP app, which next it will redirect back to discourse. (SSOhelper)

fields you may send back to discourse are

   'username' => string,
    'name'     => string,
    'avatar_url' =>  string->url,
    'add_groups' => discourse group names seperated with comma,
    'remove_groups' => discourse group names seperated with comma

About some categories based on Group you may edit your Groups @ discourse level and set them what categories to watch by default

@Falco perhaps I’m just missing it, but I cannot find the API call to make a user watch a category(ies). Do you know which API call you used to do this?

@Webmaster_ESN_Greece perhaps I’m not understanding correctly, but the there doesn’t appear to be a way in the Discourse UI to set categories to watch by default when editing a group. Would you ming be more specific?

Thank you.