Coder Social home page Coder Social logo

quoinefinancial / devise_google_authenticator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pharmony/devise_gauth

0.0 0.0 0.0 214 KB

A Devise extension to allow your app to utilise Google's 2FA Mobile app

Home Page: http://labs.asteriskinfosec.com.au/tag/devise_google_authenticator/

License: MIT License

JavaScript 0.64% Ruby 86.98% CoffeeScript 0.32% CSS 0.49% HTML 6.12% SCSS 1.66% Earthly 3.79%

devise_google_authenticator's Introduction

Devise Google Authenticator

This is a (devise)[https://github.com/plataformatec/devise] extension to allow your app to utilise (Google Authenticator)[http://code.google.com/p/google-authenticator/] for Time-based One Time Passwords (TOTP).

The current version of this gem support Rails 4.

Installation

Add the gem to your Gemfile (don't forget devise too):

gem 'devise'
gem 'devise_google_authenticator', '0.3.16'

Don't forget to "bundle install"

Devise Installation (In case you haven't done it)

Before you can setup Devise Google Authenticator you need to setup Devise first, you need to do the following (but refer to https://github.com/plataformatec/devise for more information)

Install Devise:

rails g devise:install

Setup the User or Admin model

rails g devise MODEL

Configure your app for authorisation, edit your Controller and add this before_filter:

before_action :authenticate_user!

Make sure your "root" route is configured in config/routes.rb

Automatic Installation (Lets assume this is a bare bones app)

Run the following generator to add the necessary configuration options to Devise's config file:

rails g devise_google_authenticator:install

After you've created your Devise user models (which is usually done with a "rails g devise MODEL"), set up your Google Authenticator additions:

rails g devise_google_authenticator MODEL

Don't forget to migrate if you're NOT using Mongoid as your database ORM, Mongoid installations will have appropriate fields added to the model after the command above:

rake db:migrate

Installation With Existing Users

After the above steps have been performed, you'll need to generate secrets for each user:

 User.where(:gauth_secret => nil).find_each do |user|
  user.send(:assign_auth_secret)
  user.save!
 end

By default, users won't need to perform two-factor authentication (gauth_enabled='f'). By visiting /MODEL/displayqr (eg: /users/displayqr) and submitting the form, two-factor authentication will then be turned on (gauth_enabled=1) and required for subsequent logins.

Configuration Options

The install generator adds some options to the end of your Devise config file (config/initializers/devise.rb)

  • config.ga_timeout - how long should the user be able to authenticate with their Google Authenticator token
  • config.ga_timedrift - a multiplier which provides for drift between a user's clock (and therefore their OTP) and the system clock. This should be fine at 3.
  • config.ga_remembertime - how long to remember the token for before requiring another. By default this is 1 month. To disable this setting change it to nil.
  • config.ga_appname - If you want to set a custom application name instead of using the name of the Rails app.
  • config.ga_bypass_signup - If you don't want to immediately forward newly registered or signed-up users to the Display QR page. If this is enabled, users will have to visit the /displayqr page to enable Google Authenticator.

Custom Views

If you want to customise your views (which you likely will want to, as they're pretty ugly right now), you can use the generator:

rails g devise_google_authenticator:views

Usage

With this extension enabled, the following is expected behaviour:

  • When a user registers, they are forwarded onto the Display QR page (unless ga_bypass_signup is set to true). This allows them to add their new "token" to their mobile device, and enable, or disable, the functionality. To enable/disable the functionality, the user has to enter the current token.
  • If users can't self-register, they're still able to visit this page by visiting /MODEL/displayqr (eg: /users/displayqr).
  • If the function is enabled (for that user), when they sign in, they'll be prompted for their password (as per normal), but then redirected into the Check QR page. They have to enter their token (from their device) to then successfully authenticate.
  • If configured (by default to 1 month), the user will only be prompted for the token every 1 month.

I18n

The install generator also installs an english copy of a Devise Google Authenticator i18n file. This can be modified (or used to create other language versions) and is located at: config/locales/devise.google_authenticator.en.yml

Testing

The minimal supported versions of Ruby/Rails/Devise is of this fork :

  • Ruby 2.2
  • Rails 4
  • Devise 3.5.10

Thanks (and unknown contributors)

This extension would not exist without the following other projects and associated authors (Whom I have turned to for inspiration and definitely have helped contributing by providing awesome Devise extensions. A lot of this code has been refactored from various sources, in particular these - in particular Sergio and Devise_invitable for his excellent unit test code):

Contributing to devise_google_authenticator

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2014 Christian Frichot. See LICENSE.txt for further details.

devise_google_authenticator's People

Contributors

xntrik avatar zedtux avatar mguymon avatar ronald05arias avatar felipecsl avatar blahblahblah- avatar imnotquitejack avatar mikkel avatar rreusser avatar shekhar-patil avatar redox avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.