Skip to content

Commit

Permalink
Merge pull request #7 from jayywolff/specs
Browse files Browse the repository at this point in the history
Add Appraisals for testing against Rails 7 & 7.1
  • Loading branch information
jayywolff authored Dec 30, 2024
2 parents aeaba85 + 151e4ea commit 5bfa27c
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ gemfiles/*.lock
.rvmrc

**/*.sqlite
**/*.sqlite-*
**/*.log

initializers/twilio_verify.rb
Expand Down
38 changes: 31 additions & 7 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ appraise "rails-5-2" do
gem "sqlite3", "~> 1.3.13"

group :development, :test do
gem 'factory_girl_rails', :require => false
gem 'rspec-rails', "~>4.0.0.beta3", :require => false
gem 'database_cleaner', :require => false
gem 'factory_girl_rails', require: false
gem 'rspec-rails', "~> 5.0.0", require: false
gem 'database_cleaner', require: false
end
end if RUBY_VERSION.to_f < 3.0

Expand All @@ -15,8 +15,32 @@ appraise "rails-6" do
gem "net-smtp"

group :development, :test do
gem 'factory_girl_rails', :require => false
gem 'rspec-rails', "~>4.0.0.beta3", :require => false
gem 'database_cleaner', :require => false
gem 'factory_girl_rails', require: false
gem 'rspec-rails', "~> 5.0.0", require: false
gem 'database_cleaner', require: false
end
end if RUBY_VERSION.to_f >= 2.5
end if RUBY_VERSION.to_f >= 2.5

appraise "rails-7" do
gem "rails", "~> 7.0.8"
gem "sqlite3", "~> 1.4"
gem "net-smtp"

group :development, :test do
gem 'factory_girl_rails', require: false
gem 'rspec-rails', "~> 7.0.0", require: false
gem 'database_cleaner', require: false
end
end if RUBY_VERSION.to_f >= 2.7

appraise "rails-7-1" do
gem "rails", "~> 7.1.5"
gem "sqlite3", "~> 1.4"
gem "net-smtp"

group :development, :test do
gem 'factory_girl_rails', require: false
gem 'rspec-rails', "~> 7.1.0", require: false
gem 'database_cleaner', require: false
end
end if RUBY_VERSION.to_f >= 2.7
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.2.1] - 2024-12-29

### Changed

- Added apprasials for testing against Rails 7 and Rails 7.1
- Bump rspec-rails version from "~>4.0.0.beta3" to "~> 5.0.0" for Rails 5.2 and Rails 6 testing
- Updated README to move the authy migration instructions a bit below the README gem introduction / instructions

## [0.2.0] - 2024-12-21

### Changed
Expand Down
90 changes: 45 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,3 @@
# Migrate Authy to Twilio Verify API (for SMS and TOTP 2FA)

### This gem is meant to be a drop-in replacement for devise-authy in a Rails app (minus the following features)
- Currently only support mobile phones with US country codes
- Removed Onetouch support
- Removed ability to request a phone call

### Just follow the steps below to migrate:
- Swap out `devise-authy` in your Gemfile with `devise-twilio-verify`
- `gem 'devise-twilio-verify'
- Setup a Twilio Verify account
- Add env vars and/or Rails credentials for:
- `TWILIO_AUTH_TOKEN`
- `TWILIO_ACCOUNT_SID`
- `TWILIO_VERIFY_SERVICE_SID`
- Create/run a migration to rename and add the following columns
```ruby
class MigrateAuthyToTwilioVerify < ActiveRecord::Migration[6.1]
def change
rename_column :users, :authy_sms, :twilio_verify_sms
rename_column :users, :authy_enabled, :twilio_verify_enabled
rename_column :users, :last_sign_in_with_authy, :last_sign_in_with_twilio_verify
add_column :users, :twilio_totp_factor_sid, :string
end
end

