ysinghc commented on issue #8532:
URL: 
https://github.com/apache/incubator-devlake/issues/8532#issuecomment-3478876391

   @klesh I will implement a token refresh mechanism by :
   
   Updating the connection model: I will modify the GithubConnection data model 
to store two new fields obtained from the initial OAuth exchange: the 
refreshToken and its expiry timestamp.
   
   Centralizing the token management: I will introduce a token management layer 
or service within the GitHub plugin. This service will be responsible for 
providing a valid access token to any data collection task.
   
   Implement a "GetAccessToken" Function: Instead of tasks accessing the token 
directly from the connection model, they will call a new function.
   The logic for this function will be as follows: 
   
   a. Check if the current access_token is still valid 
   b. If it is valid, return it
   c. If it is expired check if the refresh_token is still valid 
   d. If the refresh token is valid use it to make a POST request to github's 
token endpoint to get a new access_token and a new refresh_token 
   e. Update the GithubConnection record in the database with these new tokens 
and their expiry dates
   f. Return the new access_token
   g. If the refresh token is also expired then the process fails and the user 
must re-authenticate
   
   Integrate into API client creation: I will refactor the code that creates 
the authenticated GitHub API client. Before a data collection task runs this 
creation logic will now use the getaccesstoken function to ensure it is 
initialized with a valid token refreshing it automatically if necessary.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to