Class: OmniAuth::Strategies::ParallelMarkets

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/parallelmarkets.rb

Instance Method Summary collapse

Instance Method Details

#accreditationsObject



73
74
75
# File 'lib/omniauth/strategies/parallelmarkets.rb', line 73

def accreditations
  @accreditations ||= raw_accreditations.fetch('accreditations', [])
end

#authorize_paramsObject



35
36
37
38
39
40
41
# File 'lib/omniauth/strategies/parallelmarkets.rb', line 35

def authorize_params
  super.tap do |params|
    options[:authorize_options].each do |k|
      params[k] = request.params[k.to_s] if request.params[k.to_s]
    end
  end
end

#authorize_scopesObject

if given ?scope query parameter, use that. otherwise, use server-side provider configuration



53
54
55
# File 'lib/omniauth/strategies/parallelmarkets.rb', line 53

def authorize_scopes
  @authorize_scopes ||= (env['omniauth.params']['scope'] || authorize_params['scope']).split(' ')
end

#callback_urlObject

this is dumb, but github.com/omniauth/omniauth-oauth2/issues/93 is still open



44
45
46
# File 'lib/omniauth/strategies/parallelmarkets.rb', line 44

def callback_url
  options[:redirect_uri] || (full_host + script_name + callback_path)
end

#profileObject



61
62
63
# File 'lib/omniauth/strategies/parallelmarkets.rb', line 61

def profile
  @profile ||= raw_info.fetch('profile', {})
end

#raw_accreditationsObject



69
70
71
# File 'lib/omniauth/strategies/parallelmarkets.rb', line 69

def raw_accreditations
  @raw_accreditations ||= scope?(:accreditation_status) ? access_token.get('/v1/accreditations').parsed : {}
end

#raw_infoObject



57
58
59
# File 'lib/omniauth/strategies/parallelmarkets.rb', line 57

def raw_info
  @raw_info ||= scope?(:profile) ? access_token.get('/v1/me').parsed : {}
end

#scope?(single_scope) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/omniauth/strategies/parallelmarkets.rb', line 48

def scope?(single_scope)
  authorize_scopes.include?(single_scope.to_s)
end

#to_contact_details(contact) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/omniauth/strategies/parallelmarkets.rb', line 77

def to_contact_details(contact)
  (contact.nil? || contact.empty?) ? {} : {
    name: contact['name'] || "#{contact['first_name']} #{contact['last_name']}",
    first_name: contact['first_name'],
    last_name: contact['last_name'],
    email: contact['email']
  }
end

#user_profileObject



65
66
67
# File 'lib/omniauth/strategies/parallelmarkets.rb', line 65

def 
  @user_profile ||= raw_info.fetch('user_profile', {})
end