Class: OmniAuth::Strategies::Playstation

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

Constant Summary collapse

@@force_ssl =
true

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.force_sslObject



25
26
27
# File 'lib/omniauth/strategies/playstation.rb', line 25

def self.force_ssl
  @@force_ssl
end

.force_ssl=(value) ⇒ Object



21
22
23
# File 'lib/omniauth/strategies/playstation.rb', line 21

def self.force_ssl= value
  @@force_ssl = value
end

.psn_auth_envObject



29
30
31
# File 'lib/omniauth/strategies/playstation.rb', line 29

def self.psn_auth_env
  psn_env == 'np' ? '' : "#{psn_env}."
end

.psn_envObject



17
18
19
# File 'lib/omniauth/strategies/playstation.rb', line 17

def self.psn_env
  default_options[:psn_env]
end

.psn_env=(value = 'sp-int') ⇒ Object



12
13
14
15
# File 'lib/omniauth/strategies/playstation.rb', line 12

def self.psn_env= value = 'sp-int'
  option :psn_env, value
  set_client_options
end

.set_client_optionsObject



33
34
35
36
37
38
# File 'lib/omniauth/strategies/playstation.rb', line 33

def self.set_client_options
  option :client_options, {
    site: "https://auth.api.#{psn_auth_env}sonyentertainmentnetwork.com",
    info_url: "https://vl.api.#{psn_env}.ac.playstation.net/vl/api/v1/s2s/users/me/info"
  }
end

Instance Method Details

#build_access_tokenObject



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/omniauth/strategies/playstation.rb', line 60

def build_access_token
  # generate Authorization header
  auth = client.connection.basic_auth(options.client_id, options.client_secret)
  options.token_params[:headers] = { "Authorization" => auth }

  # remove code and state from callback_url
  filtered_query_string = query_string.split('&').reject { |param| param =~ /code=|state=/ }.join
  url = full_host + script_name + callback_path + filtered_query_string

  # original implementation using url instead of callback_url
  verifier = request.params["code"]
  client.auth_code.get_token(verifier, {:redirect_uri => url}.merge(token_params.to_hash(:symbolize_keys => true)), deep_symbolize(options.auth_token_params))
end

#force_sslObject



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

def force_ssl
  @@force_ssl
end

#psn_envObject



40
41
42
# File 'lib/omniauth/strategies/playstation.rb', line 40

def psn_env
  self.class.psn_env
end

#raw_infoObject



89
90
91
92
93
94
# File 'lib/omniauth/strategies/playstation.rb', line 89

def raw_info
  auth_headers = { Authorization: client.connection.basic_auth(options.client_id, options.client_secret) }
  @raw_info ||= JSON.parse(self.client.connection.run_request(:get, "https://auth.api.#{self.class.psn_auth_env}sonyentertainmentnetwork.com/2.0/oauth/token/#{self.access_token.token}", '',  auth_headers).body)
rescue ::Errno::ETIMEDOUT
  raise ::Timeout::Error
end

#redirect_uriObject



52
53
54
55
56
57
58
# File 'lib/omniauth/strategies/playstation.rb', line 52

def redirect_uri
  if force_ssl
    callback_url.gsub(/https?/,'https')
  else
    callback_url
  end
end

#request_phaseObject



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

def request_phase
  redirect client.auth_code.authorize_url({:redirect_uri => redirect_uri}.merge(authorize_params))
end