Skip to content

feat: add JSON codecs for challenges and credentials#10

Merged
brendanjryan merged 3 commits intomainfrom
brendan/mpp-go-json-codecs
Apr 16, 2026
Merged

feat: add JSON codecs for challenges and credentials#10
brendanjryan merged 3 commits intomainfrom
brendan/mpp-go-json-codecs

Conversation

@brendanjryan
Copy link
Copy Markdown
Contributor

@brendanjryan brendanjryan commented Apr 16, 2026

Summary

  • add encoding/json support for mpp.Challenge with decoded request JSON and normalized RequestB64
  • add encoding/json support for mpp.Credential so challenge.request accepts standard object JSON instead of forcing callers to manage base64url manually
  • refactor credential challenge JSON to reuse Challenge's custom JSON behavior via a transient conversion, while keeping Credential stored as ChallengeEcho
  • cover object/base64 request handling, opaque handling, and omission of challenge-only fields with regression tests

@brendanjryan brendanjryan force-pushed the brendan/mpp-go-json-codecs branch from 194002f to bb782ae Compare April 16, 2026 15:56
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 194002fe36

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/mpp/json_codec.go Outdated
Comment on lines +233 to +234
if len(trimmed) == 0 || bytes.Equal(trimmed, []byte("null")) {
return b64EncodeRequest(nil), nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject missing challenge.request in credential JSON

Credential.UnmarshalJSON currently treats an absent or null challenge.request as b64EncodeRequest(nil) (e30), which silently turns malformed input into a concrete echoed request. That means a credential JSON payload missing a required field can be re-serialized with ToAuthorization() into a syntactically valid header, and may pass downstream checks for endpoints whose expected request is {}. Missing challenge.request should fail decoding instead of being defaulted.

Useful? React with 👍 / 👎.

Comment thread pkg/mpp/json_codec.go Outdated
Comment on lines +282 to +283
if err != nil {
return map[string]string{"_raw": encoded}, nil
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fail fast on invalid opaque base64 strings

When challenge.opaque is a JSON string that is not valid base64url, decodeJSONOpaque stores it as {"_raw": ...} instead of returning an error. This accepts invalid wire data and defers failure until much later (e.g., ToAuthorization() emits that raw invalid value, which ParseCredential rejects on the receiving side). Decoding should error immediately here to keep JSON handling consistent with existing credential parsing rules.

Useful? React with 👍 / 👎.

@brendanjryan brendanjryan force-pushed the brendan/mpp-go-json-codecs branch 2 times, most recently from 8c111ca to 4e61509 Compare April 16, 2026 16:16
@brendanjryan brendanjryan force-pushed the brendan/mpp-go-json-codecs branch from 4e61509 to 00381af Compare April 16, 2026 16:20
@brendanjryan brendanjryan merged commit c810f8a into main Apr 16, 2026
5 checks passed
@brendanjryan brendanjryan deleted the brendan/mpp-go-json-codecs branch April 16, 2026 17:16
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.

1 participant