XF 2.3 Single sign on and more with OAuth2 in XenForo 2.3

hys_8_cover.png
We're approaching the conclusion of the 'Have you seen...?' series for XenForo 2.3. While it may seem like a bittersweet moment, we've intentionally saved one of the most exciting revelations until last. In the upcoming weeks, we might delve into a few more miscellaneous changes and improvements and provide a more developer-centric round up. However, our primary goal is to have XenForo 2.3 up and running on XenForo.com by the end of November. Beyond that milestone, we're excited to share a couple more surprises with you, which will include an overview of the latest enhancements in XenForo Resource Manager, Enhanced Search, and Media Gallery 2.3.

But, back to today, and not only is this an exciting revelation, but it also signals the implementation of our most popular suggestion of all time. Your XenForo installation will be able to act as an OAuth2 server and this opens up a whole array of advanced use cases:
  • Single sign on between your forum and another XenForo installation
  • Single sign on between your forum and another software
  • Building a different front end for your forum, such as a single page app
  • Building a native smartphone app for your forum
  • Integration between your forum and another application
  • Accessing the XenForo REST API as a specific user with a OAuth token
As ever, let's take a look at how to set this up in XenForo 2.3. In the following example we're going to configure an OAuth2 client on a primary XenForo instance and use a secondary XenForo instance to use that primary instance as a connected account provider.

You can add as many OAuth2 clients as you need and this can be done from your admin control panel under Setup > OAuth2 clients (which lists all clients you have created) and clicking "Add OAuth2 client".

And this is what it looks like all filled in:

hys_8_1.png


Most of this is self explanatory. Title, Description, Homepage URL and Image URL are used for branding any OAuth authorization page. Let's take a closer look at a couple of other inputs on ths page.

Client type​

The difference between "Public" and "Confidential" client types may not be immediately obvious but it is crucial. For the sheer majority of OAuth integrations you might have experience with in the past, you are most likely more familiar with the default option which is the "Confidential" type.

For most applications the "Confidential" type is fine. This means you're able to keep the client secret confidential - in other words, the client secret isn't stored or revealed anywhere by the client. This would be appropriate for a XenForo to XenForo connected account.

For situations where it's not safe to store a secret in the client application (like in JavaScript, single-page apps, or native apps), you should choose the 'Public' client type. When using the 'Public' type, you employ the Proof Key for Code Exchange (PKCE) authorization flow. Instead of sharing a secret, you create a random string. This random string serves as a secure way to confirm your identity during the authorization and token exchange process.

It should be noted that PKCE is required for public clients and recommended for confidential clients. A deeper dive into PKCE is beyond the scope of this post, but rest assured everything will be documented via the manual and/or developer documentation before XenForo 2.3 is released.

Authorization / Token / Revocation endpoints​

These are simply the endpoints you need to communicate with in order to authorize, retrieve a token and revoke tokens as per the OAuth 2.0 specs.

Redirect URIs​

Here you can add one or more redirect URIs. These are the approved redirect URIs that the secondary instance may use. Occasionally you might need more than one redirect URI to support different domains or different endpoints that may get called as part of the process. In this example, as we're going to be communicating from a second XenForo forum, its connected_account.php is sufficient as a redirect URI.


Once the client is created you will be able to view your credentials:

hys_8_2.png


Armed with these, we can now set up a connected account provider on the secondary XenForo instance.

hys_8_3.png


The connected account side of things is all very familiar if you've ever set up any of the existing ones before. The crucial thing is to make sure you get the target board URL correct.

But what you really want to see is the authorization process, don't you?

Via the login, registration or Account > Connected accounts page, as soon as you click the button that corresponds to your new XenForo connected account provider, you will be redirected to the authorization page:

hys_8_4.png


Clicking Authorize will complete the usual steps to authenticate you using OAuth and redirect you back:

hys_8_5.png


If you have approved any applications to access your XenForo account then you can see a list of them under Account > Applications:

hys_8_6.png


While exciting in itself, this is merely a single use case amongst many that our OAuth implementation will open up. And this is where we will leave it for this week. Next week we'll be focusing an entire 'Have you seen...?' entry on what's new for developers in XenForo 2.3. This will enable us to provide a more detailed dive into some smaller, developer-centric changes, including a closer look at some more advanced parts of OAuth such PKCE, authenticating against the REST API and refresh tokens.

If developers want us to talk about anything specific in more detail that we might have mentioned in the last few weeks, please do let us know.
 
This is something we'll look at between now and release.
Okay. If this isn't already done it IMHO really needs to be done before RTM as there may very well be API scopes that should not be available for every client (or any OAuth client to begin with).
For example we use the API (with custom calls and scopes) to connect various systems - such APIs definitly should not be available to normal OAuth clients.

As it stands currently, no.
Would be nice to have - Suggestion filed :)

Would be nice to see a setup guide for OAuth using one of the platform agnostic self-hosted auth platforms... Like Ory's
Not sure if that would work (without custom code).
The screenshot shows an explicit XenForo provider - this not a generic OAuth2 provider.
 
Last edited:
For example: if a user purchases an account upgrade on one site, then the account on the other site(s) would also receive the upgrade.
@Alpha1 that sounds very specific to your use case and I would recommend making your own addon for that and making use of webhooks.
 
It's great to see both webhooks and Oauth implemented, because these bring us 2 steps closer to the implementation of my suggestions. Thank you!

Not exactly: We are not there yet. From the suggestion thread:

It seems I will need to repost this most popular suggestion for the third time? The first and the second one both got hundreds of votes, were the top voted suggestions and took years.
Please consider to add member sync in xf2.3. The whole point of the first two suggestions is to have the same members with the same usergroups on multiple sites. i.e. if an account upgrade or a promotion happens on one site, then it changes on the other sites as well.
Well, this is the danger of conflating multiple things in a single suggestion.

We have implemented the suggestion because there is indeed now a mechanism to provide Single sign on between XF and other software amongst other use cases.

A REST API isn’t OAuth. And OAuth isn’t SSO. And SSO isn’t a mechanism to automatically sync users. They can be related and crossover, but it’s ignorant to conflate them all and demand it’s added. It’s obviously not going to be added in 2.3 unless we announce it. We’re close to release. If it is ever added - and I’m not at all suggesting it will be - it will be in the future.

So, yeah, you might have to make a third suggestion if you want the third entirely separate component to be implemented.
 
Well, this is the danger of conflating multiple things in a single suggestion.
That's true, but I did ask the main suggestion post to be edited back in 2019, because adding a 2nd suggestion when its dependent upon something that was not implemented yet also doesn't work. That's moot now.
A REST API isn’t OAuth. And OAuth isn’t SSO. And SSO isn’t a mechanism to automatically sync users.
True. And webhooks also isn't API or OAuth. Yet these are all closely related technologies that can be combined for the specific purpose of running multiple platforms with the same member profiles. If you read trough the original REST API thread, then its clear what intended purposes the demand is for.

At least XF2.3 has the technology to support such a setup.
 
@Alpha1 that sounds very specific to your use case and I would recommend making your own addon for that and making use of webhooks.
No, quite a lot of members here have expressed a desire for it in the years since the original suggestion was posted in 2003 and the second one in 2019.
In any case: I already had an addon for this on XF1. At some point the addon broke my site and the developer went unresponsive for 3 months. So I'm never going to repeat that situation again. Its very unwise to use addons for functionality you depend upon. Unless the developer is one of the few rare diamonds here that you can always rely upon.
 
Talk of conflating multiple things in one request - isn't that the same concept as webhooks and the conversation around it being bidirectional? I seem to remember devs saying they would consider the suggestion partially complete? I'd say that's the same for this one in specific to the suggestion thread.

There's tonnes of open suggestions, a lot very good. It would be nice to see them closed and implemented in batches rather than 2 or 3. I don't doubt they've been working very hard, but I wish there was more developers to knock these suggestions down.
 
Right, I've now had a chance to properly read this article and can say that I like this aspect especially. This is because I help to run a partner forum as well, so both forums could benefit from having a common set of users.
But not the same users.
 
But not the same users.
The same users are more than welcome to register to both. Perhaps not the same usernames. But potentially the same users.

If your site is new allow registrations on one forum and not the other except via oauth. If it's an established forum how do you suppose to deal with the conflicting username issues?
 
W
The same users are more than welcome to register to both. Perhaps not the same usernames. But potentially the same users.

If your site is new allow registrations on one forum and not the other except via oauth. If it's an established forum how do you suppose to deal with the conflicting username issues?
Would be cool if two sites could share one userbase and set their display name per site.
 
W

Would be cool if two sites could share one userbase and set their display name per site.
Absolutely but perhaps not always feasible. Nothing is ever ideal. How do you username tag between usernames and display names? How do you stop spoofing? If display names cannot copy usernames then if someone else has your name you're screwed regardless!

Perhaps usernames could be prefixed with the oauth origin. User X1 on abc.com registers on def.com as ABC-X1 maybe. Swings and roundabouts.
 
True. It's all good thinking material!
Absolutely but perhaps not always feasible. Nothing is ever ideal. How do you username tag between usernames and display names? How do you stop spoofing? If display names cannot copy usernames then if someone else has your name you're screwed regardless!

Perhaps usernames could be prefixed with the oauth origin. User X1 on abc.com registers on def.com as ABC-X1 maybe. Swings and roundabouts.
 
Single sign on between your forum and another software
So, can XF installation users access another Joomla or WordPress installation on a different website? If so, does it remain something primarily intended for developers or at least for those who are proficient in creating the necessary extensions for other platforms?
 
Top Bottom