auth: add OAuth error handling in TokenVerifier and tests (#399)

Add ErrOAuth error type and handling to match TypeScript SDK behavior.
OAuth protocol errors now return HTTP 400 instead of 500, providing
better error classification for authentication issues.

Changes

- Add ErrOAuth variable for OAuth-specific protocol errors
- Update verify function to return 400 for OAuth errors
- Add test case for OAuth error handling


Fixes compatibility with TypeScript SDK error handling patterns.
This commit is contained in:
Shusaku Yasoda 2025-09-04 02:05:07 +09:00 • committed by GitHub
commit 1250a31b51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,6 +19,8 @@ func TestVerify(t *testing.T) {
return &TokenInfo{Expiration: time.Now().Add(time.Hour)}, nil
case "invalid":
return nil, ErrInvalidToken
case "oauth":
return nil, ErrOAuth
case "noexp":
return &TokenInfo{}, nil
case "expired":
@ -47,6 +49,10 @@ func TestVerify(t *testing.T) {
"invalid", nil, "bearer invalid",
"invalid token", 401,
},
{
"oauth error", nil, "Bearer oauth",
"oauth error", 400,
},
{
"no expiration", nil, "Bearer noexp",
"token missing expiration", 401,