Skip to content

chore: return failed refresh errors on external auth as string (was boolean) #13402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 3, 2024

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented May 29, 2024

Failed refreshing of tokens should return the error for debugging. The function no longer returns a boolean, and only returns an error. So the error can be checked if it is a validation error, or a runtime error.

This was added because multiple reports of failed refreshes have occurred. Debugging these failures are extremely difficult since errors are silenced. This will begin to raise said errors.

We might want to clean up errors from IDPs in the future if they get a bit too technical in their verbage.

Emyrk added 3 commits May 29, 2024 15:53
Failed refreshes should return errors. These errors are captured
as validate errors. A fair classification of the the error
@Emyrk Emyrk requested a review from kylecarbs May 29, 2024 21:24
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change this to be of a custom error type: ErrRefreshFailed and store the validation error there. It may be useful in the future as well if we want to store other properties.

@Emyrk
Copy link
Member Author

Emyrk commented May 31, 2024

I'd change this to be of a custom error type: ErrRefreshFailed and store the validation error there. It may be useful in the future as well if we want to store other properties.

I was considering that too, I just dislike that I would need to return an error, when really none should be returned. Just the false.

If I was to go that route, I'd remove the boolean return entirely. Just

func (c *Config) RefreshToken(ctx context.Context, db database.Store, externalAuthLink database.ExternalAuthLink) (database.ExternalAuthLink, error) 

Let me give that a go with a custom error type and see how it looks

@Emyrk Emyrk requested a review from kylecarbs May 31, 2024 14:56
@kylecarbs
Copy link
Member

Sweet!

@@ -95,17 +95,31 @@ func (c *Config) GenerateTokenExtra(token *oauth2.Token) (pqtype.NullRawMessage,
}, nil
}

// InvalidTokenError is a case where the "RefreshToken" failed to complete
// as a result of invalid credentials. Error contains the reason of the failure.
type InvalidTokenError string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might wanna make this a struct instead, just so we can do e.ValidationMessage or something!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more an InvalidationMessage, but more specifically it could be related to refreshing, a deployment configuration (disabled refreshes), or a validation error.

In all cases, it is an error. And the error is related to being invalid for w/e reason. I think continuing to use it as an err.Error() makes sense

@Emyrk Emyrk merged commit 24ba819 into main Jun 3, 2024
27 checks passed
@Emyrk Emyrk deleted the stevenmasley/failed_refresh branch June 3, 2024 14:33
@github-actions github-actions bot locked and limited conversation to collaborators Jun 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants