Rails Otp
This gem is for adding two-factor-authentication. It generates OTP and Verifies it. And sends otp. For sending it uses Exotel, Smsgupshup etc. service providers' api
Installation
Add this line to your application's Gemfile:
gem 'rails_otp'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rails_otp
Usage
- Migrations
To generate migration run
$ rails g opal:migration table_name
Run rake db:migrate
to run the migration.
== 20160711094521 OtpAddToUsers: migrating ====================================
-- change_table(:users)
-> 0.0013s
== 20160711094521 OtpAddToUsers: migrated (0.0014s) ===========================
Once done with this step, include module RailsOtp
to your model.
- Configurations
Setup your configuraion as follows
RailsOtp.configure do |config|
config.sid = 'exotel_sid'
config.token = 'exotel_token'
config.otp_expiry_time = 'set expiry time for otp'
end
Now For e.g. you have instance of user
. then use user.generate_otp!
to generate_otp for user.
To regenerate otp run user.regenerate_otp!
To verify otp use user.verify_otp('otp')
.
To send otp using exotel api use following method
Opal::Exotel.send(:to => phone_munber, :body => 'Your message here')
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
License
The gem is available as open source under the terms of the MIT License.