otp

class platypush.plugins.otp.OtpPlugin(secret: Optional[str] = None, secret_path: Optional[str] = None, provisioning_name: Optional[str] = None, issuer_name: Optional[str] = None, **kwargs)[source]

This plugin can be used to generate OTP (One-Time Password) codes compatible with Google Authenticator and other 2FA (Two-Factor Authentication) applications.

Requires:

  • pyotp (pip install pyotp)

__init__(secret: Optional[str] = None, secret_path: Optional[str] = None, provisioning_name: Optional[str] = None, issuer_name: Optional[str] = None, **kwargs)[source]
Parameters
  • secret – Base32-encoded secret to be used for password generation.

  • secret_path – If no secret is provided statically, then it will be read from this path (default: ~/.local/share/platypush/otp/secret). If no secret is found then one will be generated.

  • provisioning_name – If you want to use the Google Authenticator, you can specify the default email address to associate to your OTPs for the provisioning process here.

  • issuer_name – If you want to use the Google Authenticator, you can specify the default issuer name to display on your OTPs here.

get_counter_otp(count: int, secret: Optional[str] = None, secret_path: Optional[str] = None) str[source]
Parameters
  • count – Index for the counter-OTP.

  • secret – Secret token to be used (overrides configured secret).

  • secret_path – File containing the secret to be used (overrides configured secret_path).

Returns

A count-based token, as a string.

get_time_otp(secret: Optional[str] = None, secret_path: Optional[str] = None) str[source]
Parameters
  • secret – Secret token to be used (overrides configured secret).

  • secret_path – File containing the secret to be used (overrides configured secret_path).

Returns

A time-based token, as a string.

provision_counter_otp(name: Optional[str] = None, issuer_name: Optional[str] = None, initial_count=0, secret: Optional[str] = None, secret_path: Optional[str] = None) str[source]

Generate a provisioning URI for a counter-OTP that can be imported in Google Authenticator.

Parameters
  • name – Name or e-mail address associated to the account used by the Google Authenticator. If None is specified then the value will be read from the configured provisioning_name.

  • issuer_name – Name of the issuer of the OTP (default: default configured issuer_name or None).

  • initial_count – Initial value for the counter (default: 0).

  • secret – Secret token to be used (overrides configured secret).

  • secret_path – File containing the secret to be used (overrides configured secret_path).

Returns

Generated provisioning URI.

provision_time_otp(name: Optional[str] = None, issuer_name: Optional[str] = None, secret: Optional[str] = None, secret_path: Optional[str] = None) str[source]

Generate a provisioning URI for a time-OTP that can be imported in Google Authenticator.

Parameters
  • name – Name or e-mail address associated to the account used by the Google Authenticator. If None is specified then the value will be read from the configured provisioning_name.

  • issuer_name – Name of the issuer of the OTP (default: default configured issuer_name or None).

  • secret – Secret token to be used (overrides configured secret).

  • secret_path – File containing the secret to be used (overrides configured secret_path).

Returns

Generated provisioning URI.

refresh_secret(secret_path: Optional[str] = None) platypush.message.response.Response[source]

Refresh the secret token for key generation given a secret path.

Parameters

secret_path – Secret path to refresh (default: default configured path).

verify_counter_otp(otp: str, count: int, secret: Optional[str] = None, secret_path: Optional[str] = None) bool[source]

Verify a code against a stored counter-OTP.

Parameters
  • otp – Code to be verified.

  • count – Index for the counter-OTP to be verified.

  • secret – Secret token to be used (overrides configured secret).

  • secret_path – File containing the secret to be used (overrides configured secret_path).

Returns

True if the code is valid, False otherwise.

verify_time_otp(otp: str, secret: Optional[str] = None, secret_path: Optional[str] = None) bool[source]

Verify a code against a stored time-OTP.

Parameters
  • otp – Code to be verified.

  • secret – Secret token to be used (overrides configured secret).

  • secret_path – File containing the secret to be used (overrides configured secret_path).

Returns

True if the code is valid, False otherwise.