muck-oauth 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -13,10 +13,7 @@ Add the following to environment.rb
13
13
  config.gem "muck-oauth"
14
14
 
15
15
  Add the following to your user model:
16
- has_many :client_applications
17
- has_many :tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
18
-
19
- has_one :twitter_token, :class_name => "TwitterToken", :dependent => :destroy
16
+ acts_as_muck_oauth_user
20
17
 
21
18
  == Usage
22
19
  Add configuration for services to:
@@ -26,5 +23,37 @@ Link to each service like this:
26
23
  <a href="/oauth_consumers/twitter">Twitter</a>
27
24
  <a href="/oauth_consumers/google">Google</a>
28
25
 
26
+ Each service provides methods that enable communication with the service's api via popular gems.
27
+ For example, the twitter service uses the twitter gem and so you can call methods against
28
+ a user's twitter account like this:
29
+
30
+ user.twitter.client.verify_credentials[:screen_name]
31
+
32
+ Please see each gem's documentation for more information:
33
+ Twitter Docs: http://rdoc.info/projects/jnunemaker/twitter
34
+ Twitter Examples: http://github.com/jnunemaker/twitter-app/
35
+ i.e.
36
+ user.twitter.client
37
+
38
+ Linked In Docs: http://github.com/pengwynn/linkedin
39
+ i.e.
40
+ user.linked_in.client
41
+
42
+ Google Docs: http://github.com/pelle/portablecontacts
43
+ i.e.
44
+ user.google.portable_contacts
45
+
46
+ Fire Eagle Docs: http://fireeagle.rubyforge.org/
47
+ i.e.
48
+ user.fire_eagle.client
49
+
50
+ Friend Feed Docs:
51
+ None yet
52
+
53
+ Yahoo Docs:
54
+ None yet
55
+
56
+ Flickr
57
+ None yet
29
58
 
30
59
  Copyright (c) 2009 Tatemae.com. See LICENSE for details.
data/Rakefile CHANGED
@@ -21,6 +21,7 @@ begin
21
21
  gem.add_dependency "portablecontacts"
22
22
  gem.add_dependency "agree2"
23
23
  gem.add_dependency "fireeagle"
24
+ gem.add_dependency "linkedin"
24
25
  gem.add_dependency "muck-engine"
25
26
  gem.add_dependency "muck-users"
26
27
  gem.add_development_dependency "shoulda"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -13,7 +13,8 @@ class OauthConsumersController < ApplicationController
13
13
  # params[:id] holds the service name so you could use this to redirect to various parts
14
14
  # of your application depending on what service you're connecting to.
15
15
  def go_back
16
- redirect_to root_url
16
+ #params[:id]
17
+ redirect_back_or_default('/')
17
18
  end
18
19
 
19
20
  def choose_layout
@@ -34,4 +34,12 @@ module MuckOauthHelper
34
34
  @oauth_services ||= OAUTH_CREDENTIALS.keys-oauth_consumer_tokens(user).collect{ |c| c.class.service_name }
35
35
  end
36
36
 
37
+ def oauth_service_name(service_name)
38
+ name = service_name.to_s.humanize
39
+ name = 'Fire Eagle' if name == 'Fireeagle'
40
+ name = 'LinkedIn' if name == 'Linkedin'
41
+ name = 'FriendFeed' if name == 'Friendfeed'
42
+ name
43
+ end
44
+
37
45
  end
