Skip to content

Commit e26705a

Browse files
committed
PR and version updates
1 parent 13f742b commit e26705a

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/Umbraco.Cms.Integrations.Crm.Hubspot.Core/Controllers/FormsController.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public async Task<ResponseDto> ValidateAccessToken()
228228
Error = Constants.ErrorMessages.OAuthInvalidToken
229229
};
230230

231-
var requestMessage = new HttpRequestMessage
231+
using var requestMessage = new HttpRequestMessage
232232
{
233233
Method = HttpMethod.Get,
234234
RequestUri = new Uri(HubspotFormsApiEndpoint)
@@ -239,18 +239,34 @@ public async Task<ResponseDto> ValidateAccessToken()
239239
if (response.StatusCode == HttpStatusCode.Unauthorized)
240240
{
241241
// Attempt to refresh the access token
242-
await _authorizationService.RefreshAccessTokenAsync();
243-
244-
_tokenService.TryGetParameters(Constants.AccessTokenDbKey, out string newAccessToken);
242+
var refreshAccessTokenResponse = await _authorizationService.RefreshAccessTokenAsync();
243+
if (string.IsNullOrEmpty(refreshAccessTokenResponse) || refreshAccessTokenResponse == "error")
244+
{
245+
return new ResponseDto
246+
{
247+
IsValid = false,
248+
Error = Constants.ErrorMessages.OAuthInvalidToken
249+
};
250+
}
251+
252+
if (!_tokenService.TryGetParameters(Constants.AccessTokenDbKey, out string newAccessToken)
253+
|| string.IsNullOrEmpty(newAccessToken))
254+
{
255+
return new ResponseDto
256+
{
257+
IsValid = false,
258+
Error = Constants.ErrorMessages.OAuthInvalidToken
259+
};
260+
}
245261

246262
// Retry the request with the new access token
247-
requestMessage = new HttpRequestMessage
263+
using var newRequestMessage = new HttpRequestMessage
248264
{
249265
Method = HttpMethod.Get,
250266
RequestUri = new Uri(HubspotFormsApiEndpoint)
251267
};
252-
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", newAccessToken);
253-
response = await ClientFactory().SendAsync(requestMessage);
268+
newRequestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", newAccessToken);
269+
response = await ClientFactory().SendAsync(newRequestMessage);
254270
}
255271

256272
return new ResponseDto

src/Umbraco.Cms.Integrations.Crm.Hubspot/Umbraco.Cms.Integrations.Crm.Hubspot.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageIconUrl></PackageIconUrl>
1111
<PackageProjectUrl>https://github.com/umbraco/Umbraco.Cms.Integrations/blob/main/src/Umbraco.Cms.Integrations.Crm.Hubspot</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/umbraco/Umbraco.Cms.Integrations</RepositoryUrl>
13-
<Version>4.0.3</Version>
13+
<Version>4.0.4</Version>
1414
<Authors>Umbraco HQ</Authors>
1515
<Company>Umbraco</Company>
1616
<PackageTags>Umbraco;Umbraco-Marketplace</PackageTags>

0 commit comments

Comments
 (0)