Handle case where a user's refresh token expires
#198 ouverte le 10 nov. 2020
Métriques du dépôt
- Stars
- (22 étoiles)
- Métriques de merge PR
- (Métriques PR en attente)
Description
The task here is to do the following on any request to the msgraph API:
- If an API request fails, examine the error coming back from the msgraph API to check if the acting user's refresh token is expired. If it is expired, mark the user as inactive in the kv store. Then send a DM to the user to reconnect their account.
- If the user is marked as inactive, abort any future API requests done for this user, and log via the
WARNlog level.
Per the discussion in https://github.com/mattermost/mattermost-plugin-mscalendar/issues/15#issuecomment-585033566, it was determined that we should allow the OAuth2 library to handle access tokens and refresh tokens with the library's default behavior.
The refresh token is used to retrieve an access token whenever we need to perform an operation in Microsoft's system. A customer's log reports an error that says The refresh token has expired due to inactivity. This error is occurring during the Renew Subscription job. The customer said this error is printed to the logs every night at midnight.
(log ERROR) Error renewing subscription. err=msgraph RenewSubscription: Patch
https://graph.microsoft.com/v1.0/subscriptions/REDACTED: oauth2: cannot fetch token: 400 Bad Request Response: {"error":"invalid_grant","error_description":"AADSTS700082: The refresh token has expired due to inactivity. The token was issued on 2020-07-23T12:22:48.1096407Z and was inactive for 90.00:00:00.\r\nTrace ID: b40f4014-73bb-40f3-b90d-cd42d78c9600\r\nCorrelation ID: 1bb86522-a8e8-45a2-9966-2d11a892c925\r\nTimestamp: 2020-11-05 00:00:00Z","error_codes":[700082],"timestamp":"2020-11-05 00:00:00Z","trace_id":"b40f4014-73bb-40f3-b90d-cd42d78c9600","correlation_id":"1bb86522-a8e8-45a2-9966-2d11a892c925","error_uri":https://login.microsoftonline.com/error?code=700082}
More context here https://community-daily.mattermost.com/core/pl/u7jyh7dokpdtfcq49keu6peofe
Issue created from a Mattermost message by @mickmister.