Skip to content

Commit 4caf961

Browse files
author
Agora@Ubuntu-dev
committed
Implement authenticate_url
1 parent 4cb652e commit 4caf961

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

lib/oauth/consumer.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Consumer
2323

2424
# default paths on site. These are the same as the defaults set up by the generators
2525
:request_token_path => '/oauth/request_token',
26+
:authenticate_path => '/oauth/authenticate',
2627
:authorize_path => '/oauth/authorize',
2728
:access_token_path => '/oauth/access_token',
2829

@@ -266,6 +267,10 @@ def request_token_path
266267
@options[:request_token_path]
267268
end
268269

270+
def authenticate_path
271+
@options[:authenticate_path]
272+
end
273+
269274
def authorize_path
270275
@options[:authorize_path]
271276
end
@@ -283,6 +288,14 @@ def request_token_url?
283288
@options.has_key?(:request_token_url)
284289
end
285290

291+
def authenticate_url
292+
@options[:authenticate_url] || site + authenticate_path
293+
end
294+
295+
def authenticate_url?
296+
@options.has_key?(:authenticate_url)
297+
end
298+
286299
def authorize_url
287300
@options[:authorize_url] || site + authorize_path
288301
end

lib/oauth/tokens/request_token.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ def authorize_url(params = nil)
1111
build_authorize_url(consumer.authorize_url, params)
1212
end
1313

14+
def authenticate_url(params = nil)
15+
return nil if self.token.nil?
16+
17+
params = (params || {}).merge(:oauth_token => self.token)
18+
build_authenticate_url(consumer.authenticate_url, params)
19+
end
20+
1421
def callback_confirmed?
1522
params[:oauth_callback_confirmed] == "true"
1623
end
@@ -33,5 +40,16 @@ def build_authorize_url(base_url, params)
3340
uri.query = URI.encode_www_form(queries) if !queries.empty?
3441
uri.to_s
3542
end
43+
44+
# construct an authenticate url
45+
def build_authenticate_url(base_url, params)
46+
uri = URI.parse(base_url.to_s)
47+
queries = {}
48+
queries = Hash[URI.decode_www_form(uri.query)] if uri.query
49+
# TODO doesn't handle array values correctly
50+
queries.merge!(params) if params
51+
uri.query = URI.encode_www_form(queries) if !queries.empty?
52+
uri.to_s
53+
end
3654
end
3755
end

lib/oauth/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module OAuth
2-
VERSION = "0.5.4"
2+
VERSION = "0.5.5"
33
end

0 commit comments

Comments
 (0)