lib/rotp/totp.rb in rotp-1.4.6 vs lib/rotp/totp.rb in rotp-1.5.0

- old
+ new

@@ -1,14 +1,17 @@ +DEFAULT_INTERVAL = 30 + module ROTP class TOTP < OTP - attr_reader :interval + attr_reader :interval, :issuer # @option options [Integer] interval (30) the time interval in seconds for OTP # This defaults to 30 which is standard. def initialize(s, options = {}) - @interval = options[:interval] || 30 + @interval = options[:interval] || DEFAULT_INTERVAL + @issuer = options[:issuer] super end # Accepts either a Unix timestamp integer or a Time object. # Time objects will be adjusted to UTC automatically @@ -49,10 +52,11 @@ # This can then be encoded in a QR Code and used # to provision the Google Authenticator app # @param [String] name of the account # @return [String] provisioning uri def provisioning_uri(name) - "otpauth://totp/#{URI.encode(name)}?secret=#{secret}" + encode_params("otpauth://totp/#{URI.encode(name)}", + :period => (interval==30 ? nil : interval), :issuer => issuer, :secret => secret) end private def timecode(time)