Search code examples
single-sign-ondisqus

How to lookup SSO user in Disqus?


I have SSO working in Disqus, so that my authenticated users can automatically post to my Disqus forum without separate authentication. However, I cannot find a way to whitelist my SSO users via a server-side API call. It seems that my SSO users are not recognized in any user-related calls to the API.

I've tried calling whitelists/add with both user=[userid] and email=[email], passing the exact userid and email with which I setup the SSO user. No error is returned with the userid, but it does nothing. Passing the email throws an error.

I've tried locating the Disqus user id or username for my SSO users via the users/detail API via:

   user=myuserid (the same id used for SSO)
   [email protected]  (the same email used for SSO)
   user=remote:forumshortname-myuserid
   user:username=forumshortname-myuserid

No luck.

API calls to /listUsers and /users/detail do not list my sso users at all, so I cannot retrieve their user handles that way.

The frustrating thing is that I can see the users in the UI console here: https://disqus.com/api/sso/users/ for the domain (as opposed to the forum), so I know this data exists. But I can't find a way via API to reach it.

Does anyone have this working?


Solution

  • As far as the Disqus API is concerned, the user ID and username of an SSO user is the one that is assigned by Disqus, and not the site. They're unique across the Disqus network, even though they're local to your site only.

    However, if you have your own local user ID, you can do a reverse lookup of the Disqus username for the purposes of using the API. The pattern is {sso_slug}-{user_id_md5}

    Assuming your SSO remote domain slug is example, you can retrieve the Disqus username like this in python:

    import hashlib
    
    def get_disqus_username(user_id):
        m = hashlib.md5(user_id)
        hashed_id = m.hexdigest()
        return 'example-' + str(hashed_id)
    

    Now you can make API requests like this:

    GET https://disqus.com/api/3.0/users/details.json?api_key=YOUR_PUBLIC_KEY&user=username:DISQUS_USERNAME