This gem is an OmniAuth strategy to support TrustAuth authentication.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install omniauth-trustauth
First edit your layout.
Add your handler for the OmniAuth callback. Here's an example of something simple:
# your trustauth callback handler def trustauth #if the user was authenticated if auth_hash['info']['result'] # see if this user has an account user = User.find_by_public_key(auth_hash['info']['public_key']) if not user # This user doesn't have an account so save the public key and redirect them to the page to enter an email. session[:public_key] = auth_hash['info']['public_key'] redirect_to new_user_path and return else # Sign in the user if they aren't signed in if not user_signed_in? sign_in_and_redirect(:user, user) and return end end else # Authentication of the public key failed so redirect and notify the user redirect_to root_path, :notice => "Authentication failed." end end def auth_hash request.env['omniauth.auth'] end
You will need to store the public key somewhere in order to let users sign in with it. Be sure to make this column unique.
# db/migrate/AddPublicKey.rb class AddPublicKey < ActiveRecord::Migration def up add_column :users, :public_key, :text, :unique => true end def down remove_column :users, :public_key end end
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Added some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request