Skip to content

Commit

Permalink
Support Google Cloud IAP (#8768)
Browse files Browse the repository at this point in the history
Following up on 7c2da81,
this extends the logic, adding support for Google Cloud IAP.
  • Loading branch information
giannello committed Feb 3, 2021
1 parent c40b833 commit 5edbb4b
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,26 @@ private function loginViaRemoteUser(Request $request)
if (Setting::getSettings()->login_remote_user_enabled == "1" && isset($remote_user) && !empty($remote_user)) {
Log::debug("Authenticating via HTTP header $header_name.");

$pos = strpos($remote_user, '\\');
$strip_prefixes = [
// IIS/AD
// https://github.com/snipe/snipe-it/pull/5862
'\\',

// Google Cloud IAP
// https://cloud.google.com/iap/docs/identity-howto#getting_the_users_identity_with_signed_headers
'accounts.google.com:',
];

$pos = 0;
foreach ($strip_prefixes as $needle) {
if (($pos = strpos($remote_user, $needle)) !== FALSE) {
$pos += strlen($needle);
break;
}
}

if ($pos > 0) {
$remote_user = substr($remote_user, $pos + 1);
$remote_user = substr($remote_user, $pos);
};

try {
Expand Down

0 comments on commit 5edbb4b

Please sign in to comment.