Skip to content

Commit 0a4fa13

Browse files
committed
chore: code review
1 parent 14cf7cd commit 0a4fa13

File tree

8 files changed

+368
-18
lines changed

8 files changed

+368
-18
lines changed

.schema/config.schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,15 +645,15 @@
645645
},
646646
"userinfo_url": {
647647
"type": "string",
648-
"description": "A URL of the userinfo endpoint to be advertised at the OpenID Connect Discovery endpoint /.well-known/openid-configuration. Defaults to Ory Hydra's userinfo endpoint at /userinfo. Set this value if you want to handle this endpoint yourself.",
648+
"description": "A URL of the userinfo endpoint to be advertised at the OpenID Connect Discovery endpoint `/.well-known/openid-configuration`. Defaults to Ory Hydra's userinfo endpoint at `/userinfo`. Set this value if you want to handle this endpoint yourself.",
649649
"format": "uri-reference",
650650
"examples": [
651651
"https://example.org/my-custom-userinfo-endpoint"
652652
]
653653
},
654654
"device_authorization_url": {
655655
"type": "string",
656-
"description": "A URL of the device authorization endpoint to be advertised at the OpenID Connect Discovery endpoint /.well-known/openid-configuration. Defaults to Ory Hydra's device authorizatoin endpoint at /oauth2/device/auth. Set this value if you want to handle this endpoint yourself.",
656+
"description": "A URL of the device authorization endpoint to be advertised at the OpenID Connect Discovery endpoint `/.well-known/openid-configuration`. Defaults to Ory Hydra's device authorization endpoint at `/oauth2/device/auth`. Set this value if you want to handle this endpoint yourself.",
657657
"format": "uri-reference",
658658
"examples": [
659659
"https://example.org/oauth2/device/auth"
@@ -825,7 +825,7 @@
825825
"/ui/device_verification"
826826
]
827827
},
828-
"post_device_done": {
828+
"device_verification_success": {
829829
"type": "string",
830830
"description": "Sets the post device authentication endpoint. Defaults to an internal fallback URL showing an error.",
831831
"format": "uri-reference",

consent/handler.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ func (h *Handler) acceptUserCodeRequest(w http.ResponseWriter, r *http.Request,
10951095
d := json.NewDecoder(r.Body)
10961096
d.DisallowUnknownFields()
10971097
if err := d.Decode(&reqBody); err != nil {
1098-
h.r.Writer().WriteErrorCode(w, r, http.StatusBadRequest, errorsx.WithStack(err))
1098+
h.r.Writer().WriteError(w, r, errorsx.WithStack(fosite.ErrInvalidRequest.WithWrap(err).WithHintf("Unable to decode request body: %s", err.Error())))
10991099
return
11001100
}
11011101

@@ -1106,7 +1106,7 @@ func (h *Handler) acceptUserCodeRequest(w http.ResponseWriter, r *http.Request,
11061106

11071107
cr, err := h.r.ConsentManager().GetDeviceUserAuthRequest(ctx, challenge)
11081108
if err != nil {
1109-
h.r.Writer().WriteError(w, r, errorsx.WithStack(err))
1109+
h.r.Writer().WriteError(w, r, err)
11101110
return
11111111
}
11121112

@@ -1118,17 +1118,18 @@ func (h *Handler) acceptUserCodeRequest(w http.ResponseWriter, r *http.Request,
11181118

11191119
userCodeSignature, err := h.r.RFC8628HMACStrategy().UserCodeSignature(r.Context(), reqBody.UserCode)
11201120
if err != nil {
1121-
h.r.Writer().WriteError(w, r, errorsx.WithStack(fosite.ErrServerError.WithWrap(err).WithHint(`'user_code' signature could not be computed`)))
1121+
h.r.Writer().WriteError(w, r, fosite.ErrServerError.WithWrap(err).WithHint(`The 'user_code' signature could not be computed.`))
11221122
return
11231123
}
1124+
11241125
userCodeRequest, err := h.r.OAuth2Storage().GetUserCodeSession(r.Context(), userCodeSignature, nil)
11251126
if err != nil {
1126-
h.r.Writer().WriteError(w, r, errorsx.WithStack(fosite.ErrNotFound.WithWrap(err).WithHint(`'user_code' session not found`)))
1127+
h.r.Writer().WriteError(w, r, fosite.ErrInvalidRequest.WithWrap(err).WithHint(`The 'user_code' session could not be found or has expired or is otherwise malformed.`))
11271128
return
11281129
}
1129-
err = h.r.RFC8628HMACStrategy().ValidateUserCode(ctx, userCodeRequest, reqBody.UserCode)
1130-
if err != nil {
1131-
h.r.Writer().WriteError(w, r, errorsx.WithStack(fosite.ErrTokenExpired.WithWrap(err).WithHint(`'user_code' has expired`)))
1130+
1131+
if err := h.r.RFC8628HMACStrategy().ValidateUserCode(ctx, userCodeRequest, reqBody.UserCode); err != nil {
1132+
h.r.Writer().WriteError(w, r, fosite.ErrInvalidRequest.WithWrap(err).WithHint(`The 'user_code' session could not be found or has expired or is otherwise malformed.`))
11321133
return
11331134
}
11341135

@@ -1148,22 +1149,24 @@ func (h *Handler) acceptUserCodeRequest(w http.ResponseWriter, r *http.Request,
11481149
h.r.Writer().WriteError(w, r, errorsx.WithStack(err))
11491150
return
11501151
}
1152+
11511153
if reqURL.Query().Get("client_id") == "" {
11521154
q := reqURL.Query()
11531155
q.Add("client_id", userCodeRequest.GetClient().GetID())
11541156
reqURL.RawQuery = q.Encode()
11551157
}
1158+
11561159
f.RequestURL = reqURL.String()
11571160

11581161
hr, err := h.r.ConsentManager().HandleDeviceUserAuthRequest(ctx, f, challenge, &p)
11591162
if err != nil {
1160-
h.r.Writer().WriteError(w, r, errorsx.WithStack(err))
1163+
h.r.Writer().WriteError(w, r, err)
11611164
return
11621165
}
11631166

11641167
ru, err := url.Parse(hr.RequestURL)
11651168
if err != nil {
1166-
h.r.Writer().WriteError(w, r, err)
1169+
h.r.Writer().WriteError(w, r, fosite.ErrInvalidRequest.WithWrap(err).WithHint(`Unable to parse the request_url.`))
11671170
return
11681171
}
11691172

consent/strategy_default.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,11 +1210,11 @@ func (s *DefaultStrategy) HandleOAuth2DeviceAuthorizationRequest(
12101210
// Validate client_id
12111211
clientID := r.URL.Query().Get("client_id")
12121212
if clientID == "" {
1213-
return nil, nil, errorsx.WithStack(fosite.ErrInvalidClient.WithHintf(`client_id query parameter is missing`))
1213+
return nil, nil, errorsx.WithStack(fosite.ErrInvalidClient.WithHintf(`Query parameter 'client_id' is missing.`))
12141214
}
12151215
c, err := s.r.ClientManager().GetConcreteClient(r.Context(), clientID)
12161216
if errors.Is(err, x.ErrNotFound) {
1217-
return nil, nil, errorsx.WithStack(fosite.ErrInvalidClient.WithHintf(`Unknown client_id %s`, clientID))
1217+
return nil, nil, errorsx.WithStack(fosite.ErrInvalidClient.WithWrap(err).WithHintf(`Client does not exist`))
12181218
} else if err != nil {
12191219
return nil, nil, err
12201220
}

contrib/quickstart/5-min/hydra.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ urls:
99
login: http://127.0.0.1:3000/login
1010
logout: http://127.0.0.1:3000/logout
1111
device_verification: http://127.0.0.1:3000/device_code
12-
post_device_done: http://127.0.0.1:3000/device_complete
12+
device_verification_success: http://127.0.0.1:3000/device_complete
1313

1414
secrets:
1515
system:

driver/config/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const (
8787
KeyConsentURL = "urls.consent"
8888
KeyErrorURL = "urls.error"
8989
KeyDeviceVerificationURL = "urls.device_verification"
90-
KeyDeviceDoneURL = "urls.post_device_done"
90+
KeyDeviceDoneURL = "urls.device_verification_success"
9191
KeyPublicURL = "urls.self.public"
9292
KeyAdminURL = "urls.self.admin"
9393
KeyIssuerURL = "urls.self.issuer"

internal/.hydra.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ urls:
102102
logout: https://logout
103103
error: https://error
104104
device_verification: https://device
105-
post_device_done: https://device/callback
105+
device_verification_success: https://device/callback
106106
post_logout_redirect: https://post_logout
107107

108108
strategies:

0 commit comments

Comments
 (0)