[3.0] External authentication (part 2 of 5) — lets members sign in with an OpenID Connect provider - #9488
Open
albertlast wants to merge 4 commits into
Open
[3.0] External authentication (part 2 of 5) — lets members sign in with an OpenID Connect provider#9488albertlast wants to merge 4 commits into
albertlast wants to merge 4 commits into
Conversation
Everything about signing in assumes the password form did it. The steps that follow a successful check live in Login2::DoLogin(), which is protected and reads its member from a private property, so nothing else can reuse them; two factor authentication is looked up by reading the tfa_secret column wherever the question comes up; and every account is assumed to have a password worth asking for. None of that is a problem until something else can vouch for a member, at which point each one has to be worked around rather than used. So: Moves the body of DoLogin() to Login2::completeLogin(), taking the member and the cookie lifetime as arguments. DoLogin() now just calls it, so the password path is unchanged, and anything else that authenticates a member can finish the job the same way instead of setting the cookie by hand and missing the ban check or the login history. Adds User::getSecondFactors(), which reports the factors a member has and lets a mod add its own, and asks it instead of reading tfa_secret. It reads the loaded profile rather than object properties because verifyTfa() runs before setProperties() does. Checking it in Login2::checkCookie() now also checks tfa_mode, as verifyTfa() already did; without that a member could be sent to ?action=logintfa when nothing was going to ask them for a code, which ends in "You are not allowed to access this section" rather than a login. Adds User::hasUsablePassword() for accounts that have no password to give. The login form refuses them before the legacy hash fallbacks get to compare anything against an empty string, and validateSession() offers integrate_reauthenticate so such a member is not simply locked out of the admin areas. Nothing here creates such an account yet. Adds a member_auth table for whatever credentials those accounts sign in with, dropped along with the member, and a login form slot that renders the methods registered through integrate_authentication_methods. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Migrations can say whether they still apply, and the upgrader reports the step as skipped when they do not, which keeps a re-run honest instead of relying on create() quietly ignoring the table it finds. Compares against Config::$db_prefix rather than Db::$db->prefix, since the latter is database qualified while list_tables() reports bare names, and so would never match. That same mismatch is why Table::exists() is no use here either. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Adds sign in with an external identity provider, so a forum can hand authentication to Google, Microsoft, Keycloak, Authentik or anything else that speaks the protocol, rather than being the only thing that knows a member's password. Uses the authorization code flow with PKCE and a confidential client. The ID token is read from the response to our own back channel POST to the token endpoint, over TLS with the certificate verified and the client authenticated, which is the case OpenID Connect Core 3.1.3.7 item 6 allows signature validation to be skipped in. That is why the certificate check in OidcClient::fetch() is not optional, and why the token is never taken from the redirect. Doing it this way keeps JWKS handling, and a hard dependency on openssl that SMF does not currently have, out of it entirely. Deliberately does not go through WebFetchApi. That cannot set request headers, which the token and userinfo endpoints need, and it rewrites the host to a literal IP, which defeats the certificate check. CurlFetcher would allow headers but defaults to CURLOPT_SSL_VERIFYPEER false, which is not something to inherit for a token exchange. Whose account a sign in belongs to is decided narrowly. The provider's subject claim is the key and email never is, unless an admin turns that on per provider and the provider states the address is verified; otherwise anyone able to get an address issued there could walk into the account using it here. Somebody with no account is handed to the ordinary sign up form rather than having one made for them, so the agreement, the privacy policy, COPPA and admin approval all still apply, and the credential is attached once that finishes. Members manage their own links from their profile, where the last one cannot be removed while it is the only way they can get in. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Every directory carries one, and check-smf-index.php enforces it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Feature series: external authentication, part 2 of 3. These belong together and are
not bug fixes:
This branch contains part 1's commits, because GitHub cannot base a PR on a branch that
lives in a fork. Review the last commit only, or wait for #9381 to merge and this will
reduce to it. Part 3 does not depend on this one; both sit on part 1.
Lets a forum hand authentication to an external identity provider instead of being the only
thing that knows a member's password. An admin adds a provider, the login form grows a
button for it, and members manage their own links from their profile.
Protocol. Authorization code flow with PKCE and a confidential client. The ID token is
read from the response to our own back channel POST to the token endpoint, over TLS with the
certificate verified and the client authenticated — the case OpenID Connect Core §3.1.3.7
item 6 allows signature validation to be skipped in. That is why the certificate check in
OidcClient::fetch()is not optional and why the token is never taken from the redirect. Itkeeps JWKS handling, and a hard dependency on
opensslthat SMF does not currently have,out of this entirely. No new composer dependency.
iss,aud,azp,expandnonceare all checked,stateis checked against thesession and cleared on use, and the discovery document's
issuermust agree with theconfigured one.
Why not
WebFetchApi. It cannot set request headers, which the token and userinfoendpoints need, and
makeSafe()rewrites the host to a literal IP, which defeats thecertificate check.
CurlFetcherallows headers but defaults toCURLOPT_SSL_VERIFYPEER => false, which is not something to inherit for a token exchange.So the handful of options that matter are set explicitly instead of destabilising a fetcher
that avatars and the proxy also use.
Who a sign in belongs to — the decisions that matter more than the code:
subis the key. Email never is, unless an admin turns it on per providerand the provider says
email_verified; otherwise anyone who can get an address issuedthere could walk into the account that uses it here. Off by default.
created for them, so the agreement, privacy policy, COPPA and admin approval all still
apply. The credential is attached once that finishes.
Testing. Run against a real Keycloak on the compose network, driving the whole thing as
a browser would: the login form offers the provider; the redirect carries
response_type,client_id,state,nonceand an S256code_challenge; the provider's own login formauthenticates; the callback exchanges the code and validates the claims. First run with no
matching account lands on the sign up form; after linking the subject to a member, the same
round trip ends logged in, through part 1's
Login2::completeLogin().Refusals were tested too, all five correct: no code or state, a state we never issued, a
code with no state, a provider-reported error, and replaying a state that was already used.
Credential::remove()refuses to take the last credential from an account with no passwordand allows it once there is one. Part 1's 14-check login regression suite still passes
unchanged. Provider table verified on MySQL and PostgreSQL.
Two things caught by testing rather than review, both fixed here:
Provider::__construct()merged saved settings with+, which keeps the left operand and so silently discardedevery saved setting; and the callback needed the
statecleared before use to stop replay.Issues References (Fixes|Related|Closes)