Skip to content

Commit

Permalink
Merge branch 'master' into vdr/validate-subject
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul committed Sep 4, 2024
2 parents 29d3198 + 7eaea71 commit 0b8a42b
Show file tree
Hide file tree
Showing 64 changed files with 2,306 additions and 1,534 deletions.
7 changes: 3 additions & 4 deletions auth/api/iam/access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package iam

import (
"fmt"
"github.com/nuts-foundation/go-did/did"
"github.com/nuts-foundation/nuts-node/auth/oauth"
"github.com/nuts-foundation/nuts-node/crypto"
"time"
Expand Down Expand Up @@ -60,7 +59,7 @@ type AccessToken struct {
}

// createAccessToken is used in both the s2s and openid4vp flows
func (r Wrapper) createAccessToken(issuer did.DID, walletDID did.DID, issueTime time.Time, scope string, pexState PEXConsumer, dpopToken *dpop.DPoP) (*oauth.TokenResponse, error) {
func (r Wrapper) createAccessToken(issuerURL string, clientID string, issueTime time.Time, scope string, pexState PEXConsumer, dpopToken *dpop.DPoP) (*oauth.TokenResponse, error) {
credentialMap, err := pexState.credentialMap()
if err != nil {
return nil, err
Expand All @@ -73,9 +72,9 @@ func (r Wrapper) createAccessToken(issuer did.DID, walletDID did.DID, issueTime
accessToken := AccessToken{
DPoP: dpopToken,
Token: crypto.GenerateNonce(),
Issuer: issuer.String(),
Issuer: issuerURL,
IssuedAt: issueTime,
ClientId: walletDID.String(),
ClientId: clientID,
Expiration: issueTime.Add(accessTokenValidity),
Scope: scope,
PresentationSubmissions: pexState.Submissions,
Expand Down
271 changes: 142 additions & 129 deletions auth/api/iam/api.go

Large diffs are not rendered by default.

416 changes: 187 additions & 229 deletions auth/api/iam/api_test.go

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions auth/api/iam/dpop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ func TestWrapper_CreateDPoPProof(t *testing.T) {
}
requestObject := CreateDPoPProofRequestObject{
Body: &requestBody,
Did: webDID.String(),
Did: holderDID.String(),
}
didDocument := did.Document{ID: holderDID}
vmId := did.MustParseDIDURL(webDID.String() + "#key1")
vmId := did.MustParseDIDURL(holderDID.String() + "#key1")
key, _ := spi.GenerateKeyPair()
vm, _ := did.NewVerificationMethod(vmId, ssi.JsonWebKey2020, webDID, key.Public())
vm, _ := did.NewVerificationMethod(vmId, ssi.JsonWebKey2020, holderDID, key.Public())
didDocument.AddAssertionMethod(vm)
dpopToken := dpop.New(*request)
dpopToken.GenerateProof(accesstoken)
t.Run("ok", func(t *testing.T) {
ctx := newTestClient(t)
ctx.documentOwner.EXPECT().IsOwner(gomock.Any(), webDID).Return(true, nil)
ctx.resolver.EXPECT().Resolve(webDID, gomock.Any()).Return(&didDocument, nil, nil)
ctx.documentOwner.EXPECT().IsOwner(gomock.Any(), holderDID).Return(true, nil)
ctx.resolver.EXPECT().Resolve(holderDID, gomock.Any()).Return(&didDocument, nil, nil)
ctx.jwtSigner.EXPECT().SignDPoP(gomock.Any(), gomock.Any(), vmId.String()).DoAndReturn(func(_ context.Context, token dpop.DPoP, _ string) (string, error) {
assert.Equal(t, dpopToken.String(), token.String())
return "dpop", nil
Expand All @@ -83,7 +83,7 @@ func TestWrapper_CreateDPoPProof(t *testing.T) {
})
t.Run("invalid method", func(t *testing.T) {
ctx := newTestClient(t)
ctx.documentOwner.EXPECT().IsOwner(gomock.Any(), webDID).Return(true, nil)
ctx.documentOwner.EXPECT().IsOwner(gomock.Any(), holderDID).Return(true, nil)
requestBody.Htm = "\\"
defer (func() { requestBody.Htm = "GET" })()

Expand Down Expand Up @@ -111,16 +111,16 @@ func TestWrapper_CreateDPoPProof(t *testing.T) {
})
t.Run("did not owned", func(t *testing.T) {
ctx := newTestClient(t)
ctx.documentOwner.EXPECT().IsOwner(gomock.Any(), webDID).Return(false, nil)
ctx.documentOwner.EXPECT().IsOwner(gomock.Any(), holderDID).Return(false, nil)

_, err := ctx.client.CreateDPoPProof(context.Background(), requestObject)

assert.EqualError(t, err, "DID document not managed by this node")
})
t.Run("proof error", func(t *testing.T) {
ctx := newTestClient(t)
ctx.documentOwner.EXPECT().IsOwner(gomock.Any(), webDID).Return(true, nil)
ctx.resolver.EXPECT().Resolve(webDID, gomock.Any()).Return(&didDocument, nil, nil)
ctx.documentOwner.EXPECT().IsOwner(gomock.Any(), holderDID).Return(true, nil)
ctx.resolver.EXPECT().Resolve(holderDID, gomock.Any()).Return(&didDocument, nil, nil)
ctx.jwtSigner.EXPECT().SignDPoP(gomock.Any(), gomock.Any(), vmId.String()).Return("dpop", assert.AnError)

_, err := ctx.client.CreateDPoPProof(context.Background(), requestObject)
Expand Down
Loading

0 comments on commit 0b8a42b

Please sign in to comment.