3 * Authentication plugin interface
5 * Copyright © 2004 Brion Vibber <brion@pobox.com>
6 * https://www.mediawiki.org/
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
27 * Authentication plugin interface. Instantiate a subclass of AuthPlugin
28 * and set $wgAuth to it to authenticate against some external tool.
30 * The default behavior is not to do anything, and use the local user
31 * database for all authentication. A subclass can require that all
32 * accounts authenticate externally, or use it only as a fallback; also
33 * you can transparently create internal wiki accounts the first time
34 * someone logs in who can be authenticated externally.
36 * @deprecated since 1.27
45 * Check whether there exists a user account with the given name.
46 * The name will be normalized to MediaWiki's requirements, so
47 * you might need to munge it (for instance, for lowercase initial
50 * @param string $username Username.
53 public function userExists( $username ) {
59 * Check if a username+password pair is a valid login.
60 * The name will be normalized to MediaWiki's requirements, so
61 * you might need to munge it (for instance, for lowercase initial
64 * @param string $username Username.
65 * @param string $password User password.
68 public function authenticate( $username, $password ) {
74 * Modify options in the login template.
76 * @param UserLoginTemplate $template
77 * @param string $type 'signup' or 'login'. Added in 1.16.
79 public function modifyUITemplate( &$template, &$type ) {
81 $template->set( 'usedomain', false );
85 * Set the domain this plugin is supposed to use when authenticating.
87 * @param string $domain Authentication domain.
89 public function setDomain( $domain ) {
90 $this->domain
= $domain;
94 * Get the user's domain
98 public function getDomain() {
99 if ( isset( $this->domain
) ) {
100 return $this->domain
;
102 return 'invaliddomain';
107 * Check to see if the specific domain is a valid domain.
109 * @param string $domain Authentication domain.
112 public function validDomain( $domain ) {
118 * When a user logs in, optionally fill in preferences and such.
119 * For instance, you might pull the email address or real name from the
120 * external user database.
122 * The User object is passed by reference so it can be modified; don't
123 * forget the & on your function declaration.
125 * @deprecated since 1.26, use the UserLoggedIn hook instead. And assigning
126 * a different User object to $user is no longer supported.
130 public function updateUser( &$user ) {
131 # Override this and do something
136 * Return true if the wiki should create a new local account automatically
137 * when asked to login a user who doesn't exist locally but does in the
138 * external auth database.
140 * If you don't automatically create accounts, you must still create
141 * accounts in some way. It's not possible to authenticate without
144 * This is just a question, and shouldn't perform any actions.
148 public function autoCreate() {
153 * Allow a property change? Properties are the same as preferences
154 * and use the same keys. 'Realname' 'Emailaddress' and 'Nickname'
155 * all reference this.
157 * @param string $prop
161 public function allowPropChange( $prop = '' ) {
162 if ( $prop == 'realname' && is_callable( [ $this, 'allowRealNameChange' ] ) ) {
163 return $this->allowRealNameChange();
164 } elseif ( $prop == 'emailaddress' && is_callable( [ $this, 'allowEmailChange' ] ) ) {
165 return $this->allowEmailChange();
166 } elseif ( $prop == 'nickname' && is_callable( [ $this, 'allowNickChange' ] ) ) {
167 return $this->allowNickChange();
174 * Can users change their passwords?
178 public function allowPasswordChange() {
183 * Should MediaWiki store passwords in its local database?
187 public function allowSetLocalPassword() {
192 * Set the given password in the authentication database.
193 * As a special case, the password may be set to null to request
194 * locking the password to an unusable value, with the expectation
195 * that it will be set later through a mail reset or other method.
197 * Return true if successful.
200 * @param string $password Password.
203 public function setPassword( $user, $password ) {
208 * Update user information in the external authentication database.
209 * Return true if successful.
211 * @deprecated since 1.26, use the UserSaveSettings hook instead.
215 public function updateExternalDB( $user ) {
220 * Update user groups in the external authentication database.
221 * Return true if successful.
223 * @deprecated since 1.26, use the UserGroupsChanged hook instead.
225 * @param array $addgroups Groups to add.
226 * @param array $delgroups Groups to remove.
229 public function updateExternalDBGroups( $user, $addgroups, $delgroups = [] ) {
234 * Check to see if external accounts can be created.
235 * Return true if external accounts can be created.
238 public function canCreateAccounts() {
243 * Add a user to the external authentication database.
244 * Return true if successful.
246 * @param User $user Only the name should be assumed valid at this point
247 * @param string $password
248 * @param string $email
249 * @param string $realname
252 public function addUser( $user, $password, $email = '', $realname = '' ) {
257 * Return true to prevent logins that don't authenticate here from being
258 * checked against the local database's password fields.
260 * This is just a question, and shouldn't perform any actions.
264 public function strict() {
269 * Check if a user should authenticate locally if the global authentication fails.
270 * If either this or strict() returns true, local authentication is not used.
272 * @param string $username Username.
275 public function strictUserAuth( $username ) {
280 * When creating a user account, optionally fill in preferences and such.
281 * For instance, you might pull the email address or real name from the
282 * external user database.
284 * The User object is passed by reference so it can be modified; don't
285 * forget the & on your function declaration.
287 * @deprecated since 1.26, use the UserLoggedIn hook instead. And assigning
288 * a different User object to $user is no longer supported.
290 * @param bool $autocreate True if user is being autocreated on login
292 public function initUser( &$user, $autocreate = false ) {
293 # Override this to do something.
297 * If you want to munge the case of an account name before the final
298 * check, now is your chance.
299 * @param string $username
302 public function getCanonicalName( $username ) {
307 * Get an instance of a User object
311 * @return AuthPluginUser
313 public function getUserInstance( User
&$user ) {
314 return new AuthPluginUser( $user );
318 * Get a list of domains (in HTMLForm options format) used.
322 public function domainList() {
328 * @deprecated since 1.27
330 class AuthPluginUser
{
331 function __construct( $user ) {
335 public function getId() {
341 * Indicate whether the user is locked
342 * @deprecated since 1.26, use the UserIsLocked hook instead.
345 public function isLocked() {
351 * Indicate whether the user is hidden
352 * @deprecated since 1.26, use the UserIsHidden hook instead.
355 public function isHidden() {
361 * @deprecated since 1.28, use SessionManager::invalidateSessionForUser() instead.
363 public function resetAuthToken() {