Class: OmniAuth::Strategies::Zaif

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

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject



17
18
19
20
21
# File 'lib/omniauth/strategies/zaif.rb', line 17

def authorize_params
  super.tap do |params|
    params[:scope] ||= 'id_info'
  end
end

#callback_phaseObject



55
56
57
58
59
# File 'lib/omniauth/strategies/zaif.rb', line 55

def callback_phase
  super
rescue StandardError => e
  fail!(:unkown_error, e)
end

#raw_infoObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/omniauth/strategies/zaif.rb', line 34

def raw_info
  return @raw_info if @raw_info

  uri = URI.parse('https://api.zaif.jp/tapi')
  https = Net::HTTP.new(uri.host, uri.port)

  https.use_ssl = true
  req = Net::HTTP::Post.new(uri.request_uri)

  req['token'] = access_token.token
  req.set_form_data({nonce: Time.now.to_f, method: 'get_id_info'})
  res = https.request(req)

  raise "failed to execute get_id_info. http status code: #{res.code}" unless res.code.to_i == 200

  res = JSON.load(res.body)
  raise "failed to execute get_id_info. error: #{res['error']}" unless res['success'] == 1

  @raw_info = res['return']['user']
end