A two-factor authentication library.
This library provides the primitives to support a two-factor authentication feature.
Add this line to your application's Gemfile:
gem 'idoru'
And then execute:
$ bundle
Or install it yourself as:
$ gem install idoru
This gem uses the RQREncoder library
to generate QR codes, so you will need to have libqrencode
installed in your
system.
The easiest way to install it (if you're on OS X) is to use Homebrew:
$ brew install libqrencode
require 'idoru'
# generate a shared secret for 2FA
secret = Idoru::TwoFactor.key
# create and configure an Idoru::TwoFactor generator
idoru = Idoru(issuer: 'Acme, Inc.', uid: '[email protected]', secret: secret)
# generate a QR code for 2FA registration and save to a PNG file
qrcode = idoru.qrcode
png = qrcode.to_png
png.save(File.expand_path '~/Desktop/acme.png')
# print the 2FA code at current time to verify registration or auth challenge
puts idoru.authcode
# generate backup verification codes from random points in time
10.times do
time = Time.at(Time.now + rand * Time.now.to_f).utc
puts idoru.authcode(time)
end
-
TOTP code generation using various algorithms (SHA1, SHA256, SHA512, etc), code lengths, and step-times.
-
Helper for generating matching QR code for registration.
At the moment, support is limited to the Google Authenticator and TOTP code generation only.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request