forked from omniauth/omniauth
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Meetup strategy. Closes omniauth#66
- Loading branch information
Showing
5 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |