Skip to content

Commit 34ffe6f

Browse files
committed
chore: add tenant to auth request (OIDC)
1 parent 31eb023 commit 34ffe6f

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

app/Strategies/DisplayResponseUserAgentStrategy.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
**/
1414

1515
use App\libs\Auth\SocialLoginProviders;
16+
use Illuminate\Support\Facades\Log;
1617
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
1718
use Illuminate\Support\Facades\Response;
1819
use Illuminate\Support\Facades\Redirect;
@@ -40,11 +41,12 @@ public function getConsentResponse(array $data = [])
4041
public function getLoginResponse(array $data = [])
4142
{
4243
$provider = $data["provider"] ?? null;
43-
44+
$provided_tenant = $data["tenant"] ?? '';
45+
Log::debug("OAuth2LoginStrategy::getLogin", ['provider' => $provider , 'provided_tenant' => $provided_tenant]);
4446
if(!empty($provider)) {
4547
return redirect()->route('social_login', ['provider' => $provider]);
4648
}
47-
$data['supported_providers'] = SocialLoginProviders::buildSupportedProviders();
49+
$data['supported_providers'] = SocialLoginProviders::buildSupportedProviders($provided_tenant);
4850
return Response::view("auth.login", $data, 200);
4951
}
5052

app/Strategies/OAuth2LoginStrategy.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
use App\libs\OAuth2\Strategies\ILoginHintProcessStrategy;
1616
use Illuminate\Support\Facades\Auth;
1717
use Illuminate\Support\Facades\Log;
18+
use OAuth2\Endpoints\AuthorizationEndpoint;
1819
use OAuth2\Factories\OAuth2AuthorizationRequestFactory;
1920
use OAuth2\OAuth2Message;
2021
use OAuth2\Requests\OAuth2AuthenticationRequest;
22+
use OAuth2\Requests\OAuth2AuthorizationRequest;
2123
use OAuth2\Services\IMementoOAuth2SerializerService;
2224
use Services\IUserActionService;
2325
use Utils\IPHelper;
@@ -52,12 +54,12 @@ public function __construct
5254
)
5355
{
5456
parent::__construct($user_action_service, $auth_service, $login_hint_process_strategy);
55-
$this->memento_service = $memento_service;
57+
$this->memento_service = $memento_service;
5658
}
5759

5860
public function getLogin()
5961
{
60-
Log::debug(sprintf("OAuth2LoginStrategy::getLogin"));
62+
Log::debug("OAuth2LoginStrategy::getLogin");
6163

6264
if (!Auth::guest())
6365
return Redirect::action("UserController@getProfile");
@@ -70,10 +72,13 @@ public function getLogin()
7072
)
7173
);
7274

75+
Log::debug("OAuth2LoginStrategy::getLogin", ['auth_request' => (string)$auth_request ]);
76+
7377
$response_strategy = DisplayResponseStrategyFactory::build($auth_request->getDisplay());
7478

7579
return $response_strategy->getLoginResponse([
76-
'provider' => $auth_request instanceof OAuth2AuthenticationRequest ? $auth_request->getProvider() : null
80+
'provider' => $auth_request instanceof OAuth2AuthenticationRequest ? $auth_request->getProvider() : null,
81+
'tenant' => $auth_request instanceof OAuth2AuthorizationRequest ? $auth_request->getTenant() : null
7782
]);
7883
}
7984

app/libs/Auth/SocialLoginProviders.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ public static function isSupportedProvider(string $provider): bool
4848
}
4949

5050
/**
51-
* @return string[]
51+
* @param string $provided_tenant
52+
* @return array
5253
*/
53-
public static function buildSupportedProviders(): array
54+
public static function buildSupportedProviders(string $provided_tenant = ''): array
5455
{
56+
Log::debug("SocialLoginProviders::buildSupportedProviders", ["provided_tenant" => $provided_tenant]);
5557
$res = [];
56-
$tenant = trim(Request::get('tenant', ''));
58+
$tenant = trim(Request::get('tenant', $provided_tenant));
5759
$allowed_3rd_party_providers = self::toList(
5860
Config::get("tenants.$tenant.allowed_3rd_party_providers", '')
5961
);

app/libs/OAuth2/OAuth2Protocol.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ final class OAuth2Protocol implements IOAuth2Protocol
147147
self::OAuth2Protocol_ResponseMode_Direct
148148
);
149149

150+
/**
151+
* custom param
152+
*/
153+
const Tenant = 'tenant';
154+
150155
/**
151156
* http://openid.net/specs/oauth-v2-multiple-response-types-1_0.html#ResponseModes
152157
*

app/libs/OAuth2/Requests/OAuth2AuthorizationRequest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,4 +232,8 @@ public function getCodeChallenge():?string{
232232
public function getCodeChallengeMethod():?string{
233233
return $this->getParam(OAuth2Protocol::PKCE_CodeChallengeMethod);
234234
}
235+
236+
public function getTenant():?string{
237+
return $this->getParam(OAuth2Protocol::Tenant);
238+
}
235239
}

0 commit comments

Comments
 (0)