github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

pelle / oauth-plugin

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 231
    • 26
  • Source
  • Commits
  • Network (26)
  • Issues (7)
  • Downloads (1)
  • Wiki (1)
  • Graphs
  • Tree: 019761c

click here to add a description

click here to add a homepage

  • Branches (3)
    • master
    • oauth1_0
    • oauth1_0a
  • Tags (1)
    • v0.3.11
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Rails plugin for OAuth — Read more

  cancel

http://stakeventures.com/articles/2009/07/21/consuming-oauth-intelligently-in-rails

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added a SimpleClient wrapper to make it easy to implement simple json 
clients ontop of access tokens. 
pelle (author)
Wed Sep 30 15:56:25 -0700 2009
commit  019761c04b690cb92bf4dc7280e977f0e1c6eb36
tree    75464ab6c67d90673287d13141a4a1658b4eaf20
parent  7e2a74f1fad9225fb32b1cf665096e5ade9f0cd6
oauth-plugin / lib / oauth / models / consumers / services / yahoo_token.rb lib/oauth/models/consumers/services/yahoo_token.rb
100644 109 lines (89 sloc) 3.172 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
class YahooToken < ConsumerToken
  YAHOO_SETTINGS={
    :site=>"https://www.yahoo.com",
    :request_token_url => "https://api.login.yahoo.com/oauth/v2/get_request_token",
    :authorize_url => "https://api.login.yahoo.com/oauth/v2/request_auth",
    :access_token_url => "https://api.login.yahoo.com/oauth/v2/get_token"
  }
  
  def self.consumer
    @consumer||=create_consumer
  end
  
  def self.create_consumer(options={})
    OAuth::Consumer.new credentials[:key],credentials[:secret],YAHOO_SETTINGS.merge(options)
  end
  
  def self.social_apis_consumer
    @social_api_consumer||=create_consumer :site=>"http://social.yahooapis.com/v1"
  end
  
  def self.get_request_token(callback_url, scope=nil)
    YahooRequestToken.new consumer.get_request_token({:oauth_callback=>callback_url}, :scope=>scope||credentials[:scope])
  end
  
  # We need to do some special handling to handle this strange parameter:
  #
  class YahooRequestToken < OAuth::RequestToken
    def initialize(real_token)
      super real_token.consumer,real_token.token,real_token.secret
      @params=real_token.params
    end
    
    # handle xoauth_request_auth_url
    def authorize_url(params = nil)
      if @params[:xoauth_request_auth_url]
        return @params[:xoauth_request_auth_url]
      else
        super params
      end
    end
  end
  
  def social_api
    @social_api ||= SocialAPI.new(OAuth::AccessToken.new( self.class.social_apis_consumer, token, secret))
  end
  
  class SocialAPI < Oauth::Models::Consumers::SimpleClient
    # initial implementation of this
    # http://developer.yahoo.com/social/rest_api_guide/index.html
    # Please fork and submit improvements here
    def guid
      @guid||=get("/v1/me/guid")["guid"]["value"]
    end
    
    def usercard
      get("/v1/user/#{guid}/profile/usercard")
    end
    
    def idcard
      get("/v1/user/#{guid}/profile/idcard")
    end
    
    def tinyusercard
      get("/v1/user/#{guid}/profile/tinyusercard")
    end
    
    def profile
      get("/v1/user/#{guid}/profile")
    end
    
    def contacts
      get("/v1/user/#{guid}/contacts")
    end
 
  end
end
 
 
# I have reported this as a bug to Yahoo, but on certain occassions their tokens are returned with spaces that confuse CGI.parse.
# The only change below is that it strips the response.body. Once Yahoo fixes this I will remove this whole section.
module OAuth
  class Consumer
    
    def token_request(http_method, path, token = nil, request_options = {}, *arguments)
      response = request(http_method, path, token, request_options, *arguments)
 
      case response.code.to_i
 
      when (200..299)
        # symbolize keys
        # TODO this could be considered unexpected behavior; symbols or not?
        # TODO this also drops subsequent values from multi-valued keys
        
        CGI.parse(response.body.strip).inject({}) do |h,(k,v)|
          h[k.to_sym] = v.first
          h[k] = v.first
          h
        end
      when (300..399)
        # this is a redirect
        response.error!
      when (400..499)
        raise OAuth::Unauthorized, response
      else
        response.error!
      end
    end
  end
end
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server