Permalink
Browse files

Version bump to 0.0.0

  • Loading branch information...
1 parent 83df9a0 commit 3a9efbd80ee827f7b90e11ff7313f36bd0f96f22 @pedrodelgallego committed Dec 11, 2009
Showing with 73 additions and 18 deletions.
  1. +1 −0 VERSION
  2. +1 −0 config.ru
  3. +33 −0 examples/login-app.rb
  4. +9 −0 examples/views/login.haml
  5. +29 −18 lib/rack-rpx.rb
View
@@ -0,0 +1 @@
+0.0.0
View
@@ -0,0 +1 @@
+
View
@@ -0,0 +1,33 @@
+require 'rubygems'
+require 'sinatra'
+require 'rack'
+require 'haml'
+require 'lib/rack-rpx'
+
+use Rack::Session::Cookie
+
+use Rack::Rpx, :site => 'http://twitter.com',
+ :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,0 +1,9 @@
+
+%script{ :src => "https://rpxnow.com/openid/v2/widget", :type => "text/javascript" }
+%script{ :type => "text/javascript" }
+ RPXNOW.overlay = true;
+ RPXNOW.language_preference = 'en';
+
+
+%a.rpxnow{ :href => "https://olokun.rpxnow.com/openid/v2/signin?token_url=http://localhost:9393/login_completed", :onclick => "return false;" }
+ Sign In
View
@@ -1,4 +1,4 @@
-%w(net/http net/https rubygems rack).each { |gem| require gem }
+%w(rubygems net/http net/https rack json).each { |gem| require gem }
module Rack #:nodoc:
@@ -7,47 +7,58 @@ module Rack #:nodoc:
# Note: this *requires* that a Rack::Session middleware be enabled
#
class Rpx
+ OPTIONS = {
+ :login_path => '/login',
+ :callback_path => '/callback',
+ :redirect_to => '/completed',
+ :rack_session => 'rack.session'
+ }
+
+ def login_path
+ OPTIONS[:login_path]
+ end
+
+ def callback_path
+ OPTIONS[:callback_path]
+ end
# 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'
- API_KEY = '5b17163d199813f86e51fc3282ffc4298a40cc44'
-
- DEFAULT_OPTIONS = {
- :login_path => '/oauth_login',
- :callback_path => '/oauth_callback',
- :redirect_to => '/oauth_complete',
- :rack_session => 'rack.session'
- }
# This is *the* method you want to call.
#
# After you're authorized and redirected back to your #redirect_to path,
# you should be able to call get_access_token to get and hold onto
# the access token for the user you've been authorized as.
- #
+ #
# You can use the token to make GET/POST/etc requests
- def get_access_token(token)
+ def get_credentials(token)
u = URI.parse(RPX_NOW_URL)
req = Net::HTTP::Post.new(u.path)
- req.set_form_data({:token => token, :apiKey => API_KEY, :format => 'json', :extended => 'true'})
+ req.set_form_data({:token => token, :apiKey => OPTIONS[:api_key], :format => 'json', :extended => 'true'})
http = Net::HTTP.new(u.host,u.port)
http.use_ssl = true if u.scheme == 'https'
json = JSON.parse(http.request(req).body)
raise LoginFailedError, 'Cannot log in. Try another account!' unless json['stat'] == 'ok'
json
- end
+ end
+
+ end
+
+ def initialize app, *args
+ @app = app
+ arg_options = args.pop
+ @name = args.first
+ OPTIONS.merge! arg_options
end
def call env
- # put this instance of Rack::OAuth in the env
- # so it's accessible from the application
- env['rack.rpx'] ||= {}
- env['rack.rpx'][name] = self
@app.call(env)
- end
+ end
+
end
end

0 comments on commit 3a9efbd

Please sign in to comment.