From f482fcfb1ef699a5639252563bba9367494fca60 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Tue, 22 Oct 2019 10:54:46 +0200 Subject: [PATCH] Clarify method return value and doc-block for getting client credentials: --- .../Authentication/Clients/OAuth_Client.php | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/includes/Core/Authentication/Clients/OAuth_Client.php b/includes/Core/Authentication/Clients/OAuth_Client.php index df7b3d7aaab..5f138826208 100644 --- a/includes/Core/Authentication/Clients/OAuth_Client.php +++ b/includes/Core/Authentication/Clients/OAuth_Client.php @@ -769,28 +769,34 @@ private function get_redirect_uri() { } /** - * Retrieve the Site Kit oAuth secret. + * Retrieves the OAuth credentials object. + * + * @since 1.0.0 + * + * @return object|null Credentials object with `web` property, or null if no credentials available. */ private function get_client_credentials() { if ( false !== $this->client_credentials ) { return $this->client_credentials; } - if ( $this->credentials->has() ) { - $credentials = $this->credentials->get(); - - $this->client_credentials = (object) array( - 'web' => (object) array( - 'client_id' => $credentials['oauth2_client_id'], - 'client_secret' => $credentials['oauth2_client_secret'], - 'auth_uri' => 'https://accounts.google.com/o/oauth2/auth', - 'token_uri' => 'https://oauth2.googleapis.com/token', - 'auth_provider_x509_cert_url' => 'https://www.googleapis.com/oauth2/v1/certs', - 'redirect_uris' => array( $this->get_redirect_uri() ), - ), - ); + if ( ! $this->credentials->has() ) { + return null; } + $credentials = $this->credentials->get(); + + $this->client_credentials = (object) array( + 'web' => (object) array( + 'client_id' => $credentials['oauth2_client_id'], + 'client_secret' => $credentials['oauth2_client_secret'], + 'auth_uri' => 'https://accounts.google.com/o/oauth2/auth', + 'token_uri' => 'https://oauth2.googleapis.com/token', + 'auth_provider_x509_cert_url' => 'https://www.googleapis.com/oauth2/v1/certs', + 'redirect_uris' => array( $this->get_redirect_uri() ), + ), + ); + return $this->client_credentials; } }