@@ -0,0 +1,21 @@
1
+ class FriendfeedToken < ConsumerToken
2
+ FRIENDFEED_SETTINGS = {
3
+ :site => "https://friendfeed.com",
4
+ :request_token_path => "/account/oauth/request_token",
5
+ :authorize_path => "/account/oauth/authorize",
6
+ :access_token_path => "/accounts/account/oauth/access_token",
7
+ }
8
+
9
+ def self.consumer
10
+ @consumer ||= create_consumer
11
+ end
12
+
13
+ def self.create_consumer(options={})
14
+ OAuth::Consumer.new credentials[:key], credentials[:secret], FRIENDFEED_SETTINGS.merge(options)
15
+ end
16
+
17
+ def self.get_request_token(callback_url)
18
+ consumer.get_request_token({ :oauth_callback => callback_url })
19
+ end
20
+
21
+ end
@@ -0,0 +1,31 @@
1
+ require 'linkedin'
2
+
3
+ class LinkedinToken < ConsumerToken
4
+ LINKEDIN_SETTINGS={
5
+ :site => "https://api.linkedin.com",
6
+ :request_token_path => "/uas/oauth/requestToken",
7
+ :access_token_path => "/uas/oauth/accessToken",
8
+ :authorize_path => "/uas/oauth/authorize"
9
+ }
10
+
11
+ def self.consumer
12
+ @consumer ||= create_consumer
13
+ end
14
+
15
+ def self.create_consumer(options={})
16
+ OAuth::Consumer.new(credentials[:key], credentials[:secret], LINKEDIN_SETTINGS.merge(options))
17
+ end
18
+
19
+ def self.get_request_token(callback_url)
20
+ consumer.get_request_token({ :oauth_callback => callback_url })
21
+ end
22
+
23
+ def client
24
+ unless @client
25
+ @client = LinkedIn::Client.new(LinkedInToken.consumer.key, LinkedInToken.consumer.secret)
26
+ @client.authorize_from_access(token, secret)
27
+ end
28
+ @client
29
+ end
30
+
31
+ end
@@ -0,0 +1,110 @@
1
+ # This was taken from an older version of the oauth-plugin gem.
2
+ class YahooToken < ConsumerToken
3
+ YAHOO_SETTINGS={
4
+ :site => "https://www.yahoo.com",
5
+ :request_token_url => "https://api.login.yahoo.com/oauth/v2/get_request_token",
6
+ :authorize_url => "https://api.login.yahoo.com/oauth/v2/request_auth",
7
+ :access_token_url => "https://api.login.yahoo.com/oauth/v2/get_token"
8
+ }
9
+
10
+ def self.consumer
11
+ @consumer ||= create_consumer
12
+ end
13
+
14
+ def self.create_consumer(options={})
15
+ OAuth::Consumer.new credentials[:key], credentials[:secret],YAHOO_SETTINGS.merge(options)
16
+ end
17
+
18
+ def self.social_apis_consumer
19
+ @social_api_consumer ||= create_consumer :site => "http://social.yahooapis.com/v1"
20
+ end
21
+
22
+ def self.get_request_token(callback_url, scope = nil)
23
+ YahooRequestToken.new consumer.get_request_token({:oauth_callback => callback_url}, :scope => scope || credentials[:scope])
24
+ end
25
+
26
+ # We need to do some special handling to handle this strange parameter:
27
+ #
28
+ class YahooRequestToken < OAuth::RequestToken
29
+ def initialize(real_token)
30
+ super real_token.consumer, real_token.token, real_token.secret
31
+ @params = real_token.params
32
+ end
33
+
34
+ # handle xoauth_request_auth_url
35
+ def authorize_url(params = nil)
36
+ if @params[:xoauth_request_auth_url]
37
+ return @params[:xoauth_request_auth_url]
38
+ else
39
+ super params
40
+ end
41
+ end
42
+ end
43
+
44
+ def social_api
45
+ @social_api ||= SocialAPI.new(OAuth::AccessToken.new( self.class.social_apis_consumer, token, secret))
46
+ end
47
+
48
+ class SocialAPI < Oauth::Models::Consumers::SimpleClient
49
+ # initial implementation of this
50
+ # http://developer.yahoo.com/social/rest_api_guide/index.html
51
+ # Please fork and submit improvements here
52
+ def guid
53
+ @guid ||= get("/v1/me/guid")["guid"]["value"]
54
+ end
55
+
56
+ def usercard
57
+ get("/v1/user/#{guid}/profile/usercard")
58
+ end
59
+
60
+ def idcard
61
+ get("/v1/user/#{guid}/profile/idcard")
62
+ end
63
+
64
+ def tinyusercard
65
+ get("/v1/user/#{guid}/profile/tinyusercard")
66
+ end
67
+
68
+ def profile
69
+ get("/v1/user/#{guid}/profile")
70
+ end
71
+
72
+ def contacts
73
+ get("/v1/user/#{guid}/contacts")
74
+ end
75
+
76
+ end
77
+ end
78
+
79
+
80
+ # I have reported this as a bug to Yahoo, but on certain occassions their tokens are returned with spaces that confuse CGI.parse.
81
+ # The only change below is that it strips the response.body. Once Yahoo fixes this I will remove this whole section.
82
+ module OAuth
83
+ class Consumer
84
+
85
+ def token_request(http_method, path, token = nil, request_options = {}, *arguments)
86
+ response = request(http_method, path, token, request_options, *arguments)
87
+
88
+ case response.code.to_i
89
+
90
+ when (200..299)
91
+ # symbolize keys
92
+ # TODO this could be considered unexpected behavior; symbols or not?
93
+ # TODO this also drops subsequent values from multi-valued keys
94
+
95
+ CGI.parse(response.body.strip).inject({}) do |h,(k,v)|
96
+ h[k.to_sym] = v.first
97
+ h[k] = v.first
98
+ h
99
+ end
100
+ when (300..399)
101
+ # this is a redirect
102
+ response.error!
103
+ when (400..499)
104
+ raise OAuth::Unauthorized, response
105
+ else
106
+ response.error!
107
+ end
108
+ end
109
+ end
110
+ end
@@ -4,7 +4,7 @@
4
4
  <ul <%='class="icon-list"' if include_icons%>>
