Class: OmniAuth::Strategies::SoundCloud

Inherits:
OAuth2
  • Object
show all
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

Methods inherited from OAuth2

#callback_url, #client

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, 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

Instance Method Details

#auth_hashObject



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' => ,
      'extra' => {
        'user_hash' => user_hash,
      }
    }
  )
end

#build_access_tokenObject

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.options[:header_format] = "OAuth %s"
  access_token
end

#user_hashObject



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_infoObject



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_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