Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Supporting path prefixes throughout the plugin.
  • Loading branch information
Michael Bleigh committed Mar 27, 2009
1 parent dc1bb07 commit 1364bd4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Expand Up @@ -48,7 +48,7 @@ def oauth_callback
cookies[:remember_token] = @user.remember_me

authentication_succeeded
rescue Net::HTTPServerException, Net::HTTPFatalError => e
rescue Net::HTTPServerException, Net::HTTPFatalError, TwitterAuth::Dispatcher::Error => e
case e.message
when '401 "Unauthorized"'
authentication_failed('This authentication request is no longer valid. Please try again.') and return
Expand Down
8 changes: 5 additions & 3 deletions app/models/twitter_auth/oauth_user.rb
Expand Up @@ -6,14 +6,16 @@ def self.included(base)
end

base.extend TwitterAuth::OauthUser::ClassMethods
base.extend TwitterAuth::Dispatcher::Shared
end

module ClassMethods
def identify_or_create_from_access_token(token, secret=nil)
raise ArgumentError, 'Must authenticate with an OAuth::AccessToken or the string access token and secret.' unless (token && secret) || token.is_a?(OAuth::AccessToken)

user_info = JSON.parse(token.get('/account/verify_credentials.json').body)


response = token.get(TwitterAuth.path_prefix + '/account/verify_credentials.json')
user_info = handle_response(response)

if user = User.find_by_login(user_info['screen_name'])
user.assign_twitter_attributes(user_info)
user.access_token = token.token
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter_auth/dispatcher/oauth.rb
Expand Up @@ -16,7 +16,7 @@ def initialize(user)
def request(http_method, path, *arguments)
path = TwitterAuth.path_prefix + path
path = append_extension_to(path)

response = super

handle_response(response)
Expand Down
2 changes: 2 additions & 0 deletions lib/twitter_auth/dispatcher/shared.rb
Expand Up @@ -15,6 +15,8 @@ def handle_response(response)
rescue JSON::ParserError
response.body
end
when Net::HTTPUnauthorized
raise TwitterAuth::Dispatcher::Error, 'The credentials provided did not authorize the user.'
else
message = begin
JSON.parse(response.body)['error']
Expand Down

0 comments on commit 1364bd4

Please sign in to comment.