omniauth-kakao-myletter 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bea3a4e26f0dafce9bdaeaccb84a1b8e14318e43
4
+ data.tar.gz: 41487358cb30e874611ee0f51f6e52cf1f3b85f6
5
+ SHA512:
6
+ metadata.gz: 7590e2af3843bc46b766033fc9a6b5a734eb17528e1796344cacd7999de541ac01c47489d14e2c4fd1c25f9bae1d71aefd519c72dfcb2ef1afc74cce85289427
7
+ data.tar.gz: 447af3edf24bba5fe2074545e02c969e3c893f77b3d9292077fac170aa7a592adb935fe66bc05ce352622bde3382e5ccdff767a5204fb7e32afd15350b38d0b6
@@ -0,0 +1 @@
1
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,7 @@
1
+ ## v0.0.2
2
+
3
+ * 개발 완료
4
+
5
+ ## v0.0.1
6
+
7
+ * 릴리즈 준비
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-github.gemspec
4
+ gemspec
@@ -0,0 +1,86 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-kakao (0.1.1)
5
+ omniauth (~> 1.0)
6
+ omniauth-oauth2 (~> 1.1)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ celluloid (0.15.2)
12
+ timers (~> 1.1.0)
13
+ celluloid-io (0.15.0)
14
+ celluloid (>= 0.15.0)
15
+ nio4r (>= 0.5.0)
16
+ coderay (1.1.0)
17
+ diff-lcs (1.2.5)
18
+ fakeweb (1.3.0)
19
+ faraday (0.9.0)
20
+ multipart-post (>= 1.2, < 3)
21
+ ffi (1.9.3)
22
+ formatador (0.2.4)
23
+ guard (2.6.0)
24
+ formatador (>= 0.2.4)
25
+ listen (~> 2.7)
26
+ lumberjack (~> 1.0)
27
+ pry (>= 0.9.12)
28
+ thor (>= 0.18.1)
29
+ guard-rspec (4.2.8)
30
+ guard (~> 2.1)
31
+ rspec (>= 2.14, < 4.0)
32
+ hashie (3.3.1)
33
+ jwt (1.0.0)
34
+ listen (2.7.4)
35
+ celluloid (>= 0.15.2)
36
+ celluloid-io (>= 0.15.0)
37
+ rb-fsevent (>= 0.9.3)
38
+ rb-inotify (>= 0.9)
39
+ lumberjack (1.0.5)
40
+ method_source (0.8.2)
41
+ multi_json (1.10.1)
42
+ multi_xml (0.5.5)
43
+ multipart-post (2.0.0)
44
+ nio4r (1.0.0)
45
+ oauth2 (1.0.0)
46
+ faraday (>= 0.8, < 0.10)
47
+ jwt (~> 1.0)
48
+ multi_json (~> 1.3)
49
+ multi_xml (~> 0.5)
50
+ rack (~> 1.2)
51
+ omniauth (1.2.2)
52
+ hashie (>= 1.2, < 4)
53
+ rack (~> 1.0)
54
+ omniauth-oauth2 (1.2.0)
55
+ faraday (>= 0.8, < 0.10)
56
+ multi_json (~> 1.3)
57
+ oauth2 (~> 1.0)
58
+ omniauth (~> 1.2)
59
+ pry (0.9.12.6)
60
+ coderay (~> 1.0)
61
+ method_source (~> 0.8)
62
+ slop (~> 3.4)
63
+ rack (1.5.2)
64
+ rb-fsevent (0.9.4)
65
+ rb-inotify (0.9.4)
66
+ ffi (>= 0.5.0)
67
+ rspec (2.14.1)
68
+ rspec-core (~> 2.14.0)
69
+ rspec-expectations (~> 2.14.0)
70
+ rspec-mocks (~> 2.14.0)
71
+ rspec-core (2.14.8)
72
+ rspec-expectations (2.14.5)
73
+ diff-lcs (>= 1.1.3, < 2.0)
74
+ rspec-mocks (2.14.6)
75
+ slop (3.5.0)
76
+ thor (0.19.1)
77
+ timers (1.1.0)
78
+
79
+ PLATFORMS
80
+ ruby
81
+
82
+ DEPENDENCIES
83
+ fakeweb (~> 1.3, >= 1.3.0)
84
+ guard-rspec (~> 4.2, >= 4.2.8)
85
+ omniauth-kakao!
86
+ rspec (~> 2.14, >= 2.14.1)
@@ -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
@@ -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
+ ![이미지](https://developers.kakao.com/assets/images/dashboard/dev_011.png)
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.
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sinatra', '~> 1.4.5'
4
+ gem 'shotgun', '~> 0.9'
5
+ gem 'omniauth-kakao', :path => '../'
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ omniauth-kakao (0.1.1)
5
+ omniauth (~> 1.0)
6
+ omniauth-oauth2 (~> 1.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ faraday (0.9.0)
12
+ multipart-post (>= 1.2, < 3)
13
+ hashie (3.3.1)
14
+ jwt (1.0.0)
15
+ multi_json (1.10.1)
16
+ multi_xml (0.5.5)
17
+ multipart-post (2.0.0)
18
+ oauth2 (1.0.0)
19
+ faraday (>= 0.8, < 0.10)
20
+ jwt (~> 1.0)
21
+ multi_json (~> 1.3)
22
+ multi_xml (~> 0.5)
23
+ rack (~> 1.2)
24
+ omniauth (1.2.2)
25
+ hashie (>= 1.2, < 4)
26
+ rack (~> 1.0)
27
+ omniauth-oauth2 (1.2.0)
28
+ faraday (>= 0.8, < 0.10)
29
+ multi_json (~> 1.3)
30
+ oauth2 (~> 1.0)
31
+ omniauth (~> 1.2)
32
+ rack (1.5.2)
33
+ rack-protection (1.5.3)
34
+ rack
35
+ shotgun (0.9)
36
+ rack (>= 1.0)
37
+ sinatra (1.4.5)
38
+ rack (~> 1.4)
39
+ rack-protection (~> 1.4)
40
+ tilt (~> 1.3, >= 1.3.4)
41
+ tilt (1.4.1)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ omniauth-kakao!
48
+ shotgun (~> 0.9)
49
+ sinatra (~> 1.4.5)
@@ -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!(" ", "&nbsp;&nbsp;&nbsp;&nbsp;")
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">&times;</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,2 @@
1
+ require "omniauth-kakao/version"
2
+ require 'omniauth/strategies/kakao'
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Kakao
3
+ VERSION = "0.1.2"
4
+ end
5
+ end
@@ -0,0 +1,58 @@
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.nil? ? "" : raw_properties['nickname'],
21
+ 'image' => raw_properties.nil? ? "" : 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
+ def mock_call!(*)
42
+ options.delete(:callback_path)
43
+ super
44
+ end
45
+
46
+ private
47
+ def raw_info
48
+ @raw_info ||= access_token.get('https://kapi.kakao.com/v1/user/me', {}).parsed || {}
49
+ end
50
+
51
+ def raw_properties
52
+ @raw_properties ||= raw_info['properties']
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ 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-myletter"
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"
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.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
@@ -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,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-kakao-myletter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Shayne Sung-Hee Kang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-23 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.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.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.rb
120
+ - lib/omniauth-kakao/version.rb
121
+ - lib/omniauth/strategies/kakao.rb
122
+ - omniauth-kakao.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
145
+ rubygems_version: 2.4.7
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
152
+ has_rdoc: