Skip to content

Commit 6cc3266

Browse files
committed
more work + pr feedback + fix tests
1 parent 925e3b7 commit 6cc3266

File tree

6 files changed

+164
-298
lines changed

6 files changed

+164
-298
lines changed

auth/api/iam/api.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,10 @@ func (r Wrapper) HandleAuthorizeRequest(ctx context.Context, request HandleAutho
306306
queryParams := httpRequest.URL.Query()
307307

308308
// parse and validate as JAR (RFC9101, JWT Authorization Request)
309-
ro, err := r.jar.Parse(ctx, *ownDID, queryParams)
309+
authzParams, err := r.jar.Parse(ctx, *ownDID, queryParams)
310310
if err != nil {
311311
return nil, err
312312
}
313-
authzParams := ro.Claims
314313

315314
session := createSession(authzParams, *ownDID)
316315

@@ -354,24 +353,32 @@ func (r Wrapper) HandleAuthorizeRequest(ctx context.Context, request HandleAutho
354353
// GetRequestJWT returns the Request Object referenced as 'request_uri' in an authorization request.
355354
// RFC9101: The OAuth 2.0 Authorization Framework: JWT-Secured Authorization Request (JAR).
356355
func (r Wrapper) GetRequestJWT(ctx context.Context, request GetRequestJWTRequestObject) (GetRequestJWTResponseObject, error) {
357-
ro := new(requestObject)
356+
ro := new(jarRequest)
358357
err := r.authzRequestObjectStore().Get(request.Id, ro)
359358
if err != nil {
360359
return nil, err
361360
}
362-
if ro.client().String() != request.Did {
361+
// compare raw strings, don't waste a db call to see if we own the request.Did.
362+
if ro.Client.String() != request.Did {
363363
return nil, errors.New("invalid request")
364364
}
365-
if !ro.signed() {
365+
if ro.RequestURIMethod != "get" {
366+
// TODO: wallet does not support `request_uri_method=post`. Signing the current jarRequest would leave it without 'aud'.
367+
// is this acceptable or should it fail?
366368
return nil, oauth.OAuth2Error{
367369
Code: oauth.InvalidRequest,
368370
Description: "used request_uri_method 'get' on a 'post' request_uri",
369371
InternalError: errors.New("wrong 'request_uri_method' authorization server or wallet probably does not support 'request_uri_method'"),
370372
}
371373
}
374+
token, err := r.jar.Sign(ctx, ro.Claims)
375+
if err != nil {
376+
// TODO: oauth.OAuth2Error?
377+
return nil, err
378+
}
372379
return GetRequestJWT200ApplicationoauthAuthzReqJwtResponse{
373-
Body: bytes.NewReader([]byte(ro.Token)),
374-
ContentLength: int64(len(ro.Token)),
380+
Body: bytes.NewReader([]byte(token)),
381+
ContentLength: int64(len(token)),
375382
}, nil
376383
}
377384

@@ -829,23 +836,21 @@ func (r Wrapper) CreateAuthorizationRequest(ctx context.Context, client did.DID,
829836
}
830837

831838
// request_uri
832-
requestID := cryptoNuts.GenerateNonce()
839+
requestURIID := cryptoNuts.GenerateNonce()
833840
requestObj := r.jar.Create(client, &server, modifier)
834-
if err = r.jar.Sign(ctx, requestObj); err != nil {
835-
return nil, fmt.Errorf("sign authorization Request Object: %w", err)
836-
}
837-
if err = r.authzRequestObjectStore().Put(requestID, requestObj); err != nil {
841+
if err = r.authzRequestObjectStore().Put(requestURIID, requestObj); err != nil {
838842
return nil, err
839843
}
840844
baseURL, err := createOAuth2BaseURL(client)
841845
if err != nil {
842846
return nil, err
843847
}
844-
requestURI := baseURL.JoinPath("request.jwt", requestID)
848+
requestURI := baseURL.JoinPath("request.jwt", requestURIID)
845849

846850
// JAR request
847851
params := map[string]string{
848852
oauth.ClientIDParam: client.String(),
853+
oauth.RequestURIMethodParam: requestObj.RequestURIMethod,
849854
oauth.RequestURIParam: requestURI.String(),
850855
}
851856
if metadata.RequireSignedRequestObject {

0 commit comments

Comments
 (0)