5
5
  <% services.each do |service| -%>
6
6
  <li class="<%=service.to_s.parameterize%> oauth_service service-link" <%= service_icon_background(service) if include_icons%> title="<%=translate('muck.oauth.connect_to_account_title', :service => service.to_s.humanize) %>">
7
- <%= link_to service.to_s.humanize, oauth_consumer_path(service), :class => 'oauthfancybox iframe' %>
7
+ <%= link_to oauth_service_name(service), oauth_consumer_path(service) %>
8
8
  </li>
9
9
  <% end -%>
10
10
  </ul>
@@ -6,9 +6,9 @@
6
6
  <ul <%='class="icon-list"' if include_icons%>>
7
7
  <% consumer_tokens.each do |token| -%>
8
8
  <li class="<%=token.class.service_name.to_s.parameterize%> oauth_service service-link" <%= service_icon_background(token.class.service_name) if include_icons %>>
9
- <%= link_to token.class.service_name.to_s.humanize, oauth_consumer_path(token.class.service_name), :class => 'oauthfancybox iframe' %>
9
+ <%= link_to oauth_service_name(token.class.service_name), oauth_consumer_path(token.class.service_name), :class => 'oauthfancybox' %>
10
10
  </li>
11
11
  <% end -%>
12
12
  </ul>
13
13
  <% end -%>
14
- </div>
14
+ </div>
@@ -2,46 +2,23 @@
2
2
  # each entry needs a corresponding token model.
3
3
  #
4
4
  # eg. :twitter => TwitterToken, :hour_feed => HourFeedToken etc.
5
- #
6
- # OAUTH_CREDENTIALS={
7
- # get it at: http://twitter.com/apps
8
- # :twitter=>{
9
- # :key=>"",
10
- # :secret=>""
11
- # },
12
- # :google=>{
13
- # :key=>"",
14
- # :secret=>"",
15
- # :scope=>"" # see http://code.google.com/apis/gdata/faq.html#AuthScopes
16
- # },
17
- # :agree2=>{
18
- # :key=>"",
19
- # :secret=>""
20
- # },
21
- # :fireeagle=>{
22
- # :key=>"",
23
- # :secret=>""
24
- # },
25
- # :hour_feed=>{
26
- # :key=>"",
27
- # :secret=>"",
28
- # :options=>{ # OAuth::Consumer options
29
- # :site=>"http://hourfeed.com" # Remember to add a site for a generic OAuth site
30
- # }
31
- # },
32
- # :nu_bux=>{
33
- # :key=>"",
34
- # :secret=>"",
35
- # :super_class=>"OpenTransactToken", # if a OAuth service follows a particular standard
36
- # # with a token implementation you can set the superclass
37
- # # to use
38
- # :options=>{ # OAuth::Consumer options
39
- # :site=>"http://nubux.heroku.com"
40
- # }
41
- # }
42
- # }
43
- #
44
- OAUTH_CREDENTIALS={
45
- } unless defined? OAUTH_CREDENTIALS
46
5
 
