MediaWiki master
AuthenticationResponse.php
Go to the documentation of this file.
1<?php
24namespace MediaWiki\Auth;
25
26use InvalidArgumentException;
28
40 public const PASS = 'PASS';
41
43 public const FAIL = 'FAIL';
44
50 public const RESTART = 'RESTART';
51
53 public const ABSTAIN = 'ABSTAIN';
54
56 public const UI = 'UI';
57
59 public const REDIRECT = 'REDIRECT';
60
62 public $status;
63
65 public $redirectTarget = null;
66
72 public $redirectApiData = null;
73
80 public $neededRequests = [];
81
83 public $message = null;
84
86 public $messageType = 'warning';
87
92 public $username = null;
93
110 public $createRequest = null;
111
120 public $linkRequest = null;
121
128 public $loginRequest = null;
129
138 public $failReasons = null;
139
145 public static function newPass( $username = null ) {
146 $ret = new AuthenticationResponse;
147 $ret->status = self::PASS;
148 $ret->username = $username;
149 return $ret;
150 }
151
158 public static function newFail( Message $msg, array $failReasons = [] ) {
159 $ret = new AuthenticationResponse;
160 $ret->status = self::FAIL;
161 $ret->message = $msg;
162 $ret->messageType = 'error';
163 $ret->failReasons = $failReasons;
164 return $ret;
165 }
166
172 public static function newRestart( Message $msg ) {
173 $ret = new AuthenticationResponse;
174 $ret->status = self::RESTART;
175 $ret->message = $msg;
176 return $ret;
177 }
178
183 public static function newAbstain() {
184 $ret = new AuthenticationResponse;
185 $ret->status = self::ABSTAIN;
186 return $ret;
187 }
188
196 public static function newUI( array $reqs, Message $msg, $msgtype = 'warning' ) {
197 if ( !$reqs ) {
198 throw new InvalidArgumentException( '$reqs may not be empty' );
199 }
200 if ( $msgtype !== 'warning' && $msgtype !== 'error' ) {
201 throw new InvalidArgumentException( $msgtype . ' is not a valid message type.' );
202 }
203
204 $ret = new AuthenticationResponse;
205 $ret->status = self::UI;
206 $ret->neededRequests = $reqs;
207 $ret->message = $msg;
208 $ret->messageType = $msgtype;
209 return $ret;
210 }
211
219 public static function newRedirect( array $reqs, $redirectTarget, $redirectApiData = null ) {
220 if ( !$reqs ) {
221 throw new InvalidArgumentException( '$reqs may not be empty' );
222 }
223
224 $ret = new AuthenticationResponse;
225 $ret->status = self::REDIRECT;
226 $ret->neededRequests = $reqs;
227 $ret->redirectTarget = $redirectTarget;
228 $ret->redirectApiData = $redirectApiData;
229 return $ret;
230 }
231
232}
This is a value object for authentication requests.
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 username 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:157