Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds Meetup strategy. Closes #66

  • Loading branch information...
commit f617741b96c5e2088b0cccd1d6378f6081139c27 2 parents 2c05e91 + 58a0bd3
@mbleigh mbleigh authored
View
4 README.markdown
@@ -26,10 +26,12 @@ OmniAuth currently supports the following external providers:
* Gowalla (credit: [kvnsmth](http://github.com/kvnsmth))
* Dopplr (credit: [flextrip](http://github.com/flextrip))
* TripIt (credit: [flextrip](http://github.com/flextrip))
+ * Meetup (credit [coderoshi](http://github.com/coderoshi))
+ * SoundCloud (credit: [leemartin](http://github.com/leemartin))
* OpenID
* Google Apps (via OpenID)
* CAS (Central Authentication Service) (credit: [jamesarosen](http://github.com/jamesarosen))
-* LDAP (credit: **Ping Yu**)
+* LDAP (credit: [pyu10055](http://github.com/pyu10055))
## Usage
View
3  oa-core/lib/omniauth/core.rb
@@ -59,7 +59,8 @@ module Utils
'openid' => 'OpenID',
'open_id' => 'OpenID',
'github' => 'GitHub',
- 'tripit' => 'TripIt'
+ 'tripit' => 'TripIt',
+ 'soundcloud' => 'SoundCloud'
}
module_function
View
1  oa-oauth/lib/omniauth/oauth.rb
@@ -16,5 +16,6 @@ module Strategies
autoload :TripIt, 'omniauth/strategies/trip_it'
autoload :Dopplr, 'omniauth/strategies/dopplr'
autoload :Meetup, 'omniauth/strategies/meetup'
+ autoload :SoundCloud, 'omniauth/strategies/sound_cloud'
end
end
View
46 oa-oauth/lib/omniauth/strategies/sound_cloud.rb
@@ -0,0 +1,46 @@
+require 'omniauth/oauth'
+require 'multi_json'
+
+module OmniAuth
+ module Strategies
+ #
+ # Authenticate to SoundCloud via OAuth and retrieve basic
+ # user information.
+ #
+ # Usage:
+ #
+ # use OmniAuth::Strategies::SoundCloud, 'consumerkey', 'consumersecret'
+ #
+
+ class SoundCloud < OmniAuth::Strategies::OAuth
+ def initialize(app, consumer_key, consumer_secret)
+ super(app, :soundcloud, consumer_key, consumer_secret, :site => 'https://api.soundcloud.com')
+ end
+
+ def auth_hash
+ OmniAuth::Utils.deep_merge(super, {
+ 'uid' => user_hash['id'],
+ 'user_info' => user_info,
+ 'extra' => {'user_hash' => user_hash}
+ })
+ end
+
+ def user_info
+ user_hash = self.user_hash
+
+ {
+ 'name' => user_hash['full_name'],
+ 'nickname' => user_hash['username'],
+ 'location' => user_hash['city'],
+ 'description' => user_hash['description'],
+ 'image' => user_hash['avatar_url'],
+ 'urls' => {'Website' => user_hash['website']}
+ }
+ end
+
+ def user_hash
+ @user_hash ||= MultiJson.decode(@access_token.get('/me.json').body)
+ end
+ end
+ end
+end
View
13 oa-oauth/spec/omniauth/strategies/sound_cloud_spec.rb
@@ -0,0 +1,13 @@
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
+
+describe 'OmniAuth::Strategies::SoundCloud' do
+
+ it 'should subclass OAuth' do
+ OmniAuth::Strategies::SoundCloud.should < OmniAuth::Strategies::OAuth
+ end
+
+ it 'should initialize with just consumer key and secret' do
+ lambda{OmniAuth::Strategies::SoundCloud.new({},'abc','def')}.should_not raise_error
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.