6
+ credentials = {}
7
+ credentials[:twitter] = { :key => GlobalConfig.twitter_oauth_key,
8
+ :secret => GlobalConfig.twitter_oauth_secret } if GlobalConfig.twitter_oauth_key
9
+ credentials[:google] = { :scope => "https://mail.google.com/mail/feed/atom/", # see http://code.google.com/apis/gdata/faq.html#AuthScopes
10
+ :key => GlobalConfig.google_oauth_key,
11
+ :secret => GlobalConfig.google_oauth_secret } if GlobalConfig.google_oauth_key
12
+ credentials[:yahoo] = { :key => GlobalConfig.yahoo_oauth_key,
13
+ :secret => GlobalConfig.yahoo_oauth_secret } if GlobalConfig.yahoo_oauth_key
14
+ credentials[:flickr] = { :key => GlobalConfig.flickr_oauth_key,
15
+ :secret => GlobalConfig.flickr_oauth_secret } if GlobalConfig.flickr_oauth_key
16
+ credentials[:linkedin] = { :key => GlobalConfig.linkedin_oauth_key,
17
+ :secret => GlobalConfig.linkedin_oauth_secret } if GlobalConfig.linkedin_oauth_key
18
+ credentials[:fireeagle] = { :key => GlobalConfig.fireeagle_oauth_key,
19
+ :secret => GlobalConfig.fireeagle_oauth_secret } if GlobalConfig.fireeagle_oauth_key
20
+ credentials[:friendfeed] = { :key => GlobalConfig.friendfeed_oauth_key,
21
+ :secret => GlobalConfig.friendfeed_oauth_secret } if GlobalConfig.friendfeed_oauth_key
22
+
23
+ OAUTH_CREDENTIALS = credentials unless defined? OAUTH_CREDENTIALS
47
24
  load 'oauth/models/consumers/service_loader.rb'
@@ -0,0 +1,49 @@
1
+ module ActiveRecord
2
+ module Acts #:nodoc:
3
+ module MuckOauthUser # :nodoc:
4
+
5
+ def self.included(base)
6
+ base.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+
11
+ # +acts_as_muck_oauth_user+ adds Oauth capabilities to a user. Currently, muck-oauth supports the following services:
12
+ # twitter
13
+ # google
14
+ # linkedin
15
+ # yahoo
16
+ # fire_eagle
17
+ # flickr
18
+ # friend_feed
19
+ # After adding this method to a user you will be able to call methods against these services ie:
20
+ # user.linked_in.client.profile
21
+ def acts_as_muck_oauth_user
22
+
23
+ has_many :client_applications
24
+ has_many :tokens, :class_name => "OauthToken", :order => "authorized_at desc", :include => [:client_application]
25
+
26
+ has_one :twitter, :class_name => "TwitterToken", :dependent => :destroy
27
+ has_one :google, :class_name => "GoogleToken", :dependent => :destroy
28
+ has_one :linked_in, :class_name => "LinkedinToken", :dependent => :destroy
29
+ has_one :yahoo, :class_name => "YahooToken", :dependent => :destroy
30
+ has_one :fire_eagle, :class_name => "FireeagleToken", :dependent => :destroy
31
+ has_one :flickr, :class_name => "FlickrToken", :dependent => :destroy
32
+ has_one :friend_feed, :class_name => "FriendfeedToken", :dependent => :destroy
33
+
34
+ include ActiveRecord::Acts::MuckOauthUser::InstanceMethods
35
+ extend ActiveRecord::Acts::MuckOauthUser::SingletonMethods
36
+ end
37
+ end
38
+
39
+ # class methods
40
+ module SingletonMethods
41
+ end
42
+
43
+ module InstanceMethods
44
+
45
+ end
46
+
47
+ end
48
+ end
49
+ end
data/lib/muck_oauth.rb CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
2
  ActionController::Base.send :helper, MuckOauthHelper
3
3
 
4
+ ActiveRecord::Base.class_eval { include ActiveRecord::Acts::MuckOauthUser }
5
+
4
6
  I18n.load_path += Dir[ File.join(File.dirname(__FILE__), '..', 'locales', '*.{rb,yml}') ]
@@ -17,7 +17,7 @@ module MuckOauth
17
17
  task :sync do
18
18
  path = File.join(File.dirname(__FILE__), *%w[.. ..])
19
19
  system "rsync -ruv #{path}/db ."
20
- system "rsync -ruv #{path}/public ."
20
+ #system "rsync -ruv #{path}/public ."
21
21
  if !File.exists('./config/oauth_consumers.rb')
22
22
  system "rsync -ruv #{path}/config/initializers/oauth_consumers.rb ./config/oauth_consumers.rb"
23
23
  end
data/muck-oauth.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{muck-oauth}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Ball"]
12
- s.date = %q{2009-12-21}
12
+ s.date = %q{2009-12-22}
13
13
  s.description = %q{A simple wrapper for the oauth and oauth-plugin gems so that it is faster to include oauth in muck based applications.}
14
14
  s.email = %q{justin@tatemae.com}
