Vectorface / GoogleAuthenticator

PHP class to generate and verify Google Authenticator 2-factor authentication
BSD 2-Clause "Simplified" License
14 stars 9 forks source link

Add UriBuilder to expose more OTP Auth URI parameters #6

Closed jdpanderson closed 9 months ago

jdpanderson commented 9 months ago

PR #5 raised the issue of the issuer parameter being unavailable. This PR adds support for more (all) of the otpauth URI parameters (including issuer) by exposing a fluent URI builder interface. It also maintains backwards compatibility with the previous interface.

It should also be more compatible with the available specs I could find (1, 2, & 3), in that free-form strings are now correctly URI-encoded.

Using one of the examples, otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example would be generated with:

(new GoogleAuthenticator())
    ->getUriBuilder()
    ->issuer("Example")
    ->account("alice@google.com")
    ->secret("JBSWY3DPEHPK3PXP")
    ->getUri();