Class TwoFactorAuth


  • public class TwoFactorAuth
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String QR_CODE_SERVICE
      Service used to display QR code images
    • Constructor Summary

      Constructors 
      Constructor Description
      TwoFactorAuth​(java.lang.String clientName)
      Generate a new 2FA QR code, can be used with Google Authenticator
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TwoFactorAuth clientName​(java.lang.String clientName)
      Change the client name field
      java.lang.String generateQRCode()
      Generates a URL of a QR code based on your client secret
      java.awt.image.BufferedImage generateQRCodeAsImage()
      Generate your QR code as a BufferedImage instead of a URL
      java.awt.image.BufferedImage generateQRCodeAsImage​(int width, int height)
      Generate your QR code as a BufferedImage instead of a URL with a custom size
      TwoFactorAuth generateSecret()
      Generates the secret key used by Google Authenticator and your server
      java.lang.String getClientName()  
      java.lang.String getLabel()  
      java.lang.String getSecret()  
      TwoFactorAuth label​(java.lang.String label)
      Change the label displayed as the user's username in Google Authenticator
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • QR_CODE_SERVICE

        public static final java.lang.String QR_CODE_SERVICE
        Service used to display QR code images
        See Also:
        Constant Field Values
    • Constructor Detail

      • TwoFactorAuth

        public TwoFactorAuth​(java.lang.String clientName)
        Generate a new 2FA QR code, can be used with Google Authenticator
        Parameters:
        clientName - Name of the application providing 2FA
    • Method Detail

      • generateQRCodeAsImage

        public java.awt.image.BufferedImage generateQRCodeAsImage()
                                                           throws SecretNoGeneratedException,
                                                                  java.io.IOException
        Generate your QR code as a BufferedImage instead of a URL
        Returns:
        Your QR code image that can be scanned by Google Authenticator
        Throws:
        SecretNoGeneratedException - If secret does not exist
        java.io.IOException - If the API fails to generate the image from the URL
      • generateQRCodeAsImage

        public java.awt.image.BufferedImage generateQRCodeAsImage​(int width,
                                                                  int height)
                                                           throws SecretNoGeneratedException,
                                                                  java.io.IOException
        Generate your QR code as a BufferedImage instead of a URL with a custom size
        Parameters:
        width - Custom width of the image
        height - Custom height of the image
        Returns:
        Your QR code image that can be scanned by Google Authenticator
        Throws:
        SecretNoGeneratedException - If secret does not exist
        java.io.IOException - If the API fails to generate the image from the URL
      • generateSecret

        public TwoFactorAuth generateSecret()
        Generates the secret key used by Google Authenticator and your server
        Returns:
        Instance of this class
      • label

        public TwoFactorAuth label​(java.lang.String label)
        Change the label displayed as the user's username in Google Authenticator
        Parameters:
        label - New value of the label
        Returns:
        Instance of this class
      • clientName

        public TwoFactorAuth clientName​(java.lang.String clientName)
        Change the client name field
        Parameters:
        clientName - New value of client name
        Returns:
        Instance of this class
      • getClientName

        public java.lang.String getClientName()
      • getLabel

        public java.lang.String getLabel()
      • getSecret

        public java.lang.String getSecret()