```
- you can also delete the `users.authy_id` column if you choose
- Twilio Verify service sms will be sent to `users.mobile_phone`, so make sure you store the users 2fa phone number in this column, can make this field name dynamic in the future
- Do a project code wide search & replace of these terms
- `devise-authy` -> `devise-twilio-verify`
- `authy_` -> `twilio_verify_`
- `_authy` -> `_twilio_verify`
- `authy-` -> `twilio-verify-`
- `-authy` -> `-twilio-verify`
- `Authy` -> `TwilioVerify`
- Do a project file search & replace of any file with authy in the name (here's a few examples to replace)
- app/javascript/src/deviseTwilioVerify.js
- app/assets/stylesheets/devise_twilio_verify.scss
- config/locales/devise.twilio_verify.en.yml

# Twilio Verify Devise [![Build Status](https://github.com/jayywolff/twilio-verify-devise/workflows/build/badge.svg)](https://github.com/jayywolff/twilio-verify-devise/actions)

This is a [Devise](https://github.com/heartcombo/devise) extension to add [Two-Factor Authentication with Twilio Verify](https://www.twilio.com/docs/verify) to your Rails application.
Expand All @@ -48,10 +7,9 @@ Please visit the Twilio Docs for more information:
* [Verify + Ruby (Rails) quickstart](https://www.twilio.com/docs/verify/quickstarts/ruby-rails)
* [Twilio Ruby helper library](https://www.twilio.com/docs/libraries/ruby)
* [Verify API reference](https://www.twilio.com/docs/verify/api)


* [Migrate Authy to Twilio Verify API](#migrate-authy-to-twilio-verify-api)
* [Pre-requisites](#pre-requisites)
* [Demo](#demo)
* [Demo (TODO)](#demo)
* [Getting started](#getting-started)
* [Configuring Models](#configuring-models)
* [With the generator](#with-the-generator)
Expand Down Expand Up @@ -246,7 +204,7 @@ This will display a QR code on the verification screen (you still need to take a

In Rails 5 `protect_from_forgery` is no longer prepended to the `before_action` chain. If you call `authenticate_user` before `protect_from_forgery` your request will result in a "Can't verify CSRF token authenticity" error.

To remedy this, add `prepend: true` to your `protect_from_forgery` call, like in this example from the [Twilio Verify Devise demo app](https://github.com/twilio/authy-devise-demo):
To remedy this, add `prepend: true` to your `protect_from_forgery` call

```ruby
class ApplicationController < ActionController::Base
Expand All @@ -262,5 +220,47 @@ Run the following command:
$ bundle exec rspec
```

## Migrate Authy to Twilio Verify API

### This gem is meant to be a drop-in replacement for devise-authy in a Rails app (minus the following features)
- Currently supports SMS and TOTP 2FA
- Currently only support mobile phones with US country codes
- Removed Onetouch support
- Removed ability to request a phone call

### Just follow the steps below to migrate:
- Swap out `devise-authy` in your Gemfile with `devise-twilio-verify`
- `gem 'devise-twilio-verify'
- Setup a Twilio Verify account
- Add env vars and/or Rails credentials for:
- `TWILIO_AUTH_TOKEN`
- `TWILIO_ACCOUNT_SID`
- `TWILIO_VERIFY_SERVICE_SID`
- Create/run a migration to rename and add the following columns
```ruby
class MigrateAuthyToTwilioVerify < ActiveRecord::Migration[6.1]
def change
rename_column :users, :authy_sms, :twilio_verify_sms
rename_column :users, :authy_enabled, :twilio_verify_enabled
rename_column :users, :last_sign_in_with_authy, :last_sign_in_with_twilio_verify
add_column :users, :twilio_totp_factor_sid, :string
end
end

```
- you can also delete the `users.authy_id` column if you choose
- Twilio Verify service sms will be sent to `users.mobile_phone`, so make sure you store the users 2fa phone number in this column, can make this field name dynamic in the future
- Do a project code wide search & replace of these terms
- `devise-authy` -> `devise-twilio-verify`
- `authy_` -> `twilio_verify_`
- `_authy` -> `_twilio_verify`
- `authy-` -> `twilio-verify-`
- `-authy` -> `-twilio-verify`
- `Authy` -> `TwilioVerify`
- Do a project file search & replace of any file with authy in the name (here's a few examples to replace)
- app/javascript/src/deviseTwilioVerify.js
- app/assets/stylesheets/devise_twilio_verify.scss
- config/locales/devise.twilio_verify.en.yml

## Copyright
See LICENSE.txt for further details.
2 changes: 1 addition & 1 deletion gemfiles/rails_5_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem "sqlite3", "~> 1.3.13"

group :development, :test do
gem "factory_girl_rails", require: false
gem "rspec-rails", "~>4.0.0.beta3", require: false
gem "rspec-rails", "~> 5.0.0", require: false
gem "database_cleaner", require: false
end

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gem "net-smtp"

group :development, :test do
gem "factory_girl_rails", require: false
gem "rspec-rails", "~>4.0.0.beta3", require: false
gem "rspec-rails", "~> 5.0.0", require: false
gem "database_cleaner", require: false
end

Expand Down
15 changes: 15 additions & 0 deletions gemfiles/rails_7.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 7.0.8"
gem "sqlite3", "~> 1.4"
gem "net-smtp"

group :development, :test do
gem "factory_girl_rails", require: false
gem "rspec-rails", "~> 7.0.0", require: false
gem "database_cleaner", require: false
end

gemspec path: "../"
15 changes: 15 additions & 0 deletions gemfiles/rails_7_1.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 7.1.5"
gem "sqlite3", "~> 1.4"
gem "net-smtp"

group :development, :test do
gem "factory_girl_rails", require: false
gem "rspec-rails", "~> 7.1.0", require: false
gem "database_cleaner", require: false
end

gemspec path: "../"
2 changes: 1 addition & 1 deletion lib/devise-twilio-verify/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DeviseTwilioVerify
VERSION = '0.2.0'
VERSION = '0.2.1'
end

0 comments on commit 5bfa27c

Please sign in to comment.