[googletts] Fix authorization from returning null refresh token (#13042)

Signed-off-by: Mark Hilbush <mark@hilbush.com>
This commit is contained in:
Mark Hilbush 2022-06-30 13:01:44 -04:00 committed by GitHub
parent 8a8add71df
commit 00400562d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 4 deletions

View 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. * **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. * **Authorization Code** - This code is used once for retrieving the Google Cloud Platform access and refresh tokens.
**Please go to your browser ...** **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**. **... 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 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. After initial authorization, this code is not needed anymore.

View File

@ -189,7 +189,11 @@ class GoogleCloudAPI {
if (authcode != null && !authcode.isEmpty()) { if (authcode != null && !authcode.isEmpty()) {
logger.debug("Trying to get access and refresh tokens."); logger.debug("Trying to get access and refresh tokens.");
try { 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) { } catch (OAuthException | OAuthResponseException e) {
logger.debug("Error fetching access token: {}", e.getMessage(), e); logger.debug("Error fetching access token: {}", e.getMessage(), e);
throw new AuthenticationException( throw new AuthenticationException(
@ -232,6 +236,9 @@ class GoogleCloudAPI {
|| accessTokenResponse.getAccessToken().isEmpty()) { || accessTokenResponse.getAccessToken().isEmpty()) {
throw new AuthenticationException("No access token. Is this thing authorized?"); 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(); return BEARER + accessTokenResponse.getAccessToken();
} }

View File

@ -26,7 +26,7 @@
</parameter> </parameter>
<parameter name="authcode" type="text" groupName="authentication"> <parameter name="authcode" type="text" groupName="authentication">
<label>Authorization Code</label> <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>
<parameter name="pitch" type="decimal" min="-20" max="20" step="0.1" groupName="tts"> <parameter name="pitch" type="decimal" min="-20" max="20" step="0.1" groupName="tts">
<label>Pitch</label> <label>Pitch</label>

View File

@ -1,5 +1,5 @@
voice.config.googletts.authcode.label = Authorization Code 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.label = Client Id
voice.config.googletts.clientId.description = Google Cloud Platform OAuth 2.0-Client Id. voice.config.googletts.clientId.description = Google Cloud Platform OAuth 2.0-Client Id.
voice.config.googletts.clientSecret.label = Client Secret voice.config.googletts.clientSecret.label = Client Secret