lib/rotp/otp/uri.rb in rotp-6.2.2 vs lib/rotp/otp/uri.rb in rotp-6.3.0
- old
+ new
@@ -1,12 +1,12 @@
module ROTP
class OTP
# https://github.com/google/google-authenticator/wiki/Key-Uri-Format
class URI
- def initialize(otp, account_name:, counter: nil)
+ def initialize(otp, account_name: nil, counter: nil)
@otp = otp
- @account_name = account_name
+ @account_name = account_name || ''
@counter = counter
end
def to_s
"otpauth://#{type}/#{label}?#{parameters}"
@@ -32,12 +32,10 @@
@otp.digits
end
def issuer
- return if @otp.is_a?(HOTP)
-
@otp.issuer&.strip&.tr(':', '_')
end
def label
[issuer, @account_name.rstrip]
@@ -54,9 +52,10 @@
algorithm: algorithm,
digits: digits,
period: period,
counter: counter,
}
+ .merge(@otp.provisioning_params)
.reject { |_, v| v.nil? }
.map { |k, v| "#{k}=#{ERB::Util.url_encode(v)}" }
.join('&')
end