umbraco / Umbraco.Cms.Integrations

MIT License
36 stars 21 forks source link

Bugfix/semrush auth UI status #179

Closed acoumb closed 6 months ago

acoumb commented 6 months ago

Current PR adds some updates to the UI of the context app as a result of issue #177.

In a context where the access token is tampered with, or it has expired without possibility of using the refresh token to exchange a new one, the UI misleads the editor into thinking that the status is Connected and allow him to make requests, without getting a visual status of the action.

To fix this, I've introduced the IsAuthorized flag, which is set in the first call to the Semrush service to ValidateToken. During this call, in case of an Unauthorized status code, the refresh token action of the authorization token service is called.

The response from Semrush in case of an invalid refresh token action has this format, so I am using this to remove the value from the database.

{"status":"BAD_REFRESH_TOKEN","message":"missing or invalid refresh token","correlationId":"58673150-43e1-473d-9a9a-cc6dd8d7149a"}