@@ -284,20 +284,13 @@ func (u *DynamoUser) FinishRegistration(r *http.Request) (string, error) {
284284 br := fixEncoding (body )
285285 parsedResponse , err := protocol .ParseCredentialCreationResponseBody (br )
286286 if err != nil {
287- var protocolError * protocol.Error
288- if errors .As (err , & protocolError ) {
289- log .Printf ("unable to parse body: %s" , body )
290- log .Printf ("ProtocolError: %s, DevInfo: %s" , protocolError .Details , protocolError .DevInfo )
291- }
287+ logProtocolError ("unable to parse body" , err )
292288 return "" , fmt .Errorf ("unable to parse credential creation response body: %w" , err )
293289 }
294290
295291 credential , err := u .WebAuthnClient .CreateCredential (u , u .SessionData , parsedResponse )
296292 if err != nil {
297- var protocolError * protocol.Error
298- if errors .As (err , & protocolError ) {
299- log .Printf ("ProtocolError: %s, DevInfo: %s" , protocolError .Details , protocolError .DevInfo )
300- }
293+ logProtocolError ("unable to create credential" , err )
301294 return "" , fmt .Errorf ("unable to create credential: %w" , err )
302295 }
303296
@@ -349,7 +342,7 @@ func (u *DynamoUser) FinishLogin(r *http.Request) (*webauthn.Credential, error)
349342 br := fixEncoding (body )
350343 parsedResponse , err := protocol .ParseCredentialRequestResponseBody (br )
351344 if err != nil {
352- log . Printf ("failed to parse credential request response body: %s" , err )
345+ logProtocolError ( fmt . Sprintf ("failed to parse credential request response body: %s" , body ) , err )
353346 return & webauthn.Credential {}, fmt .Errorf ("failed to parse credential request response body: %s" , err )
354347 }
355348
@@ -378,7 +371,7 @@ func (u *DynamoUser) FinishLogin(r *http.Request) (*webauthn.Credential, error)
378371
379372 credential , err := u .WebAuthnClient .ValidateLogin (u , u .SessionData , parsedResponse )
380373 if err != nil {
381- log . Printf ("failed to validate login: %s " , err )
374+ logProtocolError ("failed to validate login" , err )
382375 return & webauthn.Credential {}, fmt .Errorf ("failed to validate login: %s" , err )
383376 }
384377
@@ -488,3 +481,13 @@ func hashAndEncodeKeyHandle(id []byte) string {
488481 hash := sha256 .Sum256 (id )
489482 return base64 .RawURLEncoding .EncodeToString (hash [:])
490483}
484+
485+ // logProtocolError logs a detailed message if the given error is an Error from go-webauthn/webauthn/protocol
486+ func logProtocolError (msg string , err error ) {
487+ var protocolError * protocol.Error
488+ if errors .As (err , & protocolError ) {
489+ log .Printf ("%s, ProtocolError: %s, DevInfo: %s" , msg , protocolError .Details , protocolError .DevInfo )
490+ } else {
491+ log .Printf ("%s, Error: %s" , msg , err )
492+ }
493+ }
0 commit comments