Skip to content

Commit 1750e6f

Browse files
author
Dan Jewett
committed
* 'master' of https://github.com/rootinc/laravel-azure-middleware: returned missing code to get error description Changed fail error handling to an array Fix typo
2 parents cbeff74 + 0320fe5 commit 1750e6f

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/Azure.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,23 @@ 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')) {
189+
// JustinByrne updated the original code from smitthhyy (18 Dec 2019) to change to an array to allow for multiple error codes.
190+
if ($request->isMethod('get')) {
191191
$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.");
192+
193+
$azureErrors = [
194+
'AADSTS50105' => [
195+
'HTTP_CODE' => '403',
196+
'msg' => 'User is not authorized within Azure AD to access this application.',
197+
],
198+
'AADSTS90072' => [
199+
'HTTP_CODE' => '403',
200+
'msg' => 'The logged on User is not in the allowed Tenant. Log in with a User in the allowed Tenant.',
201+
],
202+
];
203+
204+
if (array_key_exists($errorDescription, $azureErrors)) {
205+
return abort($azureErrors[$errorDescription]['HTTP_CODE'], $azureErrors[$errorDescription]['msg']);
194206
}
195207
}
196208

0 commit comments

Comments
 (0)