From cb490bc83d0466a97d67c99ab31e54888aa1a4c8 Mon Sep 17 00:00:00 2001 From: aina-esokia Date: Wed, 16 Jan 2019 12:27:24 +0400 Subject: [PATCH] use const on call --- lib/classes/API/OAuth2/Adapter.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/classes/API/OAuth2/Adapter.php b/lib/classes/API/OAuth2/Adapter.php index e64e258b1d..4de6639d4d 100644 --- a/lib/classes/API/OAuth2/Adapter.php +++ b/lib/classes/API/OAuth2/Adapter.php @@ -537,7 +537,9 @@ class API_OAuth2_Adapter extends OAuth2 public function verifyAccessToken($scope = null, $exit_not_present = true, $exit_invalid = true, $exit_expired = true, $exit_scope = true, $realm = null) { - $useTokenHeader = $this->app['conf']->get(['main', 'api_token_header']); + $apiTokenHeader = $this->app['conf']->get(['main', 'api_token_header']); + + $useTokenHeader = $this->useTokenHeaderChoice($apiTokenHeader); $token_param = $this->getAccessTokenParams($useTokenHeader); @@ -810,4 +812,21 @@ class API_OAuth2_Adapter extends OAuth2 return false; } } + + /** + * Get the correct constante to call on Oauth2 + * + * @param $apiTokenHeader + * @return string + */ + private function useTokenHeaderChoice($apiTokenHeader) + { + if ($apiTokenHeader === true) { + return Oauth2::TOKEN_ONLY_IN_HEADER; + } elseif ($apiTokenHeader === false) { + return Oauth2::TOKEN_ONLY_IN_GETPOST; + } else { + return Oauth2::TOKEN_AUTO_FIND; + } + } }