Permalink
Browse files

Merge branch 'hotfix/0.0.2'

  • Loading branch information...
2 parents 02c8566 + 355aaa0 commit 9e6d8dd44485ba06621accbfa9ba26abbb41f10f @romaimperator romaimperator committed Apr 3, 2012
Showing with 42 additions and 3 deletions.
  1. +38 −3 README.md
  2. +4 −0 lib/omniauth/strategies/trustauth.rb
View
@@ -1,6 +1,6 @@
-# Omniauth::Trustauth
+# OmniAuth::TrustAuth
-TODO: Write a gem description
+This gem is an OmniAuth strategy to support TrustAuth authentication.
## Installation
@@ -18,7 +18,42 @@ Or install it yourself as:
## Usage
-TODO: Write usage instructions here
+1. First edit your layout.
+
+ <!-- app/views/layouts/application.html.erb -->
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <title>Your Title</title>
+ <%= stylesheet_link_tag "application", :media => "all" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tags %>
+ <%= trustauth_url %> <!-- Add this line to your layout to allow logging in from any page. -->
+ </head>
+ <body>
+ ...
+
+2. 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']
+ # find the public key in the database or create a new user
+ user = User.find_or_create_by_public_key(auth_hash['info']['public_key'])
+
+ # login if the user isn't logged in
+ if not user_signed_in?
+ sign_in_and_redirect(:user, user)
+ end
+ end
+ redirect_to root_path
+ end
+
+ def auth_hash
+ request.env['omniauth.auth']
+ end
## Contributing
@@ -51,6 +51,10 @@ def request_phase
session[:user][:public_key] = user[:public_key]
session[:user][:result] = result[:status]
+
+ if not result[:status]
+ fail!(:invalid_credentials, 'Failed to authorize the public key.')
+ end
end
end

0 comments on commit 9e6d8dd

Please sign in to comment.