Skip to content

Commit

Permalink
Adds Meetup strategy. Closes omniauth#66
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bleigh committed Oct 25, 2010
2 parents 2c05e91 + 58a0bd3 commit f617741
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.markdown
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion oa-core/lib/omniauth/core.rb
Expand Up @@ -59,7 +59,8 @@ module Utils
'openid' => 'OpenID',
'open_id' => 'OpenID',
'github' => 'GitHub',
'tripit' => 'TripIt'
'tripit' => 'TripIt',
'soundcloud' => 'SoundCloud'
}

module_function
Expand Down
1 change: 1 addition & 0 deletions oa-oauth/lib/omniauth/oauth.rb
Expand Up @@ -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
46 changes: 46 additions & 0 deletions 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
13 changes: 13 additions & 0 deletions 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

0 comments on commit f617741

Please sign in to comment.