Class: Rack::Rpx
- Inherits:
-
Object
- Object
- Rack::Rpx
- Defined in:
- lib/rack-rpx.rb
Overview
Rack Middleware for integrating RPX Now into your application
Note: this requires that a Rack::Session middleware be enabled
Defined Under Namespace
Modules: Methods Classes: LoginFailedError, NoSession
Constant Summary collapse
- RPX_LOGIN_URL =
"https://rpxnow.com/api/v2/auth_info"
- OPTIONS =
{ :callback_path => '/login_completed', :logout_path => '/logout', :host => 'localhost', :port => '80', :rack_session => 'rack.session', :name => 'default' }
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, *options) ⇒ Rpx
constructor
A new instance of Rpx.
-
#login(env) ⇒ Object
This is the method that you should override if you want to perform any operation just after the response from rpx now.
-
#logout(env) ⇒ Object
This is the method that you should override if you want to perform any operation just before you reach the logout_path.
Constructor Details
Class Method Details
.get_credentials(token) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rack-rpx.rb', line 48 def get_credentials(token) 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) http.use_ssl = true if u.scheme == 'https' json = JSON.parse(http.request(req).body) raise LoginFailedError, "Cannot log in. Try another account! #{json.inspect}" unless json['stat'] == 'ok' json end |
Instance Method Details
#call(env) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rack-rpx.rb', line 66 def call env @req = Rack::Request.new env raise NoSession, 'No compatible session.' unless env['rack.session'] if env['PATH_INFO'] == OPTIONS[:callback_path] && @req.post? then token = @req.params["token"] login(env) elsif env['PATH_INFO'] == OPTIONS[:logout_path] then logout(env) end @app.call(env) end |
#login(env) ⇒ Object
This is the method that you should override if you want to perform any operation just after the response from rpx now
81 |
# File 'lib/rack-rpx.rb', line 81 def login(env); end |
#logout(env) ⇒ Object
This is the method that you should override if you want to perform any operation just before you reach the logout_path
85 |
# File 'lib/rack-rpx.rb', line 85 def logout(env); end |