Skip to content

Add jose typ package and authn scope and retry error fields - #506

Merged
jhrozek merged 1 commit into
mainfrom
ts-01-wp2-jose-errors
Nov 19, 2026
Merged

jhrozek merged 1 commit into
mainfrom
ts-01-wp2-jose-errors

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add package jose: the JOSE typ constants, IsJOSEType and IsIDJAG (stdlib only), plus its CLAUDE.md and README rows.
  • In authn, add CodeInsufficientScope, ReasonScope, Code.HTTPStatus, and the Error retry-after and required-scopes fields with RetryAfter and RequiredScopes.
  • Add (*Error).HTTPStatus and (*Error).MissingCredentials, and ReasonUnsupportedScheme. Code.HTTPStatus maps by Code alone, so it would answer 400 for a request with no credentials; RFC 6750 §3.1 wants 401 with a bare WWW-Authenticate: Bearer challenge and no error code, also when the client used an unsupported scheme. (*Error).HTTPStatus returns 401 for those cases and Code.HTTPStatus otherwise.
  • Behaviour change: ParseBearer reports a non-Bearer scheme (e.g. Basic …) as ReasonUnsupportedScheme instead of ReasonMalformed. The Code stays invalid_request.

First PR of a stack that prepares authn for verifying tokens from several issuers.

Stack: #506 (jose, errors) → #507 (verify/accept) → #508 (checks) → #509 (scopes, algs) → #510 (JWKS close race) → #511 (ProviderOnly) → #514 (TrustSet) → #515 (guards)

Test plan

  • go vet ./...
  • go test -race ./authn/... ./jose/... (incl. TestErrorMissingCredentialsAndHTTPStatus and new ParseBearer scheme cases)

🤖 Generated with Claude Code

Add package jose with the JOSE typ constants, IsJOSEType and IsIDJAG,
and its CLAUDE.md and README rows.

In authn, add CodeInsufficientScope, ReasonScope, Code.HTTPStatus, and
the Error retryAfter and scopes fields with RetryAfter and
RequiredScopes.

Also add (*Error).HTTPStatus, (*Error).MissingCredentials and
ReasonUnsupportedScheme. Code.HTTPStatus maps by Code alone, so it
answers 400 for every ParseBearer failure, including a request with no
credentials. RFC 6750 section 3.1 says a request that lacks
authentication information, including one using an unsupported
authentication method, should get 401 with a bare WWW-Authenticate:
Bearer challenge and no error code. MissingCredentials is true for
ReasonMissingHeader and ReasonUnsupportedScheme, and (*Error).HTTPStatus
returns 401 for those and Code.HTTPStatus otherwise.

Behaviour change: a non-Bearer Authorization scheme now reports
ReasonUnsupportedScheme instead of ReasonMalformed. The Code stays
CodeInvalidRequest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. The jose package is small and stdlib-only, and the MissingCredentials/(*Error).HTTPStatus split gets the RFC 6750 §3.1 case right. Reporting a non-Bearer scheme as ReasonUnsupportedScheme is a sensible behaviour change.

@jhrozek
jhrozek merged commit 513c232 into main Nov 19, 2026
6 checks passed
@jhrozek
jhrozek deleted the ts-01-wp2-jose-errors branch November 19, 2026 15:38
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

Successfully merging this pull request may close these issues.

2 participants