File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
src/Umbraco.Cms.Integrations.Crm.Hubspot.Core/Controllers Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ public async Task<ResponseDto> GetAllOAuth()
145
145
Forms = ParseForms ( forms ) . ToList ( )
146
146
} ;
147
147
}
148
- catch ( HttpRequestException ex ) when ( ex . Message . Contains ( HttpStatusCode . Unauthorized . ToString ( ) ) )
148
+ catch ( HttpRequestException ex ) when ( ex . Message . Contains ( HttpStatusCode . Unauthorized . ToString ( ) ) )
149
149
{
150
150
_logger . LogError ( string . Format ( LoggingResources . OAuthFetchFormsFailed , responseContent ) ) ;
151
151
@@ -236,6 +236,22 @@ public async Task<ResponseDto> ValidateAccessToken()
236
236
requestMessage . Headers . Authorization = new AuthenticationHeaderValue ( "Bearer" , accessToken ) ;
237
237
238
238
var response = await ClientFactory ( ) . SendAsync ( requestMessage ) ;
239
+ if ( response . StatusCode == HttpStatusCode . Unauthorized )
240
+ {
241
+ // Attempt to refresh the access token
242
+ await _authorizationService . RefreshAccessTokenAsync ( ) ;
243
+
244
+ _tokenService . TryGetParameters ( Constants . AccessTokenDbKey , out string newAccessToken ) ;
245
+
246
+ // Retry the request with the new access token
247
+ requestMessage = new HttpRequestMessage
248
+ {
249
+ Method = HttpMethod . Get ,
250
+ RequestUri = new Uri ( HubspotFormsApiEndpoint )
251
+ } ;
252
+ requestMessage . Headers . Authorization = new AuthenticationHeaderValue ( "Bearer" , newAccessToken ) ;
253
+ response = await ClientFactory ( ) . SendAsync ( requestMessage ) ;
254
+ }
239
255
240
256
return new ResponseDto
241
257
{
You can’t perform that action at this time.
0 commit comments