[googlestt] Fix authorization from returning null refresh token (#13043)
Signed-off-by: Mark Hilbush <mark@hilbush.com>
This commit is contained in:
parent
00400562d4
commit
2e8167fa3f
|
@ -28,7 +28,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&prompt=consent&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.
|
||||
|
|
|
@ -175,7 +175,11 @@ public class GoogleSTTService implements STTService {
|
|||
private void getAccessToken(OAuthClientService oAuthService, String oauthCode) {
|
||||
logger.debug("Trying to get access and refresh tokens.");
|
||||
try {
|
||||
oAuthService.getAccessTokenResponseByAuthorizationCode(oauthCode, GCP_REDIRECT_URI);
|
||||
AccessTokenResponse response = oAuthService.getAccessTokenResponseByAuthorizationCode(oauthCode,
|
||||
GCP_REDIRECT_URI);
|
||||
if (response.getRefreshToken() == null || response.getRefreshToken().isEmpty()) {
|
||||
logger.warn("Error fetching refresh token. Please try to reauthorize.");
|
||||
}
|
||||
} catch (OAuthException | OAuthResponseException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Error fetching access token: {}", e.getMessage(), e);
|
||||
|
@ -298,19 +302,21 @@ public class GoogleSTTService implements STTService {
|
|||
|
||||
private @Nullable Credentials getCredentials() {
|
||||
String accessToken = null;
|
||||
String refreshToken = null;
|
||||
try {
|
||||
OAuthClientService oAuthService = this.oAuthService;
|
||||
if (oAuthService != null) {
|
||||
AccessTokenResponse response = oAuthService.getAccessTokenResponse();
|
||||
if (response != null) {
|
||||
accessToken = response.getAccessToken();
|
||||
refreshToken = response.getRefreshToken();
|
||||
}
|
||||
}
|
||||
} catch (OAuthException | IOException | OAuthResponseException e) {
|
||||
logger.warn("Access token error: {}", e.getMessage());
|
||||
}
|
||||
if (accessToken == null) {
|
||||
logger.warn("Missed google cloud access token");
|
||||
if (accessToken == null || refreshToken == null) {
|
||||
logger.warn("Missed google cloud access and/or refresh token");
|
||||
return null;
|
||||
}
|
||||
return OAuth2Credentials.create(new AccessToken(accessToken, null));
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
</parameter>
|
||||
<parameter name="oauthCode" 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="singleUtteranceMode" type="boolean" groupName="stt">
|
||||
<label>Single Utterance Mode</label>
|
||||
|
|
|
@ -17,7 +17,7 @@ voice.config.googlestt.maxTranscriptionSeconds.description = Max seconds to wait
|
|||
voice.config.googlestt.noResultsMessage.label = No Results Message
|
||||
voice.config.googlestt.noResultsMessage.description = Message to be told when no results. (Empty for disabled)
|
||||
voice.config.googlestt.oauthCode.label = Authorization Code
|
||||
voice.config.googlestt.oauthCode.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.googlestt.oauthCode.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.googlestt.refreshSupportedLocales.label = Refresh Supported Locales
|
||||
voice.config.googlestt.refreshSupportedLocales.description = Try loading supported locales from the documentation page.
|
||||
voice.config.googlestt.singleUtteranceMode.label = Single Utterance Mode
|
||||
|
|
Loading…
Reference in New Issue