Skip to content

Commit ef3eb21

Browse files
Merge pull request #32 from JustinByrne/master
Changing fail() error handling to support an array of errors
2 parents f872b07 + 603364a commit ef3eb21

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Azure.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,20 @@ protected function success(Request $request, $access_token, $refresh_token, $pro
186186
*/
187187
protected function fail(Request $request, \Exception $e)
188188
{
189-
// Added by smitthhyy 18Dec2019 - Return 403 if user authenticates in AD but is not assigned to this application
190-
if ($request->isMethod('get')) {
191-
$errorDescription = trim(substr($request->query('error_description', 'SOMETHING_ELSE'), 0, 11));
192-
if($errorDescription == "AADSTS50105") {
193-
abort(403, "User is not authorisied within Azure AD to access this application.");
194-
}
189+
// JustinByrne updated the original code from smitthhyy (18 Dec 2019) to change to an array to allow for multiple error codes.
190+
$azureErrors = [
191+
'AADSTS50105' => [
192+
'HTTP_CODE' => '403',
193+
'msg' => 'User is not authorised within Azure AD to access this application.',
194+
],
195+
'AADSTS90072' => [
196+
'HTTP_CODE' => '403',
197+
'msg' => 'The logged on User is not in the allowed Tenant. Log in with a User in the allowed Tenant.',
198+
],
199+
];
200+
201+
if (array_key_exists($errorDescription, $azureErrors)) {
202+
return abort($azureErrors[$errorDescription]['HTTP_CODE'], $azureErrors[$errorDescription]['msg']);
195203
}
196204

197205
return implode("", explode(PHP_EOL, $e->getMessage()));

0 commit comments

Comments
 (0)