Class: OmniAuth::Strategies::KakaoAccessToken

Inherits:
OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/kakao-access-token.rb

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/omniauth/strategies/kakao-access-token.rb', line 50

def callback_phase
  if !request.params['access_token'] || request.params['access_token'].to_s.empty?
    raise ArgumentError.new("No access token provided.")
  end

  self.access_token = build_access_token
  self.access_token = self.access_token.refresh! if self.access_token.expired?
  
  hash = auth_hash
  hash[:provider] = "kakao"
  self.env['omniauth.auth'] = hash
  call_app!

 rescue ::OAuth::Error => e
   fail!(:invalid_credentials, e)
 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)
end

#raw_infoObject



35
36
37
# File 'lib/omniauth/strategies/kakao-access-token.rb', line 35

def raw_info
  @raw_info ||= access_token.get('https://kapi.kakao.com/v1/user/me', {}).parsed || {}
end

#raw_propertiesObject



39
40
41
# File 'lib/omniauth/strategies/kakao-access-token.rb', line 39

def raw_properties
  @raw_properties ||= raw_info['properties']
end

#request_phaseObject



43
44
45
46
47
48
# File 'lib/omniauth/strategies/kakao-access-token.rb', line 43

def request_phase
  form = OmniAuth::Form.new(:title => "User Token", :url => callback_path)
  form.text_field "Access Token", "access_token"
  form.button "Sign In"
  form.to_response
end