From f43bcbd06f34ad09bad090a49a76dbe432939d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Lundb=C3=B8l?= Date: Mon, 4 Feb 2019 14:43:56 +0100 Subject: [PATCH] Allow a state to be passed. --- src/Client.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Client.php b/src/Client.php index 97b9cbc..c6098dc 100644 --- a/src/Client.php +++ b/src/Client.php @@ -289,9 +289,10 @@ public function getAccessToken(): ?AccessToken * Get the url to redirect users to when setting up a salesforce access token * * @param string $redirectUrl + * @param string|null $state * @return string */ - public function getLoginUrl(string $redirectUrl): string + public function getLoginUrl(string $redirectUrl, ?string $state = null): string { $params = [ 'client_id' => $this->clientConfig->getClientId(), @@ -300,7 +301,12 @@ public function getLoginUrl(string $redirectUrl): string 'grant_type' => 'authorization_code' ]; - return rtrim($this->clientConfig->getLoginUrl(), '/') . '/services/oauth2/authorize?' . http_build_query($params); + if (null !== $state) { + $params['state'] = $state; + } + + return rtrim($this->clientConfig->getLoginUrl(), '/') . '/services/oauth2/authorize?' . + http_build_query($params, '', '&', PHP_QUERY_RFC1738); } /**