]> git.basschouten.com Git - openhab-addons.git/commitdiff
[googletts] Fix authorization from returning null refresh token (#13042)
authorMark Hilbush <mark@hilbush.com>
Thu, 30 Jun 2022 17:01:44 +0000 (13:01 -0400)
committerGitHub <noreply@github.com>
Thu, 30 Jun 2022 17:01:44 +0000 (19:01 +0200)
Signed-off-by: Mark Hilbush <mark@hilbush.com>
bundles/org.openhab.voice.googletts/README.md
bundles/org.openhab.voice.googletts/src/main/java/org/openhab/voice/googletts/internal/GoogleCloudAPI.java
bundles/org.openhab.voice.googletts/src/main/resources/OH-INF/config/config.xml
bundles/org.openhab.voice.googletts/src/main/resources/OH-INF/i18n/googletts.properties

index adfbd5e86f4d12adbf1ed73df3d3b1b494a92847..426b571e6266f7a69ee1ed09a7f9133f99da29dc 100644 (file)
@@ -39,7 +39,7 @@ Using your favorite configuration UI to edit **Settings / Other Services - Googl
 * **Client Secret** - Google Cloud Platform OAuth 2.0-Client Secret.
 * **Authorization Code** - This code is used once for retrieving the Google Cloud Platform access and refresh tokens.
 **Please go to your browser ...**
-[https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/cloud-platform&access_type=offline&include_granted_scopes=true&response_type=code&redirect_uri=https://www.google.com&client_id=<clientId>](https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/cloud-platform&access_type=offline&include_granted_scopes=true&response_type=code&redirect_uri=https://www.google.com&client_id=<clientId>) (replace `<clientId>` by your Client Id)
+[https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/cloud-platform&access_type=offline&include_granted_scopes=true&response_type=code&redirect_uri=https://www.google.com&client_id=<clientId>](https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/cloud-platform&access_type=offline&prompt=consent&include_granted_scopes=true&response_type=code&redirect_uri=https://www.google.com&client_id=<clientId>) (replace `<clientId>` by your Client Id)
 **... to generate an authorization code and paste it here**.
 After your browser has been redirected to https://www.google.com, the authorization code will be set in the browser URL as value of the "code" URL query parameter.
 After initial authorization, this code is not needed anymore.
index 2d782b565747a3f2e20d1daa9d991cdb67998c93..e4b6e05e020334e221eea83c6dd1bbd4e46398aa 100644 (file)
@@ -189,7 +189,11 @@ class GoogleCloudAPI {
         if (authcode != null && !authcode.isEmpty()) {
             logger.debug("Trying to get access and refresh tokens.");
             try {
-                oAuthService.getAccessTokenResponseByAuthorizationCode(authcode, GCP_REDIRECT_URI);
+                AccessTokenResponse response = oAuthService.getAccessTokenResponseByAuthorizationCode(authcode,
+                        GCP_REDIRECT_URI);
+                if (response.getRefreshToken() == null || response.getRefreshToken().isEmpty()) {
+                    throw new AuthenticationException("Error fetching refresh token. Please reauthorize");
+                }
             } catch (OAuthException | OAuthResponseException e) {
                 logger.debug("Error fetching access token: {}", e.getMessage(), e);
                 throw new AuthenticationException(
@@ -232,6 +236,9 @@ class GoogleCloudAPI {
                 || accessTokenResponse.getAccessToken().isEmpty()) {
             throw new AuthenticationException("No access token. Is this thing authorized?");
         }
+        if (accessTokenResponse.getRefreshToken() == null || accessTokenResponse.getRefreshToken().isEmpty()) {
+            throw new AuthenticationException("No refresh token. Please reauthorize");
+        }
         return BEARER + accessTokenResponse.getAccessToken();
     }
 
index 844467b6e713ecacf642a5a827f9cdd54da845b6..f92ce5b80aa13e33642d04cc82fc27443ed54e49 100644 (file)
@@ -26,7 +26,7 @@
                </parameter>
                <parameter name="authcode" type="text" groupName="authentication">
                        <label>Authorization Code</label>
-                       <description><![CDATA[This code is used once for retrieving the Google Cloud Platform access and refresh tokens. Open the following URL in your browser to generate an authorization code:<br><br>https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/cloud-platform&access_type=offline&include_granted_scopes=true&response_type=code&redirect_uri=https://www.google.com&client_id={{clientId}}<br><br>After your browser has been redirected to https://www.google.com, the authorization code will be set in the browser URL as value of the "code" URL query parameter.]]></description>
+                       <description><![CDATA[This code is used once for retrieving the Google Cloud Platform access and refresh tokens. Open the following URL in your browser to generate an authorization code:<br><br>https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/cloud-platform&access_type=offline&prompt=consent&include_granted_scopes=true&response_type=code&redirect_uri=https://www.google.com&client_id={{clientId}}<br><br>After your browser has been redirected to https://www.google.com, the authorization code will be set in the browser URL as value of the "code" URL query parameter.]]></description>
                </parameter>
                <parameter name="pitch" type="decimal" min="-20" max="20" step="0.1" groupName="tts">
                        <label>Pitch</label>
index eee173c580b9349c290a9ba6ad88e96229d274d3..2f3850d252cc96fe24bc9bc610dd6ff2ed9a6dd7 100644 (file)
@@ -1,5 +1,5 @@
 voice.config.googletts.authcode.label = Authorization Code
-voice.config.googletts.authcode.description = This code is used once for retrieving the Google Cloud Platform access and refresh tokens. Open the following URL in your browser to generate an authorization code:<br><br>https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/cloud-platform&access_type=offline&include_granted_scopes=true&response_type=code&redirect_uri=https://www.google.com&client_id={{clientId}}<br><br>After your browser has been redirected to https://www.google.com, the authorization code will be set in the browser URL as value of the "code" URL query parameter.
+voice.config.googletts.authcode.description = This code is used once for retrieving the Google Cloud Platform access and refresh tokens. Open the following URL in your browser to generate an authorization code:<br><br>https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/cloud-platform&access_type=offline&prompt=consent&include_granted_scopes=true&response_type=code&redirect_uri=https://www.google.com&client_id={{clientId}}<br><br>After your browser has been redirected to https://www.google.com, the authorization code will be set in the browser URL as value of the "code" URL query parameter.
 voice.config.googletts.clientId.label = Client Id
 voice.config.googletts.clientId.description = Google Cloud Platform OAuth 2.0-Client Id.
 voice.config.googletts.clientSecret.label = Client Secret