15
15
  s.extra_rdoc_files = [
@@ -30,9 +30,12 @@ Gem::Specification.new do |s|
30
30
  "app/models/access_token.rb",
31
31
  "app/models/client_application.rb",
32
32
  "app/models/consumer_token.rb",
33
+ "app/models/friendfeed_token.rb",
34
+ "app/models/linkedin_token.rb",
33
35
  "app/models/oauth_nonce.rb",
34
36
  "app/models/oauth_token.rb",
35
37
  "app/models/request_token.rb",
38
+ "app/models/yahoo_token.rb",
36
39
  "app/views/oauth/authorize.html.erb",
37
40
  "app/views/oauth/authorize_failure.html.erb",
38
41
  "app/views/oauth/authorize_success.html.erb",
@@ -50,6 +53,7 @@ Gem::Specification.new do |s|
50
53
  "config/muck_oauth_routes.rb",
51
54
  "db/migrate/20091205001023_create_oauth_consumer_tokens.rb",
52
55
  "db/migrate/20091210172015_create_oauth_tables.rb",
56
+ "lib/active_record/acts/muck_oauth_user.rb",
53
57
  "lib/muck_oauth.rb",
54
58
  "lib/muck_oauth/initialize_routes.rb",
55
59
  "lib/muck_oauth/tasks.rb",
@@ -1821,6 +1825,7 @@ Gem::Specification.new do |s|
1821
1825
  s.add_runtime_dependency(%q<portablecontacts>, [">= 0"])
1822
1826
  s.add_runtime_dependency(%q<agree2>, [">= 0"])
1823
1827
  s.add_runtime_dependency(%q<fireeagle>, [">= 0"])
1828
+ s.add_runtime_dependency(%q<linkedin>, [">= 0"])
1824
1829
  s.add_runtime_dependency(%q<muck-engine>, [">= 0"])
1825
1830
  s.add_runtime_dependency(%q<muck-users>, [">= 0"])
1826
1831
  s.add_development_dependency(%q<shoulda>, [">= 0"])
@@ -1831,6 +1836,7 @@ Gem::Specification.new do |s|
1831
1836
  s.add_dependency(%q<portablecontacts>, [">= 0"])
1832
1837
  s.add_dependency(%q<agree2>, [">= 0"])
1833
1838
  s.add_dependency(%q<fireeagle>, [">= 0"])
1839
+ s.add_dependency(%q<linkedin>, [">= 0"])
1834
1840
  s.add_dependency(%q<muck-engine>, [">= 0"])
1835
1841
  s.add_dependency(%q<muck-users>, [">= 0"])
1836
1842
  s.add_dependency(%q<shoulda>, [">= 0"])
@@ -1842,6 +1848,7 @@ Gem::Specification.new do |s|
1842
1848
  s.add_dependency(%q<portablecontacts>, [">= 0"])
1843
1849
  s.add_dependency(%q<agree2>, [">= 0"])
1844
1850
  s.add_dependency(%q<fireeagle>, [">= 0"])
1851
+ s.add_dependency(%q<linkedin>, [">= 0"])
1845
1852
  s.add_dependency(%q<muck-engine>, [">= 0"])
1846
1853
  s.add_dependency(%q<muck-users>, [">= 0"])
1847
1854
  s.add_dependency(%q<shoulda>, [">= 0"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muck-oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Ball
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-21 00:00:00 -07:00
12
+ date: 2009-12-22 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -72,6 +72,16 @@ dependencies:
72
72
  - !ruby/object:Gem::Version
73
73
  version: "0"
74
74
  version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: linkedin
77
+ type: :runtime
78
+ version_requirement:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
75
85
  - !ruby/object:Gem::Dependency
76
86
  name: muck-engine
77
87
  type: :runtime
@@ -125,9 +135,12 @@ files:
125
135
  - app/models/access_token.rb
126
136
  - app/models/client_application.rb
127
137
  - app/models/consumer_token.rb
138
+ - app/models/friendfeed_token.rb
139
+ - app/models/linkedin_token.rb
128
140
  - app/models/oauth_nonce.rb
129
141
  - app/models/oauth_token.rb
130
142
  - app/models/request_token.rb
143
+ - app/models/yahoo_token.rb
131
144
  - app/views/oauth/authorize.html.erb
132
145
  - app/views/oauth/authorize_failure.html.erb
133
146
  - app/views/oauth/authorize_success.html.erb
@@ -145,6 +158,7 @@ files:
145
158
  - config/muck_oauth_routes.rb
146
159
  - db/migrate/20091205001023_create_oauth_consumer_tokens.rb
147
160
  - db/migrate/20091210172015_create_oauth_tables.rb
161
+ - lib/active_record/acts/muck_oauth_user.rb
148
162
  - lib/muck_oauth.rb
149
163
  - lib/muck_oauth/initialize_routes.rb
150
164
  - lib/muck_oauth/tasks.rb