Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support v2 api #8

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
30 changes: 15 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ PATH
specs:
omniauth-kakao (0.2.0)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.3.1)
omniauth-oauth2 (~> 1.5.0)

GEM
remote: http://rubygems.org/
specs:
coderay (1.1.1)
diff-lcs (1.2.5)
fakeweb (1.3.0)
faraday (0.9.2)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.14)
formatador (0.2.5)
Expand All @@ -29,38 +29,38 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
hashie (3.4.4)
jwt (1.5.4)
hashie (3.5.7)
jwt (1.5.6)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
lumberjack (1.0.10)
method_source (0.8.2)
multi_json (1.12.1)
multi_xml (0.5.5)
multi_json (1.13.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nenv (0.3.0)
notiffany (0.1.1)
nenv (~> 0.1)
shellany (~> 0.0)
oauth2 (1.2.0)
faraday (>= 0.8, < 0.10)
oauth2 (1.4.0)
faraday (>= 0.8, < 0.13)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
omniauth (1.3.1)
hashie (>= 1.2, < 4)
rack (>= 1.0, < 3)
omniauth-oauth2 (1.3.1)
oauth2 (~> 1.0)
omniauth (1.8.1)
hashie (>= 3.4.6, < 3.6.0)
rack (>= 1.6.2, < 3)
omniauth-oauth2 (1.5.0)
oauth2 (~> 1.1)
omniauth (~> 1.2)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (2.0.1)
rack (2.0.5)
rb-fsevent (0.9.7)
rb-inotify (0.9.7)
ffi (>= 0.5.0)
Expand All @@ -87,4 +87,4 @@ DEPENDENCIES
rspec (~> 2.14, >= 2.14.1)

BUNDLED WITH
1.12.3
1.12.5
38 changes: 18 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,24 @@ Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:

```ruby
{
:provider => 'kakao',
:uid => '123456789',
:info => {
:name => 'Hong Gil-Dong',
:image => 'http://xxx.kakao.com/.../aaa.jpg',
},
:credentials => {
:token => 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store.
:refresh_token => 'OPQRST...', # OAuth 2.0 refresh_token.
:expires_at => 1321747205, # when the access token expires (it always will)
:expires => true # this will always be true
},
:extra => {
:properties => {
:nickname => 'Hong Gil-Dong',
:thumbnail_image => 'http://xxx.kakao.com/.../aaa.jpg'
:profile_image => 'http://xxx.kakao.com/.../bbb.jpg'
}
}
}
provider: kakao
uid: '1656831'
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
name: "김수림"
thumbnail_image: http://mud-kage.kakao.co.kr/14/dn/btqbrEZH0uH/YJAsXaWawNtQ32gwIhdgW0/o.jpg
profile_image: http://mud-kage.kakao.co.kr/14/dn/btqbrCnh7kj/5rkkAq6GASCd1hHhkIxKbK/o.jpg
credentials: !ruby/hash:OmniAuth::AuthHash
token: tneJoAkZy1RG2TCFK2E8TzWRaDZrIqmKzIr11KwQQjMAAAFHkOPavQ
refresh_token: FZdBEjbuJDebaEbilBM992eGShfiZM5rkevTL6wQQjMAAAFHkOPavg
expires_at: 1406906907
expires: true
extra: !ruby/hash:OmniAuth::AuthHash
raw_info: !ruby/hash:OmniAuth::AuthHash
id: 1656831
properties: !ruby/hash:OmniAuth::AuthHash
nickname: "김수림"
thumbnail_image: http://mud-kage.kakao.co.kr/14/dn/btqbrEZH0uH/YJAsXaWawNtQ32gwIhdgW0/o.jpg
profile_image: http://mud-kage.kakao.co.kr/14/dn/btqbrCnh7kj/5rkkAq6GASCd1hHhkIxKbK/o.jpg
```

## Contributors
Expand Down
42 changes: 22 additions & 20 deletions lib/omniauth/strategies/kakao.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,51 @@ class Kakao < OmniAuth::Strategies::OAuth2
option :name, 'kakao'

option :client_options, {
:site => 'https://kauth.kakao.com',
:authorize_path => '/oauth/authorize',
:token_url => '/oauth/token',
site: 'https://kauth.kakao.com',
authorize_path: '/oauth/authorize',
token_url: '/oauth/token',
}

uid { raw_info['id'].to_s }

info do
{
'name' => raw_properties['nickname'],
'image' => raw_properties['thumbnail_image'],
name: raw_properties['nickname'],
image: image,
email: email
}
end

extra do
{'properties' => raw_properties}
{ raw_info: raw_info }
end

def initialize(app, *args, &block)
super
options[:callback_path] = options[:redirect_path] || DEFAULT_REDIRECT_PATH
def callback_url
full_host + script_name + callback_path
end

def callback_phase
previous_callback_path = options.delete(:callback_path)
@env["PATH_INFO"] = "/auth/kakao/callback"
options[:callback_path] = previous_callback_path
super
end
private

def mock_call!(*)
options.delete(:callback_path)
super
def email
return if raw_kakao_account['email'].nil?
return raw_kakao_account['email']
end

private
def image
return if raw_properties['profile_image'].nil?
return raw_properties['profile_image']
end
def raw_info
@raw_info ||= access_token.get('https://kapi.kakao.com/v1/user/me', {}).parsed || {}
@raw_info ||= access_token.get('https://kapi.kakao.com/v2/user/me').parsed
end

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

def raw_kakao_account
@raw_kakao_account ||= raw_info['kakao_account']
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion omniauth-kakao.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]

s.add_dependency 'omniauth', '~> 1.0'
s.add_dependency 'omniauth-oauth2', '~> 1.3.1'
s.add_dependency 'omniauth-oauth2', '~> 1.5.0'

s.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
s.add_development_dependency 'guard-rspec', '~> 4.2', '>= 4.2.8'
Expand Down
13 changes: 0 additions & 13 deletions spec/omniauth/strategies/kakao_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,6 @@ def make_request(url, opts={})
})
end

describe "GET /auth/kakao" do
it "should redirect to callback url (/auth/kakao/callback)" do
request = make_request("/auth/kakao")
middleware = make_middleware(CLIENT_ID)
code, env = middleware.call(request)

code.should == 302

actual_path = URI(env["Location"]).path
actual_path.should == "/auth/kakao/callback"
end
end

describe "GET /oauth" do
it "should request registered mock" do
request = make_request("/oauth")
Expand Down