Skip to content

Commit

Permalink
Merge branch 'hotfix/0.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
romaimperator committed Apr 3, 2012
2 parents 02c8566 + 355aaa0 commit 9e6d8dd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
41 changes: 38 additions & 3 deletions README.md
@@ -1,6 +1,6 @@
# Omniauth::Trustauth
# OmniAuth::TrustAuth

TODO: Write a gem description
This gem is an OmniAuth strategy to support TrustAuth authentication.

## Installation

Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions lib/omniauth/strategies/trustauth.rb
Expand Up @@ -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

Expand Down

0 comments on commit 9e6d8dd

Please sign in to comment.