Class: OmniAuth::Strategies::SoundCloud
- Defined in:
- lib/omniauth/strategies/oauth2/sound_cloud.rb
Overview
Authenticate to SoundCloud via OAuth2 and retrieve basic user information.
Usage: use OmniAuth::Strategies::SoundCloud, 'consumerkey', 'consumersecret'
Instance Attribute Summary
Attributes inherited from OAuth2
#client_id, #client_options, #client_secret, #options
Instance Method Summary collapse
- #auth_hash ⇒ Object
-
#build_access_token ⇒ Object
OAuth2 by default uses 'Bearer %s' in the header.
-
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ SoundCloud
constructor
A new instance of SoundCloud.
- #user_hash ⇒ Object
- #user_info ⇒ Object
Methods inherited from OAuth2
Constructor Details
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ SoundCloud
Returns a new instance of SoundCloud.
12 13 14 15 16 17 18 19 |
# File 'lib/omniauth/strategies/oauth2/sound_cloud.rb', line 12 def initialize(app, consumer_key=nil, consumer_secret=nil, ={}, &block) = { :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, , , &block) end |
Instance Method Details
#auth_hash ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/omniauth/strategies/oauth2/sound_cloud.rb', line 21 def auth_hash OmniAuth::Utils.deep_merge( super, { 'uid' => user_hash['id'], 'user_info' => user_info, 'extra' => { 'user_hash' => user_hash, } } ) end |
#build_access_token ⇒ Object
OAuth2 by default uses 'Bearer %s' in the header
52 53 54 55 56 |
# File 'lib/omniauth/strategies/oauth2/sound_cloud.rb', line 52 def build_access_token access_token = super access_token.[:header_format] = "OAuth %s" access_token end |
#user_hash ⇒ Object
47 48 49 |
# File 'lib/omniauth/strategies/oauth2/sound_cloud.rb', line 47 def user_hash @user_hash ||= MultiJson.decode(@access_token.get('/me.json').body) end |
#user_info ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/omniauth/strategies/oauth2/sound_cloud.rb', line 33 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 |