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()
145145 Forms = ParseForms ( forms ) . ToList ( )
146146 } ;
147147 }
148- catch ( HttpRequestException ex ) when ( ex . Message . Contains ( HttpStatusCode . Unauthorized . ToString ( ) ) )
148+ catch ( HttpRequestException ex ) when ( ex . Message . Contains ( HttpStatusCode . Unauthorized . ToString ( ) ) )
149149 {
150150 _logger . LogError ( string . Format ( LoggingResources . OAuthFetchFormsFailed , responseContent ) ) ;
151151
@@ -236,6 +236,22 @@ public async Task<ResponseDto> ValidateAccessToken()
236236 requestMessage . Headers . Authorization = new AuthenticationHeaderValue ( "Bearer" , accessToken ) ;
237237
238238 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+ }
239255
240256 return new ResponseDto
241257 {
You can’t perform that action at this time.
0 commit comments