@@ -107,6 +107,61 @@ docker exec "$CONTAINER" test -f "$RUN_PHP" \
107107docker exec " $CONTAINER " test -f " $OAUTH_SCRIPT " \
108108 || die " Extension:OAuth not found at $MW_PATH /extensions/OAuth (install it and enable OAuth2)"
109109
110+ # Extension:OAuth being installed does not make the wiki able to issue OAuth2
111+ # tokens. Registration needs rights that Extension:OAuth grants to nobody by
112+ # default, and the token endpoint needs a signing keypair. Missing either, a
113+ # consumer registered here — or in the browser — is useless, so check before
114+ # provisioning rather than handing back credentials that cannot work.
115+ readiness_php=' $u=User::newFromName("' " $ADMIN_USER " ' ");'
116+ readiness_php+=' $p=MediaWiki\MediaWikiServices::getInstance()->getPermissionManager();'
117+ readiness_php+=' echo "KEYS=".(((string)($GLOBALS["wgOAuth2PrivateKey"]??"")!==""'
118+ readiness_php+=' &&(string)($GLOBALS["wgOAuth2PublicKey"]??"")!=="")?"yes":"no")'
119+ readiness_php+=' ." EMAIL=".($u->getEmail()!==""?"yes":"no")'
120+ readiness_php+=' ." PROPOSE=".($p->userHasRight($u,"mwoauthproposeconsumer")?"yes":"no")'
121+ readiness_php+=' ." APPROVE=".($p->userHasRight($u,"mwoauthmanageconsumer")?"yes":"no")."\n";'
122+ readiness=" $( printf ' %s' " $readiness_php " \
123+ | docker exec -i " $CONTAINER " php " $RUN_PHP " eval 2> /dev/null | tr -d ' \r' ) "
124+
125+ case " $readiness " in
126+ * KEYS=* )
127+ missing=' '
128+ case " $readiness " in * KEYS=no* ) missing=" ${missing} keys " ;; esac
129+ case " $readiness " in * EMAIL=no* ) missing=" ${missing} email " ;; esac
130+ case " $readiness " in * PROPOSE=no* ) missing=" ${missing} propose " ;; esac
131+ case " $readiness " in * APPROVE=no* ) missing=" ${missing} approve " ;; esac
132+ if [ -n " $missing " ]; then
133+ log " This wiki cannot issue OAuth2 tokens yet. Fix the items below, then re-run."
134+ log " "
135+ case " $missing " in * keys* )
136+ log " OAuth2 signing keys are not configured. Generate a keypair:"
137+ log " openssl genrsa -out oauth2.key 2048"
138+ log " openssl rsa -in oauth2.key -pubout -out oauth2.pub"
139+ log " and set \$ wgOAuth2PrivateKey / \$ wgOAuth2PublicKey in LocalSettings.php"
140+ log " to the key text (or to paths the web server user can read)."
141+ log " " ;;
142+ esac
143+ case " $missing " in * propose* |* approve* )
144+ log " ${ADMIN_USER} may not register consumers. Extension:OAuth grants these"
145+ log " to no group by default, so add to LocalSettings.php:"
146+ log " \$ wgGroupPermissions['sysop']['mwoauthproposeconsumer'] = true;"
147+ log " \$ wgGroupPermissions['sysop']['mwoauthmanageconsumer'] = true;"
148+ log " " ;;
149+ esac
150+ case " $missing " in * email* )
151+ log " ${ADMIN_USER} has no email address, which consumer registration requires."
152+ log " Set one at Special:Preferences (or Special:ChangeEmail) on the wiki."
153+ log " " ;;
154+ esac
155+ die " wiki not ready for OAuth2 (missing: ${missing% } )"
156+ fi
157+ ;;
158+ * )
159+ log " warning: could not determine whether this wiki can issue OAuth2 tokens."
160+ log " Continuing; if sign-in later fails, check the OAuth2 signing keys and the"
161+ log " mwoauthproposeconsumer right for ${ADMIN_USER} ."
162+ ;;
163+ esac
164+
110165# --- register consumer (only if the stock CLI supports OAuth2) ---------------
111166# The OAuth2 flags exist only in newer Extension:OAuth. The copy bundled with the
112167# MediaWiki 1.43 LTS ships an OAuth1-only createOAuthConsumer.php, so the consumer
0 commit comments