MediaWiki  master
AuthenticationResponse.php
Go to the documentation of this file.
1 <?php
24 namespace MediaWiki\Auth;
25 
26 use Message;
27 
39  public const PASS = 'PASS';
40 
42  public const FAIL = 'FAIL';
43 
49  public const RESTART = 'RESTART';
50 
52  public const ABSTAIN = 'ABSTAIN';
53 
55  public const UI = 'UI';
56 
58  public const REDIRECT = 'REDIRECT';
59 
61  public $status;
62 
64  public $redirectTarget = null;
65 
71  public $redirectApiData = null;
72 
79  public $neededRequests = [];
80 
82  public $message = null;
83 
85  public $messageType = 'warning';
86 
91  public $username = null;
92 
109  public $createRequest = null;
110 
119  public $linkRequest = null;
120 
127  public $loginRequest = null;
128 
134  public static function newPass( $username = null ) {
135  $ret = new AuthenticationResponse;
136  $ret->status = self::PASS;
137  $ret->username = $username;
138  return $ret;
139  }
140 
146  public static function newFail( Message $msg ) {
147  $ret = new AuthenticationResponse;
148  $ret->status = self::FAIL;
149  $ret->message = $msg;
150  $ret->messageType = 'error';
151  return $ret;
152  }
153 
159  public static function newRestart( Message $msg ) {
160  $ret = new AuthenticationResponse;
161  $ret->status = self::RESTART;
162  $ret->message = $msg;
163  return $ret;
164  }
165 
170  public static function newAbstain() {
171  $ret = new AuthenticationResponse;
172  $ret->status = self::ABSTAIN;
173  return $ret;
174  }
175 
183  public static function newUI( array $reqs, Message $msg, $msgtype = 'warning' ) {
184  if ( !$reqs ) {
185  throw new \InvalidArgumentException( '$reqs may not be empty' );
186  }
187  if ( $msgtype !== 'warning' && $msgtype !== 'error' ) {
188  throw new \InvalidArgumentException( $msgtype . ' is not a valid message type.' );
189  }
190 
191  $ret = new AuthenticationResponse;
192  $ret->status = self::UI;
193  $ret->neededRequests = $reqs;
194  $ret->message = $msg;
195  $ret->messageType = $msgtype;
196  return $ret;
197  }
198 
206  public static function newRedirect( array $reqs, $redirectTarget, $redirectApiData = null ) {
207  if ( !$reqs ) {
208  throw new \InvalidArgumentException( '$reqs may not be empty' );
209  }
210 
211  $ret = new AuthenticationResponse;
212  $ret->status = self::REDIRECT;
213  $ret->neededRequests = $reqs;
214  $ret->redirectTarget = $redirectTarget;
215  $ret->redirectApiData = $redirectApiData;
216  return $ret;
217  }
218 
219 }
MediaWiki\Auth\AuthenticationResponse\RESTART
const RESTART
Indicates that third-party authentication succeeded but no user exists.
Definition: AuthenticationResponse.php:49
MediaWiki\Auth\AuthenticationResponse\$message
Message null $message
I18n message to display in case of UI or FAIL.
Definition: AuthenticationResponse.php:82
MediaWiki\Auth\AuthenticationResponse\newAbstain
static newAbstain()
Definition: AuthenticationResponse.php:170
MediaWiki\Auth\AuthenticationResponse\UI
const UI
Indicates that the authentication needs further user input of some sort.
Definition: AuthenticationResponse.php:55
MediaWiki\Auth\AuthenticationResponse\$loginRequest
AuthenticationRequest null $loginRequest
Returned with an AuthManager account creation PASS, this holds a request to pass to AuthManager::begi...
Definition: AuthenticationResponse.php:127
MediaWiki\Auth\AuthenticationResponse\REDIRECT
const REDIRECT
Indicates that the authentication needs to be redirected to a third party to proceed.
Definition: AuthenticationResponse.php:58
MediaWiki\Auth\AuthenticationResponse
This is a value object to hold authentication response data.
Definition: AuthenticationResponse.php:37
MediaWiki\Auth\AuthenticationResponse\ABSTAIN
const ABSTAIN
Indicates that the authentication provider does not handle this request.
Definition: AuthenticationResponse.php:52
MediaWiki\Auth\AuthenticationResponse\$redirectTarget
string null $redirectTarget
URL to redirect to for a REDIRECT response.
Definition: AuthenticationResponse.php:64
MediaWiki\Auth\AuthenticationResponse\FAIL
const FAIL
Indicates that the authentication failed.
Definition: AuthenticationResponse.php:42
MediaWiki\Auth\AuthenticationResponse\$messageType
string $messageType
Whether the $message is an error or warning message, for styling reasons.
Definition: AuthenticationResponse.php:85
MediaWiki\Auth\AuthenticationResponse\$linkRequest
AuthenticationRequest null $linkRequest
When returned with a PrimaryAuthenticationProvider login PASS with no username, the request this hold...
Definition: AuthenticationResponse.php:119
MediaWiki\Auth\AuthenticationResponse\$username
string null $username
Local user name from authentication.
Definition: AuthenticationResponse.php:91
MediaWiki\Auth\AuthenticationResponse\$createRequest
AuthenticationRequest null $createRequest
Returned with a PrimaryAuthenticationProvider login FAIL or a PASS with no username,...
Definition: AuthenticationResponse.php:109
MediaWiki\Auth\AuthenticationResponse\newFail
static newFail(Message $msg)
Definition: AuthenticationResponse.php:146
MediaWiki\Auth\AuthenticationResponse\newRedirect
static newRedirect(array $reqs, $redirectTarget, $redirectApiData=null)
Definition: AuthenticationResponse.php:206
MediaWiki\Auth\AuthenticationResponse\$status
string $status
One of the constants above.
Definition: AuthenticationResponse.php:61
Message
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:161
MediaWiki\Auth\AuthenticationResponse\PASS
const PASS
Indicates that the authentication succeeded.
Definition: AuthenticationResponse.php:39
MediaWiki\Auth\AuthenticationResponse\newRestart
static newRestart(Message $msg)
Definition: AuthenticationResponse.php:159
MediaWiki\Auth
Definition: AbstractAuthenticationProvider.php:22
MediaWiki\Auth\AuthenticationResponse\newPass
static newPass( $username=null)
Definition: AuthenticationResponse.php:134
MediaWiki\Auth\AuthenticationResponse\newUI
static newUI(array $reqs, Message $msg, $msgtype='warning')
Definition: AuthenticationResponse.php:183
MediaWiki\Auth\AuthenticationResponse\$redirectApiData
mixed $redirectApiData
Data for a REDIRECT response that a client might use to query the remote site via its API rather than...
Definition: AuthenticationResponse.php:71
MediaWiki\Auth\AuthenticationRequest
This is a value object for authentication requests.
Definition: AuthenticationRequest.php:38
MediaWiki\Auth\AuthenticationResponse\$neededRequests
AuthenticationRequest[] $neededRequests
Needed AuthenticationRequests to continue after a UI or REDIRECT response.
Definition: AuthenticationResponse.php:79