From 64b9edca191c9a9467c95f9969db9263f40bf04c Mon Sep 17 00:00:00 2001 From: Sander de Vos Date: Wed, 20 Mar 2019 09:26:10 +0100 Subject: [PATCH] Format the callback URI, resolving a relative URI if needed --- composer.json | 3 ++- src/Config.php | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 1705e52..ca4bdb7 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ }], "require": { "php": "^5.6 || ^7.0", - "laravel/socialite": "~3.0|~4.0" + "laravel/socialite": "~3.0|~4.0", + "illuminate/support": "~5.4|~5.7.0|~5.8.0" }, "require-dev": { "phpunit/phpunit": "^5.0", diff --git a/src/Config.php b/src/Config.php index acba673..f7e7163 100644 --- a/src/Config.php +++ b/src/Config.php @@ -2,6 +2,9 @@ namespace SocialiteProviders\Manager; +use Illuminate\Support\Str; +use Illuminate\Support\Facades\URL; + class Config implements Contracts\ConfigInterface { /** @@ -22,10 +25,23 @@ public function __construct($key, $secret, $callbackUri, array $additionalProvid $this->config = array_merge([ 'client_id' => $key, 'client_secret' => $secret, - 'redirect' => $callbackUri, + 'redirect' => $this->formatRedirectUri($callbackUri), ], $additionalProviderConfig); } + /** + * Format the callback URI, resolving a relative URI if needed. + * + * @param string $callbackUri + * @return string + */ + protected function formatRedirectUri(string $callbackUri) + { + return Str::startsWith($callbackUri, '/') + ? URL::to($callbackUri) + : $callbackUri; + } + /** * @return array */