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 
137  public $failReasons = null;
138 
144  public static function newPass( $username = null ) {
145  $ret = new AuthenticationResponse;
146  $ret->status = self::PASS;
147  $ret->username = $username;
148  return $ret;
149  }
150 
157  public static function newFail( Message $msg, array $failReasons = [] ) {
158  $ret = new AuthenticationResponse;
159  $ret->status = self::FAIL;
160  $ret->message = $msg;
161  $ret->messageType = 'error';
162  $ret->failReasons = $failReasons;
163  return $ret;
164  }
165 
171  public static function newRestart( Message $msg ) {
172  $ret = new AuthenticationResponse;
173  $ret->status = self::RESTART;
174  $ret->message = $msg;
175  return $ret;
176  }
177 
182  public static function newAbstain() {
183  $ret = new AuthenticationResponse;
184  $ret->status = self::ABSTAIN;
185  return $ret;
186  }
187 
195  public static function newUI( array $reqs, Message $msg, $msgtype = 'warning' ) {
196  if ( !$reqs ) {
197  throw new \InvalidArgumentException( '$reqs may not be empty' );
198  }
199  if ( $msgtype !== 'warning' && $msgtype !== 'error' ) {
200  throw new \InvalidArgumentException( $msgtype . ' is not a valid message type.' );
201  }
202 
203  $ret = new AuthenticationResponse;
204  $ret->status = self::UI;
205  $ret->neededRequests = $reqs;
206  $ret->message = $msg;
207  $ret->messageType = $msgtype;
208  return $ret;
209  }
210 
218  public static function newRedirect( array $reqs, $redirectTarget, $redirectApiData = null ) {
219  if ( !$reqs ) {
220  throw new \InvalidArgumentException( '$reqs may not be empty' );
221  }
222 
223  $ret = new AuthenticationResponse;
224  $ret->status = self::REDIRECT;
225  $ret->neededRequests = $reqs;
226  $ret->redirectTarget = $redirectTarget;
227  $ret->redirectApiData = $redirectApiData;
228  return $ret;
229  }
230 
231 }
This is a value object to hold authentication response data.
const FAIL
Indicates that the authentication failed.
const PASS
Indicates that the authentication succeeded.
static newFail(Message $msg, array $failReasons=[])
string null $username
Local user name from authentication.
string null $redirectTarget
URL to redirect to for a REDIRECT response.
AuthenticationRequest null $linkRequest
When returned with a PrimaryAuthenticationProvider login PASS with no username, the request this hold...
const UI
Indicates that the authentication needs further user input of some sort.
static newRedirect(array $reqs, $redirectTarget, $redirectApiData=null)
AuthenticationRequest[] $neededRequests
Needed AuthenticationRequests to continue after a UI or REDIRECT response.
const REDIRECT
Indicates that the authentication needs to be redirected to a third party to proceed.
string $status
One of the constants above.
const ABSTAIN
Indicates that the authentication provider does not handle this request.
Message null $message
I18n message to display in case of UI or FAIL.
mixed $redirectApiData
Data for a REDIRECT response that a client might use to query the remote site via its API rather than...
AuthenticationRequest null $loginRequest
Returned with an AuthManager account creation PASS, this holds a request to pass to AuthManager::begi...
string $messageType
Whether the $message is an error or warning message, for styling reasons.
string[] null $failReasons
String data that is optionally provided on a FAIL.
AuthenticationRequest null $createRequest
Returned with a PrimaryAuthenticationProvider login FAIL or a PASS with no username,...
static newUI(array $reqs, Message $msg, $msgtype='warning')
const RESTART
Indicates that third-party authentication succeeded but no user exists.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:140