Skip to content

Commit

Permalink
Access token request returns an optional refresh token.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed Apr 25, 2010
1 parent 8466973 commit b8a74e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/oauth2/access_token.rb
@@ -1,10 +1,11 @@
module OAuth2
class AccessToken
attr_reader :client, :token
attr_reader :client, :token, :refresh_token

def initialize(client, token)
def initialize(client, token, refresh_token = nil)
@client = client
@token = token
@refresh_token = refresh_token
end

def request(verb, path, params = {}, headers = {})
Expand All @@ -27,4 +28,4 @@ def delete(path, params = {}, headers = {})
request(:delete, path, params, headers)
end
end
end
end
5 changes: 3 additions & 2 deletions lib/oauth2/strategy/web_server.rb
Expand Up @@ -12,8 +12,9 @@ def authorize_params(options = {}) #:nodoc:
def get_access_token(code, options = {})
response = @client.request(:post, @client.access_token_url, access_token_params(code, options))
params = Rack::Utils.parse_query(response)
token = params['access_token']
OAuth2::AccessToken.new(@client, token)
access = params['access_token']
refresh = params['refresh_token']
OAuth2::AccessToken.new(@client, access, refresh)
end

# <b>DEPRECATED:</b> Use #get_access_token instead.
Expand Down
6 changes: 5 additions & 1 deletion spec/oauth2/strategy/web_server_spec.rb
Expand Up @@ -6,7 +6,7 @@
cli.connection.build do |b|
b.adapter :test do |stub|
stub.post('/oauth/access_token?code=sushi&client_id=abc&client_secret=def&type=web_server') do |env|
[200, {}, 'a=1&access_token=salmon']
[200, {}, 'a=1&access_token=salmon&refresh_token=trout']
end
end
end
Expand Down Expand Up @@ -41,5 +41,9 @@
it 'returns AccessToken with #token' do
@access.token.should == 'salmon'
end

it 'returns AccessToken with #refresh_token' do
@access.refresh_token.should == 'trout'
end
end
end

0 comments on commit b8a74e0

Please sign in to comment.