This repository has been archived by the owner on Nov 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a0081bd
Showing
15 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2008 [name of plugin creator] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
h1. simple_restful_openid plugin | ||
|
||
I couldn't make sense of some of the others, so I wrote my own. | ||
|
||
h2. Usage | ||
|
||
script/plugin install git://github.com/seven1m/simple_restful_openid.git | ||
script/generate simple_restful_openid | ||
|
||
To sign in, browse to /session/new | ||
|
||
h2. Requirements | ||
|
||
Edge Rails or Rails 2.1+ | ||
|
||
Copyright (c) 2008 Tim Morgan, released under the MIT license |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
|
||
desc 'Default: run unit tests.' | ||
task :default => :test | ||
|
||
desc 'Test the simple_restful_openid plugin.' | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'lib' | ||
t.pattern = 'test/**/*_test.rb' | ||
t.verbose = true | ||
end | ||
|
||
desc 'Generate documentation for the simple_restful_openid plugin.' | ||
Rake::RDocTask.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'SimpleRestfulOpenid' | ||
rdoc.options << '--line-numbers' << '--inline-source' | ||
rdoc.rdoc_files.include('README') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Description: | ||
Generates a Sessions controller and adds a resource route for it. | ||
|
||
Example: | ||
./script/generate simple_restful_openid | ||
|
||
This will create: | ||
app/controllers/sessions_controller.rb |
16 changes: 16 additions & 0 deletions
16
generators/simple_restful_openid/simple_restful_openid_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require File.dirname(__FILE__) + '/../../lib/route_resource_command.rb' | ||
require File.dirname(__FILE__) + '/../../lib/config_gem_command.rb' | ||
|
||
class SimpleRestfulOpenidGenerator < Rails::Generator::Base | ||
def manifest | ||
record do |m| | ||
m.class_collisions 'Session' | ||
m.file 'sessions_controller.rb', 'app/controllers/sessions_controller.rb' | ||
m.directory 'app/views/sessions' | ||
m.file 'new.html.erb', 'app/views/sessions/new.html.erb' | ||
m.route_resource :session | ||
m.config_gem 'ruby-openid', :version => '>= 2.0', :lib => 'openid/consumer' | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<% form_tag session_url, :method => :post do %> | ||
<p> | ||
<label for="url">OpenID URL:</label> | ||
<%= text_field_tag :url %> | ||
<%= submit_tag 'Sign In' %> | ||
</p> | ||
<% end %> |
48 changes: 48 additions & 0 deletions
48
generators/simple_restful_openid/templates/sessions_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'openid/store/filesystem' | ||
|
||
class SessionsController < ApplicationController | ||
# login page | ||
def new | ||
end | ||
|
||
# login form submission | ||
def create | ||
store = OpenID::Store::Filesystem.new(RAILS_ROOT + '/tmp') | ||
consumer = OpenID::Consumer.new(session, store) | ||
oid_req = consumer.begin params[:url] | ||
realm = request.protocol + request.host_with_port | ||
return_to = session_url | ||
redirect_to oid_req.redirect_url(realm, return_to) | ||
end | ||
|
||
def show | ||
if params['openid.mode'] | ||
# the openid provider sends the browser back here | ||
# we'd rather use the update method because it's more RESTful | ||
update | ||
else | ||
redirect_to new_session_path | ||
end | ||
end | ||
|
||
# back from openid provider | ||
def update | ||
store = OpenID::Store::Filesystem.new(RAILS_ROOT + '/tmp') | ||
consumer = OpenID::Consumer.new(session, store) | ||
url = request.protocol + request.host_with_port + request.relative_url_root + request.path | ||
response = consumer.complete(params.reject { |k, v| k !~ /^openid\./ }, url) | ||
if response.status == :success | ||
session[:url] = response.identity_url | ||
redirect_to snippets_path | ||
else | ||
flash[:notice] = 'Failure signing in with OpenID.' | ||
redirect_to new_session_path | ||
end | ||
end | ||
|
||
# sign out | ||
def destroy | ||
session[:url] = nil | ||
redirect_to new_session_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# no hook code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# no install hook code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Rails | ||
module Generator | ||
module Commands | ||
class Create < Base | ||
def config_gem(name, options={}) | ||
sentinel = 'Rails::Initializer.run do |config|' | ||
name_and_options = name.inspect | ||
name_and_options << ", #{options.inspect}" if options.any? | ||
logger.route "config.gem #{name_and_options}" | ||
unless options[:pretend] | ||
gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match| | ||
"#{match}\n config.gem #{name_and_options}\n" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Rails | ||
module Generator | ||
module Commands | ||
class Create < Base | ||
def route_resource(*resources) | ||
resource_list = resources.map { |r| r.to_sym.inspect }.join(', ') | ||
sentinel = 'ActionController::Routing::Routes.draw do |map|' | ||
|
||
logger.route "map.resource #{resource_list}" | ||
unless options[:pretend] | ||
gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match| | ||
"#{match}\n map.resource #{resource_list}\n" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# SimpleRestfulOpenid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# desc "Explaining what the task does" | ||
# task :simple_restful_openid do | ||
# # Task goes here | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'test/unit' | ||
|
||
class SimpleRestfulOpenidTest < Test::Unit::TestCase | ||
# Replace this with your real tests. | ||
def test_this_plugin | ||
flunk | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Uninstall hook code here |