Skip to content

Commit

Permalink
Include the otpauth url when retrieving the QR svg (#356)
Browse files Browse the repository at this point in the history
* Include the otpauth url when retrieving the QR svg

This small change adds the otpauth:// url to the json output when retrieving the QR code svg image.

On some devices, notably iOS 15 and macOS Monterey, it is possible to add the 2 step verification code directly in the system keychain. This allows for autofilling the verification code, so no need for switch to another app. Note that the input for the verification code has to be marked with `autocomplete="one-time-token"`.

However, this nice feature is difficult if not impossible to use when only showing the QR code image, because the camera can not see it's own screen if you know what I mean 👀.
Adding the url makes it possible to show a button 'Add on this device', that simply is a link to the otpauth url. Clicking it will open the system dialog to confirm and add it to a specific account. I tested on both iOS and macOS and it works.

See also the [Apple documentation](https://developer.apple.com/documentation/authenticationservices/securing_logins_with_icloud_keychain_verification_codes), the mention an apple specific prefix, but it works also without the prefix.

* Update TwoFactorQrCodeController.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
JanMisker and taylorotwell committed Feb 18, 2022
1 parent 2602b19 commit 7301d72
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Http/Controllers/TwoFactorQrCodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public function show(Request $request)
return [];
}

return response()->json(['svg' => $request->user()->twoFactorQrCodeSvg()]);
return response()->json([
'svg' => $request->user()->twoFactorQrCodeSvg(),
'url' => $request->user()->twoFactorQrCodeUrl(),
]);
}
}

0 comments on commit 7301d72

Please sign in to comment.