Skip to content

Commit

Permalink
Merge pull request #416 from nekodex/master
Browse files Browse the repository at this point in the history
Update SoundCloud strategy to use OAuth2
  • Loading branch information
sferik committed Aug 3, 2011
2 parents 5972c94 + 91ea109 commit bc9376f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion oa-oauth/lib/omniauth/oauth.rb
Expand Up @@ -24,7 +24,6 @@ module Strategies
autoload :Plurk, 'omniauth/strategies/oauth/plurk'
autoload :Rdio, 'omniauth/strategies/oauth/rdio'
autoload :SmugMug, 'omniauth/strategies/oauth/smug_mug'
autoload :SoundCloud, 'omniauth/strategies/oauth/sound_cloud'
autoload :T163, 'omniauth/strategies/oauth/t163'
autoload :Tqq, 'omniauth/strategies/oauth/tqq'
autoload :TradeMe, 'omniauth/strategies/oauth/trade_me'
Expand Down Expand Up @@ -54,6 +53,7 @@ module Strategies
autoload :Mixi, 'omniauth/strategies/oauth2/mixi'
autoload :Renren, 'omniauth/strategies/oauth2/renren'
autoload :Salesforce, 'omniauth/strategies/oauth2/salesforce'
autoload :SoundCloud, 'omniauth/strategies/oauth2/sound_cloud'
autoload :TaoBao, 'omniauth/strategies/oauth2/taobao'
autoload :Teambox, 'omniauth/strategies/oauth2/teambox'
autoload :ThirtySevenSignals, 'omniauth/strategies/oauth2/thirty_seven_signals'
Expand Down
Expand Up @@ -3,15 +3,17 @@

module OmniAuth
module Strategies
# Authenticate to SoundCloud via OAuth and retrieve basic
# Authenticate to SoundCloud via OAuth2 and retrieve basic
# user information.
#
# Usage:
# use OmniAuth::Strategies::SoundCloud, 'consumerkey', 'consumersecret'
class SoundCloud < OmniAuth::Strategies::OAuth
class SoundCloud < OmniAuth::Strategies::OAuth2
def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
client_options = {
:site => 'https://api.soundcloud.com',
:authorize_url => 'https://soundcloud.com/connect',
:token_url => 'https://api.soundcloud.com/oauth2/token'
}
super(app, :soundcloud, consumer_key, consumer_secret, client_options, options, &block)
end
Expand Down Expand Up @@ -45,6 +47,14 @@ def user_info
def user_hash
@user_hash ||= MultiJson.decode(@access_token.get('/me.json').body)
end

# OAuth2 by default uses 'Bearer %s' in the header
def build_access_token
access_token = super
access_token.options[:header_format] = "OAuth %s"
access_token
end

end
end
end
@@ -1,5 +1,5 @@
require 'spec_helper'

describe OmniAuth::Strategies::SoundCloud do
it_should_behave_like 'an oauth strategy'
it_should_behave_like "an oauth2 strategy"
end

0 comments on commit bc9376f

Please sign in to comment.