Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URI encode the issuer parameter value #94

Merged
merged 1 commit into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Google Authenticator.

```ruby
totp = ROTP::TOTP.new("base32secret3232", issuer: "My Service")
totp.provisioning_uri("alice@google.com") # => 'otpauth://totp/My%20Service:alice@google.com?secret=base32secret3232&issuer=My+Service'
totp.provisioning_uri("alice@google.com") # => 'otpauth://totp/My%20Service:alice@google.com?secret=base32secret3232&issuer=My%20Service'

hotp = ROTP::HOTP.new("base32secret3232", issuer: "My Service")
hotp.provisioning_uri("alice@google.com", 0) # => 'otpauth://hotp/alice@google.com?secret=base32secret3232&counter=0'
Expand Down
2 changes: 1 addition & 1 deletion lib/rotp/totp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def provisioning_uri(name)
params = {
secret: secret,
period: interval == 30 ? nil : interval,
issuer: issuer,
issuer: Addressable::URI.encode(issuer),
digits: digits == DEFAULT_DIGITS ? nil : digits,
algorithm: digest.casecmp('SHA1').zero? ? nil : digest.upcase
}
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/rotp/totp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ def get_timecodes(at, b, a)
it 'includes the issuer as parameter' do
expect(params['issuer'].first).to eq 'FooCo'
end

context 'with spaces in issuer' do
let(:totp) { ROTP::TOTP.new 'JBSWY3DPEHPK3PXP', issuer: 'Foo Co' }

it 'includes the uri encoded issuer as parameter' do
expect(params['issuer'].first).to eq 'Foo%20Co'
end
end
end

context 'with custom interval' do
Expand Down