Skip to content

Commit 52de6e6

Browse files
committed
#3986: Pass correct wallet DID in OpenID4VCI proofs
1 parent d8c1a9e commit 52de6e6

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

auth/api/iam/openid4vci.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func (r Wrapper) RequestOpenid4VCICredentialIssuance(ctx context.Context, reques
9595
AuthorizationServerMetadata: authzServerMetadata,
9696
ClientFlow: credentialRequestClientFlow,
9797
OwnSubject: &request.SubjectID,
98+
OwnDID: walletDID,
9899
RedirectURI: request.Body.RedirectUri,
99100
PKCEParams: pkceParams,
100101
// OpenID4VCI issuers may use multiple Authorization Servers
@@ -137,17 +138,13 @@ func (r Wrapper) handleOpenID4VCICallback(ctx context.Context, authorizationCode
137138
checkURL := baseURL.JoinPath(oauth.CallbackPath)
138139

139140
// use code to request access token from remote token endpoint
140-
clientDID, err := r.determineClientDID(ctx, *oauthSession.AuthorizationServerMetadata, *oauthSession.OwnSubject)
141-
if err != nil {
142-
return nil, withCallbackURI(oauthError(oauth.AccessDenied, fmt.Sprintf("error while determining client ID: %s", err.Error())), appCallbackURI)
143-
}
144141
response, err := r.auth.IAMClient().AccessToken(ctx, authorizationCode, oauthSession.TokenEndpoint, checkURL.String(), *oauthSession.OwnSubject, clientID, oauthSession.PKCEParams.Verifier, false)
145142
if err != nil {
146143
return nil, withCallbackURI(oauthError(oauth.AccessDenied, fmt.Sprintf("error while fetching the access_token from endpoint: %s, error: %s", oauthSession.TokenEndpoint, err.Error())), appCallbackURI)
147144
}
148145

149146
// make proof and collect credential
150-
proofJWT, err := r.openid4vciProof(ctx, *clientDID, oauthSession.IssuerURL, response.Get(oauth.CNonceParam))
147+
proofJWT, err := r.openid4vciProof(ctx, *oauthSession.OwnDID, oauthSession.IssuerURL, response.Get(oauth.CNonceParam))
151148
if err != nil {
152149
return nil, withCallbackURI(oauthError(oauth.ServerError, fmt.Sprintf("error building proof to fetch the credential from endpoint %s, error: %s", oauthSession.IssuerCredentialEndpoint, err.Error())), appCallbackURI)
153150
}
@@ -156,7 +153,7 @@ func (r Wrapper) handleOpenID4VCICallback(ctx context.Context, authorizationCode
156153
return nil, withCallbackURI(oauthError(oauth.ServerError, fmt.Sprintf("error while fetching the credential from endpoint %s, error: %s", oauthSession.IssuerCredentialEndpoint, err.Error())), appCallbackURI)
157154
}
158155
// validate credential
159-
// TODO: check that issued credential is bound to DID that requested it (OwnSubject)???
156+
// TODO: check that issued credential is bound to DID that requested it (OwnDID)???
160157
credential, err := vc.ParseVerifiableCredential(credentials.Credential)
161158
if err != nil {
162159
return nil, withCallbackURI(oauthError(oauth.ServerError, fmt.Sprintf("error while parsing the credential: %s, error: %s", credentials.Credential, err.Error())), appCallbackURI)

auth/api/iam/openid4vci_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ package iam
2121
import (
2222
"context"
2323
"errors"
24-
"github.com/nuts-foundation/nuts-node/core/to"
2524
"net/url"
2625
"testing"
2726
"time"
2827

28+
"github.com/nuts-foundation/nuts-node/core/to"
29+
2930
"github.com/nuts-foundation/nuts-node/auth/client/iam"
3031
"github.com/nuts-foundation/nuts-node/auth/oauth"
3132
"github.com/nuts-foundation/nuts-node/crypto"
@@ -190,6 +191,7 @@ func TestWrapper_handleOpenID4VCICallback(t *testing.T) {
190191
},
191192
ClientFlow: "openid4vci_credential_request",
192193
OwnSubject: &holderSubjectID,
194+
OwnDID: &holderDID,
193195
RedirectURI: redirectUrl,
194196
PKCEParams: pkceParams,
195197
TokenEndpoint: tokenEndpoint,

auth/api/iam/openid4vp_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
)
4242

4343
var holderDID = did.MustParseDID("did:web:example.com:iam:holder")
44+
var holderDIDAlt = did.MustParseDID("did:web:example.com:iam:holder_alt")
4445
var issuerDID = did.MustParseDID("did:web:example.com:iam:issuer")
4546
var holderURL = test.MustParseURL("https://example.com/oauth2/holder")
4647
var issuerURL = test.MustParseURL("https://example.com/oauth2/issuer")

auth/api/iam/session.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ package iam
2121
import (
2222
"errors"
2323
"fmt"
24-
"github.com/nuts-foundation/nuts-node/auth/oauth"
2524
"net/url"
2625

26+
"github.com/nuts-foundation/nuts-node/auth/oauth"
27+
2728
"github.com/nuts-foundation/go-did/did"
2829
"github.com/nuts-foundation/go-did/vc"
2930
"github.com/nuts-foundation/nuts-node/http"
@@ -40,12 +41,15 @@ type OAuthSession struct {
4041
ClientState string `json:"client_state,omitempty"`
4142
OpenID4VPVerifier *PEXConsumer `json:"openid4vp_verifier,omitempty"`
4243
OwnSubject *string `json:"own_subject,omitempty"`
43-
OtherDID *did.DID `json:"other_did,omitempty"`
44-
PKCEParams PKCEParams `json:"pkce_params"`
45-
RedirectURI string `json:"redirect_uri,omitempty"`
46-
Scope string `json:"scope,omitempty"`
47-
SessionID string `json:"session_id,omitempty"`
48-
TokenEndpoint string `json:"token_endpoint,omitempty"`
44+
// OwnDID is the DID of the entity that owns this session, which must be a DID of the subject (OwnSubject).
45+
// It is used in OpenID4VCI to select the target wallet.
46+
OwnDID *did.DID `json:"own_did,omitempty"`
47+
OtherDID *did.DID `json:"other_did,omitempty"`
48+
PKCEParams PKCEParams `json:"pkce_params"`
49+
RedirectURI string `json:"redirect_uri,omitempty"`
50+
Scope string `json:"scope,omitempty"`
51+
SessionID string `json:"session_id,omitempty"`
52+
TokenEndpoint string `json:"token_endpoint,omitempty"`
4953
// IssuerURL is the URL that identifies the OAuth2 Authorization Server according to RFC 8414 (Authorization Server Metadata).
5054
IssuerURL string `json:"issuer_url,omitempty"`
5155
UseDPoP bool `json:"use_dpop,omitempty"`

0 commit comments

Comments
 (0)