omniauth-kakao-bucketplace 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/CHANGELOG +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +88 -0
- data/Guardfile +8 -0
- data/README.md +128 -0
- data/Rakefile +2 -0
- data/example/Gemfile +5 -0
- data/example/Gemfile.lock +50 -0
- data/example/app.rb +147 -0
- data/lib/omniauth-kakao-bucketplace.rb +2 -0
- data/lib/omniauth-kakao/version.rb +5 -0
- data/lib/omniauth/strategies/kakao.rb +72 -0
- data/omniauth-kakao-bucketplace.gemspec +29 -0
- data/spec/omniauth/strategies/kakao_spec.rb +193 -0
- data/spec/spec_helper.rb +23 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 787e2d0fd72746821f85b7b1cd4aa84f1c927099
|
4
|
+
data.tar.gz: 4256b5eff6a84151eb1f0009415fdaca4a1189d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b3a8b3be0d3c438a27085aa8183855419a8f3fcbade791bdb82beb57d39f9f3491563abb858f8260fa418b16c8854bcff8384e5a53566b7612fdf361d77800a5
|
7
|
+
data.tar.gz: ed4f80f5fde0205e31f9a79545eb4b44714c3d2357f6cd823a9ff65e47fc900c83c1a3b233bd51b0a4c719b9169b84249454f5eb5e018eef0133a47ca1f08066
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/.rspec
ADDED
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
omniauth-kakao (0.1.2)
|
5
|
+
omniauth (~> 1.0)
|
6
|
+
omniauth-oauth2 (~> 1.3.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.1.0)
|
12
|
+
diff-lcs (1.2.5)
|
13
|
+
fakeweb (1.3.0)
|
14
|
+
faraday (0.9.2)
|
15
|
+
multipart-post (>= 1.2, < 3)
|
16
|
+
ffi (1.9.10)
|
17
|
+
formatador (0.2.5)
|
18
|
+
guard (2.13.0)
|
19
|
+
formatador (>= 0.2.4)
|
20
|
+
listen (>= 2.7, <= 4.0)
|
21
|
+
lumberjack (~> 1.0)
|
22
|
+
nenv (~> 0.1)
|
23
|
+
notiffany (~> 0.0)
|
24
|
+
pry (>= 0.9.12)
|
25
|
+
shellany (~> 0.0)
|
26
|
+
thor (>= 0.18.1)
|
27
|
+
guard-compat (1.2.1)
|
28
|
+
guard-rspec (4.6.4)
|
29
|
+
guard (~> 2.1)
|
30
|
+
guard-compat (~> 1.1)
|
31
|
+
rspec (>= 2.99.0, < 4.0)
|
32
|
+
hashie (3.4.3)
|
33
|
+
jwt (1.5.1)
|
34
|
+
listen (3.0.6)
|
35
|
+
rb-fsevent (>= 0.9.3)
|
36
|
+
rb-inotify (>= 0.9.7)
|
37
|
+
lumberjack (1.0.10)
|
38
|
+
method_source (0.8.2)
|
39
|
+
multi_json (1.11.2)
|
40
|
+
multi_xml (0.5.5)
|
41
|
+
multipart-post (2.0.0)
|
42
|
+
nenv (0.3.0)
|
43
|
+
notiffany (0.0.8)
|
44
|
+
nenv (~> 0.1)
|
45
|
+
shellany (~> 0.0)
|
46
|
+
oauth2 (1.1.0)
|
47
|
+
faraday (>= 0.8, < 0.10)
|
48
|
+
jwt (~> 1.0, < 1.5.2)
|
49
|
+
multi_json (~> 1.3)
|
50
|
+
multi_xml (~> 0.5)
|
51
|
+
rack (>= 1.2, < 3)
|
52
|
+
omniauth (1.3.1)
|
53
|
+
hashie (>= 1.2, < 4)
|
54
|
+
rack (>= 1.0, < 3)
|
55
|
+
omniauth-oauth2 (1.3.1)
|
56
|
+
oauth2 (~> 1.0)
|
57
|
+
omniauth (~> 1.2)
|
58
|
+
pry (0.10.3)
|
59
|
+
coderay (~> 1.1.0)
|
60
|
+
method_source (~> 0.8.1)
|
61
|
+
slop (~> 3.4)
|
62
|
+
rack (1.6.4)
|
63
|
+
rb-fsevent (0.9.7)
|
64
|
+
rb-inotify (0.9.7)
|
65
|
+
ffi (>= 0.5.0)
|
66
|
+
rspec (2.99.0)
|
67
|
+
rspec-core (~> 2.99.0)
|
68
|
+
rspec-expectations (~> 2.99.0)
|
69
|
+
rspec-mocks (~> 2.99.0)
|
70
|
+
rspec-core (2.99.2)
|
71
|
+
rspec-expectations (2.99.2)
|
72
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
73
|
+
rspec-mocks (2.99.4)
|
74
|
+
shellany (0.0.1)
|
75
|
+
slop (3.6.0)
|
76
|
+
thor (0.19.1)
|
77
|
+
|
78
|
+
PLATFORMS
|
79
|
+
ruby
|
80
|
+
|
81
|
+
DEPENDENCIES
|
82
|
+
fakeweb (~> 1.3, >= 1.3.0)
|
83
|
+
guard-rspec (~> 4.2, >= 4.2.8)
|
84
|
+
omniauth-kakao!
|
85
|
+
rspec (~> 2.14, >= 2.14.1)
|
86
|
+
|
87
|
+
BUNDLED WITH
|
88
|
+
1.11.2
|
data/Guardfile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :rspec, :cmd => "bundle exec rspec spec" do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# OmniAuth Kakao
|
2
|
+
|
3
|
+
This is the OmniAuth strategy for authenticating to [Kakao](http://www.kakao.com/). To
|
4
|
+
use it, you'll need to sign up for an REST API Key on the [Kakao Developers Page](http://developers.kakao.com). For more information, please refer to [Create New Application](https://developers.kakao.com/docs/restapi#시작하기-앱-생성) page.
|
5
|
+
|
6
|
+
[카카오](http://www.kakao.com/) 인증을 위한 OmniAuth strategy 입니다. [카카오 개발자 페이지](http://developers.kakao.com)에서 REST API 키를 생성한 뒤 이용해 주세요. 자세한 사항은 [시작하기 - 앱 생성](https://developers.kakao.com/docs/restapi#시작하기-앱-생성) 페이지를 참고하시기 바랍니다.
|
7
|
+
|
8
|
+
## Installing
|
9
|
+
|
10
|
+
Add to your `Gemfile`:
|
11
|
+
|
12
|
+
`Gemfile`에 다음의 코드를 넣어주세요.
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'omniauth-kakao'
|
16
|
+
```
|
17
|
+
|
18
|
+
Then `bundle install`.
|
19
|
+
|
20
|
+
이후 `bundle install` 을 실행해 주세요.
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
25
|
+
|
26
|
+
다음은 간단한 예제입니다. `config/initializers/omniauth.rb`에서 미들웨어(Middleware)를 레일즈 어플리케이션에 넣어주세요.
|
27
|
+
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
31
|
+
provider :kakao, ENV['KAKAO_CLIENT_ID']
|
32
|
+
|
33
|
+
# 또는 Redirect Path를 설정하고 싶다면(or if you want to customize your Redirect Path)
|
34
|
+
# provider :kakao, ENV['KAKAO_CLIENT_ID'], {:redirect_path => ENV['REDIRECT_PATH']}
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
Then go to [My Application](https://developers.kakao.com/apps) page, select your current application and add your domain address(ex: http://localhost:3000/) to 'Setting - Platform - Web - Site Domain'.
|
39
|
+
|
40
|
+
그리고 [내 어플리케이션](https://developers.kakao.com/apps)에서 현재 어플리케이션을 선택하고, '설정 - 플랫폼 - 웹 - 사이트 도메인'에 도메인 주소(예: http://localhost:3000/)를 넣어주세요.
|
41
|
+
|
42
|
+

|
43
|
+
|
44
|
+
For more information, please read the [OmniAuth](https://github.com/intridea/omniauth) docs for detailed instructions.
|
45
|
+
|
46
|
+
더 자세한 사항은 [OmniAuth](https://github.com/intridea/omniauth)의 문서를 참고해 주세요.
|
47
|
+
|
48
|
+
## Example
|
49
|
+
|
50
|
+
You can test omniauth-kakao in the `example/` folder.
|
51
|
+
|
52
|
+
`example/` 폴더에 있는 예제를 통해 omniauth-kakao를 테스트해볼 수 있습니다.
|
53
|
+
|
54
|
+
```
|
55
|
+
cd example/
|
56
|
+
bundle install
|
57
|
+
KAKAO_CLIENT_ID='<your-kakako-client-id>' ruby app.rb
|
58
|
+
|
59
|
+
# 또는 Redirect Path를 설정하고 싶다면(or if you want to customize your Redirect Path)
|
60
|
+
# KAKAO_CLIENT_ID='<your-kakako-client-id>' REDIRECT_PATH='<your-redirect-path>' ruby app.rb
|
61
|
+
```
|
62
|
+
|
63
|
+
Then open `http://localhost:4567/` in your browser.
|
64
|
+
|
65
|
+
이후 `http://localhost:4567/`로 접속하시면 됩니다.
|
66
|
+
|
67
|
+
Warning: Do not forgot to add `http://localhost:4567/` in [My Application](https://developers.kakao.com/apps).
|
68
|
+
|
69
|
+
주의: [내 어플리케이션](https://developers.kakao.com/apps) 의 '설정된 플랫폼 - 웹 - 사이트 도메인'에 `http://localhost:4567/`을 넣는 걸 잊지 마세요.
|
70
|
+
|
71
|
+
## Auth Hash
|
72
|
+
|
73
|
+
Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:
|
74
|
+
|
75
|
+
`request.env['omniauth.auth']` 안에 들어있는 *Auth Hash* 는 다음과 같습니다.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
{
|
79
|
+
:provider => 'kakao',
|
80
|
+
:uid => '123456789',
|
81
|
+
:info => {
|
82
|
+
:name => 'Hong Gil-Dong',
|
83
|
+
:image => 'http://xxx.kakao.com/.../aaa.jpg',
|
84
|
+
},
|
85
|
+
:credentials => {
|
86
|
+
:token => 'ABCDEF...', # OAuth 2.0 access_token, which you may wish to store.
|
87
|
+
:refresh_token => 'OPQRST...', # OAuth 2.0 refresh_token.
|
88
|
+
:expires_at => 1321747205, # when the access token expires (it always will)
|
89
|
+
:expires => true # this will always be true
|
90
|
+
},
|
91
|
+
:extra => {
|
92
|
+
:properties => {
|
93
|
+
:nickname => 'Hong Gil-Dong',
|
94
|
+
:thumbnail_image => 'http://xxx.kakao.com/.../aaa.jpg'
|
95
|
+
:profile_image => 'http://xxx.kakao.com/.../bbb.jpg'
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
```
|
100
|
+
|
101
|
+
## Contributors
|
102
|
+
* [Shayne Sung-Hee Kang](https://github.com/shaynekang)
|
103
|
+
* [Hong Chulju](https://github.com/fegs)
|
104
|
+
|
105
|
+
## Contribute
|
106
|
+
|
107
|
+
1. Fork the repository.
|
108
|
+
1. Create a new branch for each feature or improvement.
|
109
|
+
1. Add tests for it. This is important!
|
110
|
+
1. Send a pull request from each feature branch.
|
111
|
+
|
112
|
+
***
|
113
|
+
|
114
|
+
1. 저장소를 Fork해 주세요.
|
115
|
+
1. 새로운 기능(또는 개선할 부분)마다 브랜치를 만들어 주세요.
|
116
|
+
1. 테스트를 작성해주세요. 이는 매우 중요합니다!
|
117
|
+
1. 브랜치를 pull request로 보내주세요.
|
118
|
+
|
119
|
+
|
120
|
+
## License
|
121
|
+
|
122
|
+
Copyright (c) 2014 [Shayne Sung-Hee Kang](http://medium.com/@shaynekang).
|
123
|
+
|
124
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
125
|
+
|
126
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
127
|
+
|
128
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/example/Gemfile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
omniauth-kakao (0.1.2)
|
5
|
+
omniauth (~> 1.0)
|
6
|
+
omniauth-oauth2 (~> 1.3.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
faraday (0.9.2)
|
12
|
+
multipart-post (>= 1.2, < 3)
|
13
|
+
hashie (3.4.3)
|
14
|
+
jwt (1.5.1)
|
15
|
+
multi_json (1.11.2)
|
16
|
+
multi_xml (0.5.5)
|
17
|
+
multipart-post (2.0.0)
|
18
|
+
oauth2 (1.1.0)
|
19
|
+
faraday (>= 0.8, < 0.10)
|
20
|
+
jwt (~> 1.0, < 1.5.2)
|
21
|
+
multi_json (~> 1.3)
|
22
|
+
multi_xml (~> 0.5)
|
23
|
+
rack (>= 1.2, < 3)
|
24
|
+
omniauth (1.3.1)
|
25
|
+
hashie (>= 1.2, < 4)
|
26
|
+
rack (>= 1.0, < 3)
|
27
|
+
omniauth-oauth2 (1.3.1)
|
28
|
+
oauth2 (~> 1.0)
|
29
|
+
omniauth (~> 1.2)
|
30
|
+
rack (1.5.2)
|
31
|
+
rack-protection (1.5.3)
|
32
|
+
rack
|
33
|
+
shotgun (0.9)
|
34
|
+
rack (>= 1.0)
|
35
|
+
sinatra (1.4.5)
|
36
|
+
rack (~> 1.4)
|
37
|
+
rack-protection (~> 1.4)
|
38
|
+
tilt (~> 1.3, >= 1.3.4)
|
39
|
+
tilt (1.4.1)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
omniauth-kakao!
|
46
|
+
shotgun (~> 0.9)
|
47
|
+
sinatra (~> 1.4.5)
|
48
|
+
|
49
|
+
BUNDLED WITH
|
50
|
+
1.11.2
|
data/example/app.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'sinatra'
|
3
|
+
require 'omniauth-kakao'
|
4
|
+
|
5
|
+
client_id = ENV['KAKAO_CLIENT_ID']
|
6
|
+
if client_id == nil
|
7
|
+
class NoClientIDError < StandardError; end
|
8
|
+
raise NoClientIDError, "KAKAO_CLIENT_ID is nil. Please run example like `KAKAO_CLIENT_ID='<your-kakako-client-id>' ruby app.rb`"
|
9
|
+
end
|
10
|
+
|
11
|
+
redirect_path = ENV['REDIRECT_PATH'] || OmniAuth::Strategies::Kakao::DEFAULT_REDIRECT_PATH
|
12
|
+
|
13
|
+
use Rack::Session::Cookie
|
14
|
+
|
15
|
+
use OmniAuth::Builder do
|
16
|
+
provider :kakao, client_id, {:redirect_path => redirect_path}
|
17
|
+
end
|
18
|
+
|
19
|
+
helpers do
|
20
|
+
def yaml_to_html(yaml)
|
21
|
+
display = yaml.split("\n")
|
22
|
+
display = display.map do |e|
|
23
|
+
e.gsub!(" ", " ")
|
24
|
+
"<p>#{e}</p>"
|
25
|
+
end.join
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
before do
|
30
|
+
@redirect_path = redirect_path
|
31
|
+
end
|
32
|
+
|
33
|
+
get '/' do
|
34
|
+
erb :index
|
35
|
+
end
|
36
|
+
|
37
|
+
get '/auth/:provider/callback' do
|
38
|
+
@modal = {
|
39
|
+
title: "Success!",
|
40
|
+
body: yaml_to_html(request.env['omniauth.auth'].to_yaml)
|
41
|
+
}
|
42
|
+
|
43
|
+
erb :index
|
44
|
+
end
|
45
|
+
|
46
|
+
get '/auth/failure' do
|
47
|
+
@modal = {
|
48
|
+
title: "Failure",
|
49
|
+
body: "Error: #{params[:message]}"
|
50
|
+
}
|
51
|
+
|
52
|
+
erb :index
|
53
|
+
end
|
54
|
+
|
55
|
+
__END__
|
56
|
+
@@ index
|
57
|
+
<html>
|
58
|
+
<head>
|
59
|
+
<title>Test Application for Omniauth Kakao</title>
|
60
|
+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
|
61
|
+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
|
62
|
+
<script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
|
63
|
+
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
|
64
|
+
<style>
|
65
|
+
#login-form {
|
66
|
+
margin-top: 30px;
|
67
|
+
text-align: center;
|
68
|
+
}
|
69
|
+
|
70
|
+
#login-form.panel-primary {
|
71
|
+
border-color: #FFEB00;
|
72
|
+
}
|
73
|
+
|
74
|
+
#login-form.panel-primary > .panel-heading {
|
75
|
+
background-image: -webkit-linear-gradient(top, #FFEB00 0, #FFEB00 100%);
|
76
|
+
background-image: -moz-linear-gradient(top, #FFEB00 0, #FFEB00 100%);
|
77
|
+
background-image: -o-linear-gradient(top, #FFEB00 0, #FFEB00 100%);
|
78
|
+
background-image: linear-gradient(top, #FFEB00 0, #FFEB00 100%);
|
79
|
+
background-color: #FFEB00;
|
80
|
+
border-color: #FFEB00;
|
81
|
+
color: #3D1D12;
|
82
|
+
}
|
83
|
+
|
84
|
+
.btn-kakao {
|
85
|
+
display: inline-block;
|
86
|
+
background-image: url("https://kauth.kakao.com/public/widget/login/kr/kr_02_medium.png");
|
87
|
+
|
88
|
+
width: 222px;
|
89
|
+
height: 49px;
|
90
|
+
|
91
|
+
line-height: 0;
|
92
|
+
font-size: 0;
|
93
|
+
color: transparent;
|
94
|
+
}
|
95
|
+
|
96
|
+
#redirect-path {
|
97
|
+
text-align: right;
|
98
|
+
margin: 20px 0 0 0;
|
99
|
+
}
|
100
|
+
</style>
|
101
|
+
</head>
|
102
|
+
<body>
|
103
|
+
<div class="container">
|
104
|
+
<div class="row">
|
105
|
+
<div class="col-md-6 col-md-offset-3">
|
106
|
+
<div id="login-form" class="panel panel-primary">
|
107
|
+
<div class="panel-heading">
|
108
|
+
<h3 class="panel-title">Test Application for Omniauth Kakao</h3>
|
109
|
+
</div>
|
110
|
+
|
111
|
+
<div class="panel-body">
|
112
|
+
<a href="/auth/kakao" class="btn-kakao">카카오 계정으로 로그인</a>
|
113
|
+
<p id="redirect-path"><small>Redirect Path: <%= @redirect_path %></small></p>
|
114
|
+
</div>
|
115
|
+
</div>
|
116
|
+
</div>
|
117
|
+
|
118
|
+
<% if @modal %>
|
119
|
+
<div class="modal fade" id="auth-modal" tabindex="-1" role="dialog" aria-labelledby="auth-modal-label" aria-hidden="true">
|
120
|
+
<div class="modal-dialog modal-lg">
|
121
|
+
<div class="modal-content">
|
122
|
+
<div class="modal-header">
|
123
|
+
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
124
|
+
<h4 class="modal-title" id="myModalLabel"><%= @modal[:title] %></h4>
|
125
|
+
</div>
|
126
|
+
|
127
|
+
<div class="modal-body">
|
128
|
+
<%= @modal[:body] %>
|
129
|
+
</div>
|
130
|
+
|
131
|
+
<div class="modal-footer">
|
132
|
+
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
133
|
+
</div>
|
134
|
+
</div>
|
135
|
+
</div>
|
136
|
+
</div>
|
137
|
+
|
138
|
+
<script>
|
139
|
+
$(function(){
|
140
|
+
$('#auth-modal').modal('show');
|
141
|
+
});
|
142
|
+
</script>
|
143
|
+
<% end %>
|
144
|
+
</div>
|
145
|
+
</div>
|
146
|
+
</body>
|
147
|
+
</html>
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Kakao < OmniAuth::Strategies::OAuth2
|
6
|
+
DEFAULT_REDIRECT_PATH = "/oauth"
|
7
|
+
|
8
|
+
option :name, 'kakao'
|
9
|
+
|
10
|
+
option :client_options, {
|
11
|
+
:site => 'https://kauth.kakao.com',
|
12
|
+
:authorize_path => '/oauth/authorize',
|
13
|
+
:token_url => '/oauth/token',
|
14
|
+
}
|
15
|
+
|
16
|
+
uid { raw_info['id'].to_s }
|
17
|
+
|
18
|
+
info do
|
19
|
+
{
|
20
|
+
'name' => raw_properties['nickname'] || '',
|
21
|
+
'image' => raw_properties['thumbnail_image'] || '',
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
extra do
|
26
|
+
{'properties' => raw_properties}
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(app, *args, &block)
|
30
|
+
super
|
31
|
+
options[:callback_path] = options[:redirect_path] || DEFAULT_REDIRECT_PATH
|
32
|
+
end
|
33
|
+
|
34
|
+
def callback_phase
|
35
|
+
previous_callback_path = options.delete(:callback_path)
|
36
|
+
@env["PATH_INFO"] = callback_path
|
37
|
+
options[:callback_path] = previous_callback_path
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
# callback_uri와 관련해서 redirect_uri_mismatch 문제가 나오던것을 path match를 통해서 해결합니다.
|
42
|
+
# 해당 문제는 https://devtalk.kakao.com/t/rest-api-omniauth/19207 에서 나오는 문제를 해결합니다.
|
43
|
+
# NOTE If we're using code from the signed request then FB sets the redirect_uri to '' during the authorize
|
44
|
+
# phase and it must match during the access_token phase:
|
45
|
+
# https://github.com/facebook/facebook-php-sdk/blob/master/src/base_facebook.php#L477
|
46
|
+
def callback_url
|
47
|
+
if @authorization_code_from_signed_request_in_cookie
|
48
|
+
''
|
49
|
+
else
|
50
|
+
# callback url ignorance issue from https://github.com/intridea/omniauth-oauth2/commit/85fdbe117c2a4400d001a6368cc359d88f40abc7
|
51
|
+
options[:callback_url] || (full_host + script_name + callback_path)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def mock_call!(*)
|
56
|
+
options.delete(:callback_path)
|
57
|
+
super
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def raw_info
|
62
|
+
@raw_info ||= access_token.get('https://kapi.kakao.com/v1/user/me', {}).parsed || {}
|
63
|
+
end
|
64
|
+
|
65
|
+
def raw_properties
|
66
|
+
@raw_properties ||= raw_info['properties']
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
OmniAuth.config.add_camelization 'kakao', 'Kakao'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-kakao/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-kakao-bucketplace"
|
7
|
+
s.version = Omniauth::Kakao::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Shayne Sung-Hee Kang"]
|
10
|
+
s.email = ["shayne.kang@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/shaynekang/omniauth-kakao"
|
12
|
+
s.summary = %q{OmniAuth strategy for Kakao}
|
13
|
+
s.description = %q{OmniAuth strategy for Kakao(http://developers.kakao.com/)}
|
14
|
+
s.license = "MIT"
|
15
|
+
|
16
|
+
s.rubyforge_project = "omniauth-kakao-bucketplace"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_dependency 'omniauth', '~> 1.0'
|
24
|
+
s.add_dependency 'omniauth-oauth2', '~> 1.3.1'
|
25
|
+
|
26
|
+
s.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
|
27
|
+
s.add_development_dependency 'guard-rspec', '~> 4.2', '>= 4.2.8'
|
28
|
+
s.add_development_dependency 'fakeweb', '~> 1.3', '>= 1.3.0'
|
29
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'omniauth'
|
3
|
+
require 'omniauth-kakao'
|
4
|
+
|
5
|
+
describe OmniAuth::Strategies::Kakao do
|
6
|
+
CLIENT_ID = '<<your-client-id>>'
|
7
|
+
SERVER_NAME = 'www.example.com'
|
8
|
+
|
9
|
+
before do
|
10
|
+
OmniAuth.config.logger.level = 5
|
11
|
+
end
|
12
|
+
|
13
|
+
def make_middleware(client_id, opts={})
|
14
|
+
app = ->(env) { [200, env, "app"] }
|
15
|
+
|
16
|
+
middleware = OmniAuth::Strategies::Kakao.new(app, opts)
|
17
|
+
middleware.tap do |middleware|
|
18
|
+
middleware.options.client_id = client_id
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def make_request(url, opts={})
|
23
|
+
Rack::MockRequest.env_for(url, {
|
24
|
+
'rack.session' => {},
|
25
|
+
'SERVER_NAME' => SERVER_NAME,
|
26
|
+
}.merge(opts))
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "GET /auth/kakao" do
|
30
|
+
it "should redirect to authorize page" do
|
31
|
+
request = make_request('/auth/kakao')
|
32
|
+
middleware = make_middleware(CLIENT_ID)
|
33
|
+
|
34
|
+
code, env = middleware.call(request)
|
35
|
+
|
36
|
+
code.should == 302
|
37
|
+
|
38
|
+
expect_url = <<-EXPECT
|
39
|
+
https://kauth.kakao.com/oauth/authorize
|
40
|
+
?client_id=#{CLIENT_ID}
|
41
|
+
&redirect_uri=http://#{SERVER_NAME}/oauth
|
42
|
+
&response_type=code
|
43
|
+
EXPECT
|
44
|
+
.gsub(/(\n|\t|\s)/, '')
|
45
|
+
|
46
|
+
actual_url = URI.decode(env['Location'].split("&state")[0])
|
47
|
+
|
48
|
+
actual_url.should == expect_url
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should customize redirect path" do
|
52
|
+
request = make_request('/auth/kakao')
|
53
|
+
middleware = make_middleware(CLIENT_ID, redirect_path: '/auth/kakao/callback')
|
54
|
+
|
55
|
+
code, env = middleware.call(request)
|
56
|
+
|
57
|
+
code.should == 302
|
58
|
+
|
59
|
+
expect_url = <<-EXPECT
|
60
|
+
https://kauth.kakao.com/oauth/authorize
|
61
|
+
?client_id=#{CLIENT_ID}
|
62
|
+
&redirect_uri=http://#{SERVER_NAME}/auth/kakao/callback
|
63
|
+
&response_type=code
|
64
|
+
EXPECT
|
65
|
+
.gsub(/(\n|\t|\s)/, '')
|
66
|
+
|
67
|
+
actual_url = URI.decode(env['Location'].split("&state")[0])
|
68
|
+
|
69
|
+
actual_url.should == expect_url
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "GET /oauth" do
|
74
|
+
CODE = "dummy-code"
|
75
|
+
STATE = "dummy-state"
|
76
|
+
ACCESS_TOKEN = "dummy-access-token"
|
77
|
+
REFRESH_TOKEN = "dummy-refresh-token"
|
78
|
+
|
79
|
+
before do
|
80
|
+
FakeWeb.register_uri(:post, "https://kauth.kakao.com/oauth/token",
|
81
|
+
:content_type => "application/json;charset=UTF-8",
|
82
|
+
:parameters => {
|
83
|
+
:grant_type => 'authorization_code',
|
84
|
+
:client_id => CLIENT_ID,
|
85
|
+
:redirect_uri => URI.encode("http://#{SERVER_NAME}/oauth"),
|
86
|
+
:code => CODE
|
87
|
+
},
|
88
|
+
:body => {
|
89
|
+
:access_token => ACCESS_TOKEN,
|
90
|
+
:token_type => "bearer",
|
91
|
+
:refresh_token => REFRESH_TOKEN,
|
92
|
+
:expires_in => 99999,
|
93
|
+
:scope => "Basic_Profile"
|
94
|
+
}.to_json
|
95
|
+
)
|
96
|
+
|
97
|
+
FakeWeb.register_uri(:get, "https://kapi.kakao.com/v1/user/me",
|
98
|
+
:content_type => "application/json;charset=UTF-8",
|
99
|
+
:"Authorization" => "Bearer #{ACCESS_TOKEN}",
|
100
|
+
:body => {
|
101
|
+
:id => 123456789,
|
102
|
+
:properties => {
|
103
|
+
:nickname => "John Doe",
|
104
|
+
:thumbnail_image => "http://xxx.kakao.com/.../aaa.jpg",
|
105
|
+
:profile_image => "http://xxx.kakao.com/.../bbb.jpg",
|
106
|
+
}
|
107
|
+
}.to_json
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should request access token and user information" do
|
112
|
+
request = make_request("/oauth?code=#{CODE}&state=#{STATE}", {
|
113
|
+
'rack.session' => {
|
114
|
+
'omniauth.state' => STATE
|
115
|
+
},
|
116
|
+
})
|
117
|
+
|
118
|
+
middleware = make_middleware(CLIENT_ID)
|
119
|
+
|
120
|
+
code, env = middleware.call(request)
|
121
|
+
|
122
|
+
code.should == 200
|
123
|
+
|
124
|
+
response = env['omniauth.auth']
|
125
|
+
|
126
|
+
response.provider.should == "kakao"
|
127
|
+
response.uid.should == "123456789"
|
128
|
+
|
129
|
+
information = response.info
|
130
|
+
information.name.should == "John Doe"
|
131
|
+
information.image.should == "http://xxx.kakao.com/.../aaa.jpg"
|
132
|
+
|
133
|
+
credentials = response.credentials
|
134
|
+
credentials.token.should == ACCESS_TOKEN
|
135
|
+
credentials.refresh_token.should == REFRESH_TOKEN
|
136
|
+
|
137
|
+
properties = response.extra.properties
|
138
|
+
properties.nickname.should == "John Doe"
|
139
|
+
properties.thumbnail_image.should == "http://xxx.kakao.com/.../aaa.jpg"
|
140
|
+
properties.profile_image.should == "http://xxx.kakao.com/.../bbb.jpg"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "test environment" do
|
145
|
+
before do
|
146
|
+
OmniAuth.config.test_mode = true
|
147
|
+
OmniAuth.config.add_mock(:kakao, {
|
148
|
+
provider: "kakao",
|
149
|
+
uid: "123456789",
|
150
|
+
info: {
|
151
|
+
name: "John Doe",
|
152
|
+
image: "http://xxx.kakao.com/.../aaa.jpg"
|
153
|
+
}
|
154
|
+
})
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "GET /auth/kakao" do
|
158
|
+
it "should redirect to callback url (/auth/kakao/callback)" do
|
159
|
+
request = make_request("/auth/kakao")
|
160
|
+
middleware = make_middleware(CLIENT_ID)
|
161
|
+
code, env = middleware.call(request)
|
162
|
+
|
163
|
+
code.should == 302
|
164
|
+
|
165
|
+
actual_path = URI(env["Location"]).path
|
166
|
+
actual_path.should == "/auth/kakao/callback"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "GET /auth/kakao/callback" do
|
171
|
+
it "should request registered mock" do
|
172
|
+
request = make_request("/auth/kakao/callback")
|
173
|
+
middleware = make_middleware(CLIENT_ID)
|
174
|
+
code, env = middleware.call(request)
|
175
|
+
|
176
|
+
code.should == 200
|
177
|
+
|
178
|
+
response = env["omniauth.auth"]
|
179
|
+
|
180
|
+
response.provider.should == "kakao"
|
181
|
+
response.uid.should == "123456789"
|
182
|
+
|
183
|
+
information = response.info
|
184
|
+
information.name.should == "John Doe"
|
185
|
+
information.image.should == "http://xxx.kakao.com/.../aaa.jpg"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
after do
|
190
|
+
OmniAuth.config.test_mode = false
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require 'fakeweb'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
$:.unshift File.expand_path('..', __FILE__)
|
11
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
+
config.run_all_when_everything_filtered = true
|
16
|
+
config.filter_run :focus
|
17
|
+
|
18
|
+
# Run specs in random order to surface order dependencies. If you find an
|
19
|
+
# order dependency and want to debug it, you can fix the order by providing
|
20
|
+
# the seed, which is printed after each run.
|
21
|
+
# --seed 1234
|
22
|
+
config.order = 'random'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-kakao-bucketplace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shayne Sung-Hee Kang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: omniauth-oauth2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.14'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.14.1
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2.14'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.14.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: guard-rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '4.2'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 4.2.8
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '4.2'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 4.2.8
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: fakeweb
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '1.3'
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.3.0
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.3'
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.3.0
|
101
|
+
description: OmniAuth strategy for Kakao(http://developers.kakao.com/)
|
102
|
+
email:
|
103
|
+
- shayne.kang@gmail.com
|
104
|
+
executables: []
|
105
|
+
extensions: []
|
106
|
+
extra_rdoc_files: []
|
107
|
+
files:
|
108
|
+
- ".gitignore"
|
109
|
+
- ".rspec"
|
110
|
+
- CHANGELOG
|
111
|
+
- Gemfile
|
112
|
+
- Gemfile.lock
|
113
|
+
- Guardfile
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- example/Gemfile
|
117
|
+
- example/Gemfile.lock
|
118
|
+
- example/app.rb
|
119
|
+
- lib/omniauth-kakao-bucketplace.rb
|
120
|
+
- lib/omniauth-kakao/version.rb
|
121
|
+
- lib/omniauth/strategies/kakao.rb
|
122
|
+
- omniauth-kakao-bucketplace.gemspec
|
123
|
+
- spec/omniauth/strategies/kakao_spec.rb
|
124
|
+
- spec/spec_helper.rb
|
125
|
+
homepage: https://github.com/shaynekang/omniauth-kakao
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project: omniauth-kakao-bucketplace
|
145
|
+
rubygems_version: 2.5.2
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: OmniAuth strategy for Kakao
|
149
|
+
test_files:
|
150
|
+
- spec/omniauth/strategies/kakao_spec.rb
|
151
|
+
- spec/spec_helper.rb
|