Skip to content
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

What is the appropriate way to handle the errors returned from IDTokenVerifier.Verify()? #327

Open
AyushSenapati opened this issue Dec 20, 2021 · 2 comments

Comments

@AyushSenapati
Copy link

AyushSenapati commented Dec 20, 2021

Well to give some context, I am using go-oidc in a middleware to verify JWT token. *oidc.IDTokenVerifier.Verify() returns IDToken and error. The verify function could possibly return different errors. Depending on the errors I want to return appropriate HTTP status code to the user. But it looks like the pkg does not expose error types.

In the source code I see the errors are returned like below:
fmt.Errorf("oidc: malformed jwt: %v", err) or fmt.Errorf("oidc: source does not exist") etc.

So I am not sure how to compare these errors and return appropriate HTTP status code.
For now I am using strings.Contain() to compare, but I don't know if there is any better way to do this.

@AyushSenapati AyushSenapati changed the title What is the approp What is the appropriate way to handle the errors returned from IDTokenVerifier.Verify()? Dec 20, 2021
@mitar
Copy link
Contributor

mitar commented May 10, 2022

Yes, those errors should be made into exported values so you can use errors.Is to compare them.

@ericchiang
Copy link
Collaborator

What kind of errors would you want to differentiate? My experience with auth code is that it's best to be conservative, and effectively treat all errors as a 401.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants