Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSO Overhaul, Authentication Extenders #2059

Closed

Conversation

askvortsov1
Copy link
Sponsor Member

@askvortsov1 askvortsov1 commented Mar 11, 2020

Fixes #2043
Fixes Part of #1891
Fixes flarum/issue-archive#380
Fixes flarum/issue-archive#236
Fixes flarum/issue-archive#332
Fixes flarum/issue-archive#223
Fixes flarum/issue-archive#285

  • probably more

Changes proposed in this pull request:

  • Deprecate disorganized components of old authentication system
  • Centralize system for extensions to register new authentication systems
  • Add extender to add an sso driver
  • Sso registration respects disabled signups.
  • Add new admin pane, allowing forum admins to:
    • Enable/disable authentication providers
    • Enable/disable signups (move from permissions pane)
    • Enable/disable username/password registration
  • Add new user settings page, allowing users to link and unlink external auth providers from their account
    • Don't allow users to unlink sso providers if username/password authentication is disabled, and the account in question only has 1 linked provider.
  • Add a console command to re-enable username/password login (if SSO breaks we don't want to strand forum admin).
  • Add 'trust emails' feature. If a user is not logged in, and SSO returns the email of an existing user, an error message will be shown if this SSO Driver doesn't have 'trust emails' enabled in the admin pane. If trust emails is enabled for this driver, the SSO provider will be linked to the user's account.
  • Automatically display login buttons based off of meta method of driver.
  • Rewrite bundled extensions to use this new system
    • Auth Github
    • Auth Facebook
    • Auth Twitter
  • Add integration tests for SSO extender methods/functionality test (relies on Add Authenticated Test Case utility #2052)
  • Extensive manual tests

TO ADD AFTER STABLE

  • Ability to test SSO providers in admin panel before enabling (shouldn't be too difficult)
  • Add (non-accidential) support for linking multiple identifiers from a provider to a flarum user.
  • Manage button meta appearance from auth settings pane
  • Manage provider settings through auth settings pane?
  • Add extender method, full support for multifactor authentication.

Reviewers should focus on:

  • How should we standardize nomenclature? IE sso vs auth vs external auth? driver vs provider? Right now, it's kind of a mess of all these.
  • Does the sso flow described in SsoController accurately describe what we want? If not, what should we change/improve?
  • Any things I missed?

Screencasts
Disable username/password auth:
https://youtu.be/kN4XT8BwUIQ

Disabling all sso providers force enables user/pass auth
https://youtu.be/OvS1jxHj5QQ

Disabling signup:
https://youtu.be/TnwrDFgCqnM

Auth Panel controls buttons, Registration works
https://youtu.be/EQchPk7oQuc

Linking/unlinking accounts works
https://youtu.be/teHYWFbTzQY

Can't unlink last provider if username/password auth disabled
https://youtu.be/YcMkBNWORgY

SSO registration respects disabled signups:
https://youtu.be/UCYJWyJB07I

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

@askvortsov1 askvortsov1 changed the title WIP: External Authentication Overhaul, Extenders External Authentication Overhaul, Extenders Mar 12, 2020
@tankerkiller125
Copy link
Contributor

tankerkiller125 commented Mar 12, 2020

How should we standardize nomenclature? IE sso vs auth vs external auth? driver vs provider? Right now, it's kind of a mess of all these.

The nomenclature is pretty simple for me at least.

SSO is Representative of the whole sign in experience through 3rd party companies/services

Auth to me at least describes any way of logging in to the system (AKA are you authorized to access this resource)

External auth, I think is something we can get rid of, either that or we need to replace SSO with it depending on if we want to be technically accurate or we want it to be user friendly (SSO being technically accurate)

When it comes to driver vs provider the way I see it is that the driver is the implementation between flarum and the 3rd party company/service. Provider to me at least means the 3rd party company/service itself.

Does the sso flow described in SsoController accurately describe what we want? If not, what should we change/improve?

The flow looks correct to me, but I would have to test it myself to get a full understanding of how it works.

Should the "disable username/password auth" slider be disabled if no SSO providers are enabled? I'm also leaning in this direction.

Yes, I'd rather not let people break their site, even if admins can bypass it (which it appears they can?) I just think it would create a support headache if we don't disable the slider if there are no SSO provider enabled, further I think that the slider should automatically slide to be turned off if the user disables all of the 3rd party providers.

Also before you go and update all the bundled 3rd party providers to in theory support this system I would recommend you wait until a decision is made on #2006

@@ -98,6 +98,12 @@ public function handle(Request $request): ResponseInterface
}
}

if (!$actor->isGuest() && in_array($driverId, $actor->linkedProviders())) {
// This user has already linked an account from this provider. We don't currently support multiple
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because we're still linking providers by email address? Personally I would prefer to see that the PR also includes a switch to identify users via a relationship between the Flarum user ID and the provider user ID with email strictly as a backup during the transition period.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly. The actual "linkage" is done via an identifier that the SsoDriver would return back (as part of the SsoResponse wrapper class). That identifier COULD be an email, but it could also be any other persistent id.

Email Address is still used to identify if an incoming ssoResponse might be linked to an existing user (which we should keep imo). However, this PR also adds support to linking accounts that don't necessarily share an email (see line 124).

That means that theoretically, a user could link an account that doesn't share an email with their flarum account through their user portal, log out, and log in (same provider, different account on provider, where that account shares an email with their flarum account). Without this check, that new account would also be linked, and now they'd have multiple accounts on one provider linking to one flarum account.

We could allow this, but under the UI in my PR, there isn't a mechanism to unlink a specific identifier from a provider, nor to add another identifier from the same provider.

This might be a feature, not a bug: the system should still function properly with this, and I can't think of security issues it could cause. If it's something we want to support, I can remove this check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for simplicity for now we can wait on multi-identity single provider sso until after stable. I just wanted to verify how this is actually implemented so that we had the option to do so easily in the future.

@askvortsov1
Copy link
Sponsor Member Author

SSO is Representative of the whole sign in experience through 3rd party companies/services

Auth to me at least describes any way of logging in to the system (AKA are you authorized to access this resource)

External auth, I think is something we can get rid of, either that or we need to replace SSO with it depending on if we want to be technically accurate or we want it to be user friendly (SSO being technically accurate)

When it comes to driver vs provider the way I see it is that the driver is the implementation between flarum and the 3rd party company/service. Provider to me at least means the 3rd party company/service itself.

I agree with this interpretation, I'll standardize this. I'm also going to rename LoginProvider (and the associated table) to SsoProvider, as that more accurately describes what it does (username password login doesn't use LoginProviders afaik.

Yes, I'd rather not let people break their site, even if admins can bypass it (which it appears they can?) I just think it would create a support headache if we don't disable the slider if there are no SSO provider enabled, further I think that the slider should automatically slide to be turned off if the user disables all of the 3rd party providers.

Done.

Also before you go and update all the bundled 3rd party providers to in theory support this system I would recommend you wait until a decision is made on #2006

One of my main reasons to do this is to give the core dev team an easier way to test the new functionality when reviewing this PR. Besides, even if the extensions are getting moved to FoF, might as well make their lives easier too :D

@askvortsov1 askvortsov1 changed the title External Authentication Overhaul, Extenders SSO Overhaul, Authentication Extenders Mar 13, 2020
Copy link
Member

@clarkwinkelmann clarkwinkelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read through the code and here are some comments I have.

Also I noticed some files don't have the ending newline. Not sure if our automated tools will fix that formatting or not.

src/Install/Steps/WriteSettings.php Outdated Show resolved Hide resolved
src/Api/Serializer/ForumSerializer.php Show resolved Hide resolved
src/Api/Controller/DeleteSsoProviderController.php Outdated Show resolved Hide resolved
less/common/Checkbox.less Outdated Show resolved Hide resolved
js/src/forum/components/SsoGrid.js Outdated Show resolved Hide resolved
js/src/forum/components/SsoGrid.js Outdated Show resolved Hide resolved
style += providers[provider].buttonColor ? `background-color: ${providers[provider].buttonColor};` : '';
style += providers[provider].buttonTextColor ? `color: ${providers[provider].buttonTextColor}` : '';
items.add(provider,
<LogInButton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not really seen how it looks like for extensions after this change, but I feel they loose some control over their login buttons. They are restricted to only the attributes hard-coded here but might want to customize others.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, I wanted to make it easier for extensions, and these are the settings that every auth extension uses so far. If extensions wanted to go beyond this, couldn't they just extend the LogIn Buttons itemlist?

js/src/forum/components/LogInButtons.js Outdated Show resolved Hide resolved
js/src/admin/components/AuthPage.js Outdated Show resolved Hide resolved
js/src/admin/components/AuthPage.js Outdated Show resolved Hide resolved
@Eldenroot
Copy link

@askvortsov1 you are on fire :D I just wish that Flarum team would be faster in merging and releasing new versions...

@askvortsov1 askvortsov1 force-pushed the as/auth_refactor_and_extender branch 2 times, most recently from bb2dac2 to 1ced410 Compare March 22, 2020 05:33
luceos and others added 17 commits March 25, 2020 11:47
The getEnabled method returns all extensions (previously) enabled, yet manually
uninstalled through composer. This does not reference the exact, current state
of the forum. getEnabledExtensions returns a list where the getEnabled list
is filtered on the extensions found in the composer installed.json file.
I could not come up with a noun for the new "UpdateTest" for users, so
this is easier in terms of consistency.
Forces notifications into a dedicated SendNotificationsJob and passed
to the queue.

- One static method re-used in the job ::getAttributes, is that okay or
  use a trait?
- Do we want to use this solution and refactor into a better Hub after
  stable, postpone this implementation or use it in b11?
This separates sending each individual mail, thus hardening the app.
There are still many improvements possible in this code, e.g. chaining
these commands, making emails just another notification type and
listening to the Notify event instead. We can postpone this to a later
stable release.
As discussed with @luceos, let's add this once the use case comes up. It
might be a left-over from a previous state of this PR anyway.
This gives extension authors time to add the new `getAttributes()`
method to their `BlueprintInterface` implementations.

The layer itself is easy to remove in beta.14.
This has been deprecated and removed from the contract for a long time,
and it will be completely dropped in v5.8, our next upgrade target.
We need to get rid of this god class, as Laravel's Application contract
gets even bigger with 5.8. To avoid having to add all these methods, we
should try to stop using it where we can.
Copy link
Member

@dsevillamartin dsevillamartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR seems to have commits that shouldn't be here. Not sure what happened - perhaps you rebased your branch and the existing commits have different SHAs so they are new?

267 files cannot be changed by this PR 🙂

Copy link
Contributor

@tankerkiller125 tankerkiller125 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My original review was a case of not paying close enough attention to which PR I was on

@askvortsov1 askvortsov1 marked this pull request as draft May 22, 2020 22:09
@stale
Copy link

stale bot commented Aug 21, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep the amount of open issues to a manageable minimum.
In any case, thanks for taking an interest in this software and contributing by opening the issue in the first place!

@stale stale bot added the stale Issues that have had over 90 days of inactivity label Aug 21, 2020
@askvortsov1
Copy link
Sponsor Member Author

This isn't getting reviewed anytime soon, but no reason to close it either.

@stale stale bot removed the stale Issues that have had over 90 days of inactivity label Aug 22, 2020
@askvortsov1 askvortsov1 added the org/keep Issues we want to keep open label Aug 22, 2020
@BoneTM
Copy link

BoneTM commented Aug 28, 2021

why this stuff stopped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
org/keep Issues we want to keep open
Projects
None yet