@@ -24,6 +24,9 @@ type TokenInfo struct {
2424// The error that a TokenVerifier should return if the token cannot be verified.
2525var ErrInvalidToken = errors .New ("invalid token" )
2626
27+ // The error that a TokenVerifier should return for OAuth-specific protocol errors.
28+ var ErrOAuth = errors .New ("oauth error" )
29+
2730// A TokenVerifier checks the validity of a bearer token, and extracts information
2831// from it. If verification fails, it should return an error that unwraps to ErrInvalidToken.
2932type TokenVerifier func (ctx context.Context , token string ) (* TokenInfo , error )
@@ -88,7 +91,9 @@ func verify(ctx context.Context, verifier TokenVerifier, opts *RequireBearerToke
8891 if errors .Is (err , ErrInvalidToken ) {
8992 return nil , err .Error (), http .StatusUnauthorized
9093 }
91- // TODO: the TS SDK distinguishes another error, OAuthError, and returns a 400.
94+ if errors .Is (err , ErrOAuth ) {
95+ return nil , err .Error (), http .StatusBadRequest
96+ }
9297 // Investigate how that works.
9398 // See typescript-sdk/src/server/auth/middleware/bearerAuth.ts.
9499 return nil , err .Error (), http .StatusInternalServerError
0 commit comments