Sso and api sign up


(Hosein Naseri) #1

I don’t know if I’m confusing something.
I have enabled sso, now I want to sign up users from api.
How sso and api work together to sign up a user?


(Jay Pfaffman) #2

If you use so, then only the so provider can create users. It’s, called single sing on for a reason.


(Hosein Naseri) #3

My SSO provider is wordpress. The situation is this:

I have created an application and it uses wordpress for sign up/in purposes.
Now when I sign up a new user in the application, I want them to be able to create a new topic inside the application, and I, using the api, want to post that topic in my discourse forum.

the problem: the user has not still used the sso to sign up in discourse too and no username is created for them in discourse.

So how I’m able to programatically sign up the user in the discourse, when they sign up in wordpress inside my application?


(Hosein Naseri) #4

I think I found a possible solution but I don’t know if its the right way.

First I sign up the user in wordpress.

then by this api call, I sign up the user in discourse:
curl -X POST --data "name=Name&username=wordpressusername&email=wordpressemail@gmail.com&password=P@ssword&api_key=dafsdfsdfsdfds&api_username=xxxx" http://talk.mywebsite.com/users

in the above mentioned api call wordpressusername and wordpressemail is the user-name and email created for the user in wordpress, when they sign up.

By this way I can register the same email as registered in wordpress, in the discourse.

Is this solution the correct way to do it?


(Blake Erickson) #5

Have you checked out the wp-discourse plugin yet?

This should handle all of the sso for you, so that you don’t have to write your own code for it.


(Hosein Naseri) #6

Look my problem isn’t SSO. I have already solved the SSO by using this plugin.
My problem is when the user sign up with wordpress in my application, I want them to be able to create a new topic and I process the topic using discourse api. However the api needs a username and since the user has not used the sso to sign up in discourse, there is no username in discourse for it to create the topic.

I’m referring to the following api call:
curl -X POST --data "title=mytitle&raw=mycontent&category=5&api_key=xxxx&api_username=xxxx" http://talk.mywebsite.com/posts

So I need to somehow programatically sign up the user in the discourse forum too. but how?


(Blake Erickson) #7

Yes that command should work to create a new user.

http://docs.discourse.org/#tag/Users%2Fpaths%2F~1users%2Fpost

see these topics for info about activating users and activation emails:



(Hosein Naseri) #8

I know. But is it a good practice to use it with an sso enabled discourse?


(Blake Erickson) #9

Yep.

I would just make sure signup is disabled in discourse so that you don’t get users that exist in discourse but not wordpress. wordpress needs to be the source of user truth.