MediaWiki master
AuthenticationResponse.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Auth;
8
9use InvalidArgumentException;
11
23 public const PASS = 'PASS';
24
26 public const FAIL = 'FAIL';
27
33 public const RESTART = 'RESTART';
34
36 public const ABSTAIN = 'ABSTAIN';
37
39 public const UI = 'UI';
40
42 public const REDIRECT = 'REDIRECT';
43
45 public $status;
46
48 public $redirectTarget = null;
49
55 public $redirectApiData = null;
56
63 public $neededRequests = [];
64
66 public $message = null;
67
69 public $messageType = 'warning';
70
75 public $username = null;
76
93 public $createRequest = null;
94
103 public $linkRequest = null;
104
111 public $loginRequest = null;
112
121 public $failReasons = null;
122
128 public static function newPass( $username = null ) {
129 $ret = new AuthenticationResponse;
130 $ret->status = self::PASS;
131 $ret->username = $username;
132 return $ret;
133 }
134
141 public static function newFail( Message $msg, array $failReasons = [] ) {
142 $ret = new AuthenticationResponse;
143 $ret->status = self::FAIL;
144 $ret->message = $msg;
145 $ret->messageType = 'error';
146 $ret->failReasons = $failReasons;
147 return $ret;
148 }
149
155 public static function newRestart( Message $msg ) {
156 $ret = new AuthenticationResponse;
157 $ret->status = self::RESTART;
158 $ret->message = $msg;
159 return $ret;
160 }
161
166 public static function newAbstain() {
167 $ret = new AuthenticationResponse;
168 $ret->status = self::ABSTAIN;
169 return $ret;
170 }
171
179 public static function newUI( array $reqs, Message $msg, $msgtype = 'warning' ) {
180 if ( !$reqs ) {
181 throw new InvalidArgumentException( '$reqs may not be empty' );
182 }
183 if ( $msgtype !== 'warning' && $msgtype !== 'error' ) {
184 throw new InvalidArgumentException( $msgtype . ' is not a valid message type.' );
185 }
186
187 $ret = new AuthenticationResponse;
188 $ret->status = self::UI;
189 $ret->neededRequests = $reqs;
190 $ret->message = $msg;
191 $ret->messageType = $msgtype;
192 return $ret;
193 }
194
202 public static function newRedirect( array $reqs, $redirectTarget, $redirectApiData = null ) {
203 if ( !$reqs ) {
204 throw new InvalidArgumentException( '$reqs may not be empty' );
205 }
206
207 $ret = new AuthenticationResponse;
208 $ret->status = self::REDIRECT;
209 $ret->neededRequests = $reqs;
210 $ret->redirectTarget = $redirectTarget;
211 $ret->redirectApiData = $redirectApiData;
212 return $ret;
213 }
214
215}
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:144