nuts-foundation / nuts-foundation/nuts-node

Refactor: Reduce parameter threading and layer depth in access token request chain

Open
#4,127 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discuss
Dominant language
Go
Stars
28
Forks
23
Avg merge
1d 10h
Merged PRs (30d)
76

Description

Problem

The access token request call chain threads individual parameters through 4 layers:

API handler (auth/api/iam/api.go)
  → IAMClient.RequestRFC021AccessToken (auth/client/iam/interface.go / openid4vp.go)
    → Wallet.BuildSubmission (vcr/holder/interface.go / sql_wallet.go / memory_wallet.go)
      → presenter.buildSubmission (vcr/holder/presenter.go)

This causes two related problems:

1. Tramp data / parameter bloat

RequestRFC021AccessToken has 8 positional parameters. Parameters like credentialSelection are only consumed at the bottom layer (presenter) but must be threaded through every intermediate signature, mock, and test expectation. Adding or changing a parameter cascades changes through all layers — e.g. during #4122 review, a cosmetic change (nilmap[string]string{}) would have required updating 8+ mock expectations.

2. Layer depth

Each layer serves a purpose (HTTP boundary → OAuth orchestration → credential loading → VP building), but the intermediate layers act as pass-through for several parameters. This raises the question whether the current separation is the right abstraction, or whether some layers could be consolidated.

Proposed solution (needs refinement)

One option is to bundle request parameters into a struct:

type AccessTokenRequestParams struct {
    ClientID            string
    SubjectDID          string
    AuthServerURL       string
    Scopes              string
    UseDPoP             bool
    Credentials         []vc.VerifiableCredential
    CredentialSelection map[string]string
}

This would reduce signature bloat and make the pass-through layers transparent to new fields. However, it doesn't address the layer depth question — consolidating layers or restructuring responsibilities might be the better solution. This needs further discussion.

Context

Discovered during review of #4122 / #4090.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace the request chain through auth/api/iam/api.go, auth/client/iam/interface.go, openid4vp.go, vcr/holder/interface.go, sql_wallet.go, memory_wallet.go, and vcr/holder/presenter.go. Review the related mocks and test expectations, then compare bundling parameters with restructuring the layers. Done means an agreed design reduces unnecessary threading without breaking the access-token flow and its tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, authentication, backend-api-design
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.