Class: OmniAuth::Strategies::Deezer

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omniauth/strategies/deezer.rb

Defined Under Namespace

Classes: CredentialsError

Constant Summary collapse

DEFAULT_PERMS =
"basic_access"

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject

callback phase



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/omniauth/strategies/deezer.rb', line 36

def callback_phase
  begin
    if request.params['error_reason'] then 
      raise CredentialsError, request.params['error_reason'] 
    end

    # get token from Deezer
    token_url = options.client_options.token_url+'?app_id='+options.app_id+'&secret='+options.app_secret+'&code='+request.params['code']
    response = Faraday.get token_url
    response_hash = CGI::parse(response.body.chomp)
    @access_token = response_hash['access_token'][0]
    @token_expires_at = response_hash['expires'][0].to_i
    me_path = options.client_options.me_url+'?access_token='+@access_token
    # get info from current user
    response = Faraday.get me_path
    @raw_info = MultiJson.decode(response.body.chomp)

    super

  rescue ::MultiJson::DecodeError => e
    fail!(:invalid_response, e)
  rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
    fail!(:timeout, e)
  rescue ::SocketError => e
    fail!(:failed_to_connect, e)
  rescue TypeError => e
    fail!(:invalid_response, e)
  rescue CredentialsError => e                      
    fail!(:invalid_credentials, e)
  end
end

#request_phaseObject



28
29
30
31
32
# File 'lib/omniauth/strategies/deezer.rb', line 28

def request_phase
  options.perms ||= DEFAULT_PERMS
  redirecting_to = options.client_options.authorize_url+'?app_id='+options.app_id+'&redirect_uri='+CGI::escape(callback_url)+'&perms='+options.perms
  redirect redirecting_to
end