You need to configure the webhook URL for your connection application in which you listen to the account.application.deauthorized event in order to detect that the user has disconnected your application.
When you go and try to get an event to make sure it is correct using the Retrieve Event API , you will receive an error message because your application is no longer allowed:
Stripe :: AuthenticationError: (Status 401) An expired API key was provided: sk _ ********. Access to applications may be revoked.
You can rely on the fact that in this case you will receive a status code 401 to make sure that the event is valid, otherwise you will receive another error.
source share