rack-rpx 0.1.4 → 0.1.5

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.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/rack-rpx.rb +10 -21
  3. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -1,12 +1,12 @@
1
- %w(rubygems net/http net/https rack json).each { |gem| require gem }
1
+ %w(rubygems logger net/http net/https rack json).each { |gem| require gem }
2
2
  module Rack #:nodoc:
3
3
 
4
4
  # Rack Middleware for integrating RPX Now into your application
5
5
  #
6
6
  # Note: this *requires* that a Rack::Session middleware be enabled
7
- #
8
- class Rpx
7
+ class Rpx
9
8
  RPX_LOGIN_URL = "https://rpxnow.com/api/v2/auth_info"
9
+
10
10
  # Raised if an incompatible session is being used.
11
11
  class NoSession < RuntimeError; end
12
12
  class LoginFailedError < RuntimeError; end
@@ -27,18 +27,18 @@ module Rack #:nodoc:
27
27
  # This is *the* method you want to call.
28
28
  #
29
29
  # After you're authorized and redirected back to your #redirect_to path,
30
- # you should be able to call get_access_token to get and hold onto
30
+ # you should be able to call get_credentials to get and hold onto
31
31
  # the access token for the user you've been authorized as.
32
- #
33
- # You can use the token to make GET/POST/etc requests
34
32
  def get_credentials(token)
35
33
  Rack::Rpx.get_credentials(token)
36
34
  end
37
35
 
36
+ # This method will return to sign in with the widget.
38
37
  def login_widget_url(app_name=nil)
39
38
  "https://#{app_name}.rpxnow.com/openid/v2/signin?token_url=#{callback_url}"
40
39
  end
41
-
40
+
41
+ private
42
42
  def callback_url
43
43
  "http://#{env['HTTP_HOST']}#{OPTIONS[:callback_path]}"
44
44
  end
@@ -47,7 +47,7 @@ module Rack #:nodoc:
47
47
  class << self
48
48
  def get_credentials(token)
49
49
  u = URI.parse(RPX_LOGIN_URL)
50
- req = Net::HTTP::Post.new(u.path)
50
+ req = Net::HTTP::Post.new(u.path)
51
51
  req.set_form_data({:token => token, :apiKey => OPTIONS[:api_key], :format => 'json', :extended => 'true'})
52
52
  http = Net::HTTP.new(u.host,u.port)
53
53
  http.use_ssl = true if u.scheme == 'https'
@@ -61,36 +61,25 @@ module Rack #:nodoc:
61
61
  def initialize app, *options
62
62
  @app = app
63
63
  OPTIONS.merge! options.pop
64
- OPTIONS.each do |k,v|
65
- Rack::Rpx.send(:define_method, k.to_s) {OPTIONS[k]}
66
- end
67
64
  end
68
65
 
69
66
  def call env
70
67
  @req = Rack::Request.new env
71
68
  raise NoSession, 'No compatible session.' unless env['rack.session']
72
69
 
73
- if env['PATH_INFO'] == OPTIONS[:callback_path] && @req.post? then
70
+ if env['PATH_INFO'] == OPTIONS[:callback_path] && @req.post? then
74
71
  token = @req.params["token"]
75
- set_credentials(env, token) if OPTIONS[:set_credentials]
76
72
  login(env)
77
73
  elsif env['PATH_INFO'] == OPTIONS[:logout_path] then
78
74
  logout(env)
79
75
  end
80
76
  @app.call(env)
81
77
  end
82
-
83
- def set_credentials(env, token)
84
- env['rack.session']['credentials'] = self.get_credentials(token)
85
- end
86
-
78
+
87
79
  # This is the method that you should override if you want to
88
80
  # perform any operation just after the response from rpx now
89
- #
90
- # You can use the token to make GET/POST/etc requests
91
81
  def login(env); end
92
82
 
93
-
94
83
  # This is the method that you should override if you want to
95
84
  # perform any operation just before you reach the logout_path
96
85
  def logout(env); end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-rpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Del Gallego
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-17 00:00:00 +01:00
12
+ date: 2010-01-18 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency