Skip to content
Browse files

prereleasing

  • Loading branch information...
1 parent 3a9efbd commit 83350dc921a3da84fac4290b8ee9c6bd0ff61658 @pedrodelgallego committed
Showing with 56 additions and 14 deletions.
  1. +16 −11 lib/rack-rpx.rb
  2. +7 −3 rack-rpx.gemspec
  3. +33 −0 rpx-app.rb
View
27 lib/rack-rpx.rb
@@ -8,10 +8,11 @@ module Rack #:nodoc:
#
class Rpx
OPTIONS = {
- :login_path => '/login',
- :callback_path => '/callback',
- :redirect_to => '/completed',
- :rack_session => 'rack.session'
+ :login_path => '/login',
+ :callback_path => '/callback',
+ :redirect_to => '/completed',
+ :callback_url => 'localhost:9393',
+ :rack_session => 'rack.session'
}
def login_path
@@ -25,7 +26,8 @@ def callback_path
# Helper methods intended to be included in your Rails controller or
# in your Sinatra helpers block
module Methods
- RPX_NOW_URL = 'https://rpxnow.com/api/v2/auth_info'
+ RPX_API_URL = "rpxnow.com/api/v2/auth_info"
+ RPX_LOGIN_URL = "https://#{RPX_API_URL}"
# This is *the* method you want to call.
#
@@ -35,7 +37,7 @@ module Methods
#
# You can use the token to make GET/POST/etc requests
def get_credentials(token)
- u = URI.parse(RPX_NOW_URL)
+ u = URI.parse(RPX_LOGIN_URL)
req = Net::HTTP::Post.new(u.path)
req.set_form_data({:token => token, :apiKey => OPTIONS[:api_key], :format => 'json', :extended => 'true'})
http = Net::HTTP.new(u.host,u.port)
@@ -45,7 +47,12 @@ def get_credentials(token)
raise LoginFailedError, 'Cannot log in. Try another account!' unless json['stat'] == 'ok'
json
end
-
+
+
+ def callback_path
+ "http://#{OPTIONS[:callback_url]}#{OPTIONS[:callback_path]}"
+ end
+
end
def initialize app, *args
@@ -57,8 +64,6 @@ def initialize app, *args
def call env
@app.call(env)
- end
-
- end
-
+ end
+ end
end
View
10 rack-rpx.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{rack-rpx}
- s.version = ""
+ s.version = "0.0.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Pedro Del Gallego"]
- s.date = %q{2009-12-10}
+ s.date = %q{2009-12-11}
s.description = %q{Rack Middleware for OAuth Authorization}
s.email = %q{pedro.delgallego@gmail.com}
s.extra_rdoc_files = [
@@ -19,6 +19,9 @@ Gem::Specification.new do |s|
"LICENSE",
"README.rdoc",
"Rakefile",
+ "VERSION",
+ "examples/login-app.rb",
+ "examples/views/login.haml",
"lib/rack-rpx.rb",
"spec/rack-rpx_spec.rb",
"spec/spec.opts",
@@ -31,7 +34,8 @@ Gem::Specification.new do |s|
s.summary = %q{Rack Middleware for RPX Now Authorization}
s.test_files = [
"spec/spec_helper.rb",
- "spec/rack-rpx_spec.rb"
+ "spec/rack-rpx_spec.rb",
+ "examples/login-app.rb"
]
if s.respond_to? :specification_version then
View
33 rpx-app.rb
@@ -0,0 +1,33 @@
+require 'rubygems'
+require 'sinatra'
+require 'rack'
+require 'haml'
+require 'lib/rack-rpx'
+
+use Rack::Session::Cookie
+
+use Rack::Rpx, :api_key => '5b17163d199813f86e51fc3282ffc4298a40cc44',
+ :callback_path => 'login_completed'
+
+
+helpers do
+ include Rack::Rpx::Methods
+end
+
+get "/" do
+ "our current session => #{session.inspect}, params => #{params.inspect}"
+end
+
+get "/login" do
+ haml :login
+end
+
+post "/login_completed" do
+ "our current #{get_credentials(params[:token])}"
+end
+
+
+
+
+
+

0 comments on commit 83350dc

Please sign in to comment.
Something went wrong with that request. Please try again.