Skip to content

Commit 735d581

Browse files
some leftover stuff from #3333 (#3387)
1 parent 2d077d4 commit 735d581

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

auth/api/iam/api.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ func (r Wrapper) OAuthAuthorizationServerMetadata(_ context.Context, request OAu
600600
}
601601

602602
func (r Wrapper) oauthAuthorizationServerMetadata(clientID url.URL) (*oauth.AuthorizationServerMetadata, error) {
603-
md := authorizationServerMetadata(clientID, r.vdr.SupportedMethods())
603+
md := authorizationServerMetadata(&clientID, r.vdr.SupportedMethods())
604604
if !r.auth.AuthorizationEndpointEnabled() {
605605
md.AuthorizationEndpoint = ""
606606
}
@@ -895,13 +895,7 @@ func (r Wrapper) authzRequestObjectStore() storage.SessionStore {
895895
}
896896

897897
func (r Wrapper) subjectToBaseURL(subject string) url.URL {
898-
u := &url.URL{}
899-
publicURL := r.auth.PublicURL()
900-
if publicURL == nil {
901-
panic("publicURL is nil")
902-
}
903-
u = publicURL.JoinPath("oauth2", subject)
904-
return *u
898+
return *r.auth.PublicURL().JoinPath("oauth2", subject)
905899
}
906900

907901
// subjectExists checks whether the given subject is known on the local node.

auth/api/iam/jar_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func TestJar_Parse(t *testing.T) {
121121
require.NoError(t, err)
122122
token := string(bytes)
123123
walletIssuerURL := test.MustParseURL(holderDID.String())
124-
verifierMetadata := authorizationServerMetadata(*verifierURL, []string{"web"})
124+
verifierMetadata := authorizationServerMetadata(verifierURL, []string{"web"})
125125
configuration := &oauth.OpenIDConfiguration{
126126
JWKs: jwkSet,
127127
}
@@ -161,7 +161,7 @@ func TestJar_Parse(t *testing.T) {
161161
})
162162
t.Run("ok - post", func(t *testing.T) {
163163
ctx := newJarTestCtx(t)
164-
md := authorizationServerMetadata(*walletIssuerURL, []string{"web"})
164+
md := authorizationServerMetadata(walletIssuerURL, []string{"web"})
165165
ctx.iamClient.EXPECT().RequestObjectByPost(context.Background(), "request_uri", md).Return(token, nil)
166166
ctx.keyResolver.EXPECT().ResolveKeyByID(kid, nil, resolver.AssertionMethod).Return(privateKey.Public(), nil)
167167
ctx.iamClient.EXPECT().OpenIDConfiguration(gomock.Any(), holderClientID).Return(configuration, nil)
@@ -217,7 +217,7 @@ func TestJar_Parse(t *testing.T) {
217217
})
218218
t.Run("post (made by wallet)", func(t *testing.T) {
219219
ctx := newJarTestCtx(t)
220-
md := authorizationServerMetadata(*walletIssuerURL, []string{"web"})
220+
md := authorizationServerMetadata(walletIssuerURL, []string{"web"})
221221
ctx.iamClient.EXPECT().RequestObjectByPost(context.Background(), "request_uri", md).Return("", errors.New("server error"))
222222
res, err := ctx.jar.Parse(context.Background(), md,
223223
map[string][]string{

auth/api/iam/metadata.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ import (
3131
"github.com/nuts-foundation/nuts-node/crypto/jwx"
3232
)
3333

34-
func authorizationServerMetadata(issuerURL url.URL, supportedDIDMethods []string) oauth.AuthorizationServerMetadata {
34+
func authorizationServerMetadata(issuerURL *url.URL, supportedDIDMethods []string) oauth.AuthorizationServerMetadata {
3535
metadata := &oauth.AuthorizationServerMetadata{
3636
AuthorizationEndpoint: "openid4vp:",
3737
ClientIdSchemesSupported: clientIdSchemesSupported,
3838
DIDMethodsSupported: supportedDIDMethods,
3939
DPoPSigningAlgValuesSupported: jwx.SupportedAlgorithmsAsStrings(),
4040
GrantTypesSupported: grantTypesSupported,
41-
Issuer: issuerURL.String(),
41+
Issuer: "https://self-issued.me/v2",
4242
PreAuthorizedGrantAnonymousAccessSupported: true,
4343
PresentationDefinitionUriSupported: to.Ptr(true),
4444
RequireSignedRequestObject: true,
@@ -49,9 +49,12 @@ func authorizationServerMetadata(issuerURL url.URL, supportedDIDMethods []string
4949
RequestObjectSigningAlgValuesSupported: jwx.SupportedAlgorithmsAsStrings(),
5050
}
5151

52-
metadata.AuthorizationEndpoint = issuerURL.JoinPath("authorize").String()
53-
metadata.PresentationDefinitionEndpoint = issuerURL.JoinPath("presentation_definition").String()
54-
metadata.TokenEndpoint = issuerURL.JoinPath("token").String()
52+
if issuerURL != nil {
53+
metadata.Issuer = issuerURL.String()
54+
metadata.AuthorizationEndpoint = issuerURL.JoinPath("authorize").String()
55+
metadata.PresentationDefinitionEndpoint = issuerURL.JoinPath("presentation_definition").String()
56+
metadata.TokenEndpoint = issuerURL.JoinPath("token").String()
57+
}
5558
return *metadata
5659
}
5760

@@ -87,10 +90,11 @@ func clientMetadata(identity url.URL) oauth.OAuthClientMetadata {
8790

8891
func openIDConfiguration(issuerURL url.URL, jwkSet jwk.Set, supportedDIDMethods []string) oauth.OpenIDConfiguration {
8992
return oauth.OpenIDConfiguration{
90-
Issuer: issuerURL.String(),
91-
IssuedAt: time.Now().Unix(),
92-
Subject: issuerURL.String(),
93-
JWKs: jwkSet,
94-
Metadata: oauth.EntityStatementMetadata{OpenIDProvider: authorizationServerMetadata(issuerURL, supportedDIDMethods)},
93+
Issuer: issuerURL.String(),
94+
IssuedAt: time.Now().Unix(),
95+
Expiration: time.Now().Add(time.Hour).Unix(), // just a number, data is retrieved runtime. Value must be larger than clock skew to prevent technical problems.
96+
Subject: issuerURL.String(),
97+
JWKs: jwkSet,
98+
Metadata: oauth.EntityStatementMetadata{OpenIDProvider: authorizationServerMetadata(&issuerURL, supportedDIDMethods)},
9599
}
96100
}

auth/api/iam/metadata_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func Test_authorizationServerMetadata(t *testing.T) {
5050
RequestObjectSigningAlgValuesSupported: jwx.SupportedAlgorithmsAsStrings(),
5151
}
5252
authServerUrl := test.MustParseURL("https://example.com/oauth2/example")
53-
md := authorizationServerMetadata(*authServerUrl, []string{"test"})
53+
md := authorizationServerMetadata(authServerUrl, []string{"test"})
5454
assert.Equal(t, baseExpected, md)
5555
}
5656

auth/api/iam/openid4vp.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ func (r Wrapper) sendAndHandleDirectPost(ctx context.Context, subject string, vp
384384
// Dispatch a new HTTP request to the local OpenID4VP wallet's authorization endpoint that includes request parameters,
385385
// but with openid4vp: as scheme.
386386
// The context contains data from the previous request. Usage by the handler will probably result in incorrect behavior.
387-
issuerURL := r.subjectToBaseURL(subject)
388-
userWalletMetadata := authorizationServerMetadata(issuerURL, r.vdr.SupportedMethods())
387+
userWalletMetadata := authorizationServerMetadata(nil, r.vdr.SupportedMethods())
389388
response, err := r.handleAuthorizeRequest(ctx, subject, userWalletMetadata, *parsedRedirectURI)
390389
if err != nil {
391390
return nil, err

auth/oauth/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ type OpenIDConfiguration struct {
415415
Subject string `json:"sub"`
416416
// IssuedAt: the time the entity statement was issued
417417
IssuedAt int64 `json:"iat"`
418+
// Expiration: the time after which the entity statement may no longer be processed
419+
Expiration int64 `json:"exp"`
418420
// JWKs is the JSON Web Key Set of the entity statement. Contains keys of all DIDs for the subject
419421
JWKs jwk.Set `json:"jwks"`
420422
// Metadata: the metadata of the entity statement
@@ -443,6 +445,9 @@ func (j *OpenIDConfiguration) UnmarshalJSON(bytes []byte) error {
443445
if issuedAt, ok := claims["iat"].(float64); ok {
444446
j.IssuedAt = int64(issuedAt)
445447
}
448+
if expiration, ok := claims["exp"].(float64); ok {
449+
j.Expiration = int64(expiration)
450+
}
446451

447452
metadataJson, _ := json.Marshal(claims["metadata"])
448453
if err := json.Unmarshal(metadataJson, &j.Metadata); err != nil {

0 commit comments

Comments
 (0)