rack-rpx 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/examples/login-app.rb +33 -0
- data/examples/views/login.haml +9 -0
- data/lib/rack-rpx.rb +69 -0
- data/spec/rack-rpx_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +27 -0
- metadata +85 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Pedro Del Gallego
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= rack-rpx
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2009 Pedro Del Gallego. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require 'spec/rake/spectask'
|
7
|
+
|
8
|
+
puts "\nGem: rack-rpx\n\n"
|
9
|
+
|
10
|
+
task :default => :spec
|
11
|
+
begin
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |s|
|
14
|
+
s.name = 'rack-rpx'
|
15
|
+
s.summary = 'Rack Middleware for RPX Now Authorization'
|
16
|
+
s.email = 'pedro.delgallego@gmail.com'
|
17
|
+
s.homepage = 'http://github.com/remi/rack-oauth'
|
18
|
+
s.description = 'Rack Middleware for RPX Authorization, this rack middleware will make even easier to interact with rpx now'
|
19
|
+
s.authors = ["Pedro Del Gallego"]
|
20
|
+
s.files = FileList['[A-Z]*', '{lib,spec,bin,examples}/**/*']
|
21
|
+
s.add_dependency 'rack'
|
22
|
+
s.add_development_dependency "rspec", ">= 1.2.9"
|
23
|
+
s.extra_rdoc_files = %w( README.rdoc )
|
24
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
25
|
+
end
|
26
|
+
Jeweler::GemcutterTasks.new
|
27
|
+
rescue LoadError
|
28
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'spec/rake/spectask'
|
32
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
33
|
+
spec.libs << 'lib' << 'spec'
|
34
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
35
|
+
end
|
36
|
+
|
37
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
38
|
+
spec.libs << 'lib' << 'spec'
|
39
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
40
|
+
spec.rcov = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :spec => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :spec
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "rack-rpx #{version}"
|
52
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'rack'
|
4
|
+
require 'haml'
|
5
|
+
require 'lib/rack-rpx'
|
6
|
+
|
7
|
+
use Rack::Session::Cookie
|
8
|
+
|
9
|
+
use Rack::Rpx, :site => 'http://twitter.com',
|
10
|
+
:api_key => '5b17163d199813f86e51fc3282ffc4298a40cc44',
|
11
|
+
:callback_path => 'login_completed'
|
12
|
+
|
13
|
+
helpers do
|
14
|
+
include Rack::Rpx::Methods
|
15
|
+
end
|
16
|
+
|
17
|
+
get "/" do
|
18
|
+
"our current session => #{session.inspect}, params => #{params.inspect}"
|
19
|
+
end
|
20
|
+
|
21
|
+
get "/login" do
|
22
|
+
haml :login
|
23
|
+
end
|
24
|
+
|
25
|
+
post "/login_completed" do
|
26
|
+
"our current #{get_credentials(params[:token])}"
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
|
2
|
+
%script{ :src => "https://rpxnow.com/openid/v2/widget", :type => "text/javascript" }
|
3
|
+
%script{ :type => "text/javascript" }
|
4
|
+
RPXNOW.overlay = true;
|
5
|
+
RPXNOW.language_preference = 'en';
|
6
|
+
|
7
|
+
|
8
|
+
%a.rpxnow{ :href => "https://olokun.rpxnow.com/openid/v2/signin?token_url=http://localhost:9393/login_completed", :onclick => "return false;" }
|
9
|
+
Sign In
|
data/lib/rack-rpx.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
%w(rubygems net/http net/https rack json).each { |gem| require gem }
|
2
|
+
|
3
|
+
module Rack #:nodoc:
|
4
|
+
|
5
|
+
# Rack Middleware for integrating RPX Now into your application
|
6
|
+
#
|
7
|
+
# Note: this *requires* that a Rack::Session middleware be enabled
|
8
|
+
#
|
9
|
+
class Rpx
|
10
|
+
OPTIONS = {
|
11
|
+
:login_path => '/login',
|
12
|
+
:callback_path => '/callback',
|
13
|
+
:redirect_to => '/completed',
|
14
|
+
:callback_url => 'localhost:9393',
|
15
|
+
:rack_session => 'rack.session'
|
16
|
+
}
|
17
|
+
|
18
|
+
def login_path
|
19
|
+
OPTIONS[:login_path]
|
20
|
+
end
|
21
|
+
|
22
|
+
def callback_path
|
23
|
+
OPTIONS[:callback_path]
|
24
|
+
end
|
25
|
+
|
26
|
+
# Helper methods intended to be included in your Rails controller or
|
27
|
+
# in your Sinatra helpers block
|
28
|
+
module Methods
|
29
|
+
RPX_API_URL = "rpxnow.com/api/v2/auth_info"
|
30
|
+
RPX_LOGIN_URL = "https://#{RPX_API_URL}"
|
31
|
+
|
32
|
+
# This is *the* method you want to call.
|
33
|
+
#
|
34
|
+
# After you're authorized and redirected back to your #redirect_to path,
|
35
|
+
# you should be able to call get_access_token to get and hold onto
|
36
|
+
# the access token for the user you've been authorized as.
|
37
|
+
#
|
38
|
+
# You can use the token to make GET/POST/etc requests
|
39
|
+
def get_credentials(token)
|
40
|
+
u = URI.parse(RPX_LOGIN_URL)
|
41
|
+
req = Net::HTTP::Post.new(u.path)
|
42
|
+
req.set_form_data({:token => token, :apiKey => OPTIONS[:api_key], :format => 'json', :extended => 'true'})
|
43
|
+
http = Net::HTTP.new(u.host,u.port)
|
44
|
+
http.use_ssl = true if u.scheme == 'https'
|
45
|
+
json = JSON.parse(http.request(req).body)
|
46
|
+
|
47
|
+
raise LoginFailedError, 'Cannot log in. Try another account!' unless json['stat'] == 'ok'
|
48
|
+
json
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def callback_path
|
53
|
+
"http://#{OPTIONS[:callback_url]}#{OPTIONS[:callback_path]}"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def initialize app, *args
|
59
|
+
@app = app
|
60
|
+
arg_options = args.pop
|
61
|
+
@name = args.first
|
62
|
+
OPTIONS.merge! arg_options
|
63
|
+
end
|
64
|
+
|
65
|
+
def call env
|
66
|
+
@app.call(env)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rack-rpx'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
require 'rackbox'
|
7
|
+
require File.dirname(__FILE__) + '/../lib/rack-rpx'
|
8
|
+
|
9
|
+
RackBox.app = lambda {}
|
10
|
+
Spec::Runner.configure do |config|
|
11
|
+
config.use_blackbox = true
|
12
|
+
end
|
13
|
+
|
14
|
+
# returns the path to a data file, eg. data_path(:foo) => 'spec/data/foo.yml'
|
15
|
+
def data_path name
|
16
|
+
File.join File.dirname(__FILE__), 'data', "#{name}.yml"
|
17
|
+
end
|
18
|
+
|
19
|
+
# returns the string body of a file using data_path to get the path to the file
|
20
|
+
def data name
|
21
|
+
File.read data_path(name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def mock_request_token options = {}
|
25
|
+
YAML.load data(:unauthorized_request_token).sub('AUTH_PATH', options[:authorize_path] || '/oauth/authorize')
|
26
|
+
end
|
27
|
+
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-rpx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pedro Del Gallego
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-11 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rack
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.9
|
34
|
+
version:
|
35
|
+
description: Rack Middleware for RPX Authorization, this rack middleware will make even easier to interact with rpx now
|
36
|
+
email: pedro.delgallego@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.rdoc
|
43
|
+
files:
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
- Rakefile
|
47
|
+
- VERSION
|
48
|
+
- examples/login-app.rb
|
49
|
+
- examples/views/login.haml
|
50
|
+
- lib/rack-rpx.rb
|
51
|
+
- spec/rack-rpx_spec.rb
|
52
|
+
- spec/spec.opts
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://github.com/remi/rack-oauth
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options:
|
60
|
+
- --charset=UTF-8
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.3.5
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Rack Middleware for RPX Now Authorization
|
82
|
+
test_files:
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
- spec/rack-rpx_spec.rb
|
85
|
+
- examples/login-app.rb
|