omniauth-nate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem 'omniauth', :git => 'https://github.com/intridea/omniauth.git'
5
+ end
6
+
7
+ # Specify your gem's dependencies in omniauth-nate.gemspec
8
+ gemspec
@@ -0,0 +1,110 @@
1
+ omniauth-nate
2
+ =============
3
+
4
+ 네이트 인증을 위한 omniauth strategy입니다. 네이트/싸이월드/엠파스 계정을 이용한 인증이 가능하도록 합니다.
5
+
6
+ http://www.nate.com
7
+
8
+ Nate의 인증 API는 OAuth 1.0를 따릅니다.
9
+
10
+ http://devsquare.nate.com/openApi/nateAuthAPIGuide
11
+
12
+ 설치
13
+ ----
14
+
15
+ Gemfile 에 추가 후,
16
+
17
+ ```ruby
18
+ gem 'omniauth-nate'
19
+ ```
20
+
21
+ `bundle install`
22
+
23
+ 사용 절차
24
+ ---------
25
+
26
+ Nate의 devsquare에서 consumer key를 발급 받습니다.
27
+
28
+ http://devsquare.nate.com/
29
+
30
+ 발급 확인 메일을 통해 `GetNateMemberInfo` API 의 결과를 복호화하는 필요한
31
+ encryption key와 IV를 함께 할당받게 됩니다.
32
+
33
+ ### Usage
34
+
35
+ OAuth를 위한 consumer key, secret과 함께 발급 확인 메일을 통해 부여받은
36
+ encryption key를 기재합니다.
37
+
38
+ ```ruby
39
+ Rails.application.config.middleware.use OmniAuth::Builder do
40
+ provider :nate, consumer_key, consumer_secret,
41
+ :encryption => {
42
+ :key => key, # Required.
43
+ :iv => 0.chr * 8, # Optional. Default: 0.chr * 8
44
+ :algorithm => 'des-ede3-cbc' # Optional. Default: des-ede3-cbc
45
+ }
46
+ end
47
+ ```
48
+
49
+ ### Devise 에서의 설정
50
+
51
+ ```ruby
52
+ Devise.setup do |config|
53
+ config.omniauth :nate, consumer_key, consumer_secret,
54
+ :encryption => {
55
+ :key => key, # Required.
56
+ :iv => 0.chr * 8, # Optional. Default: 0.chr * 8
57
+ :algorithm => 'des-ede3-cbc' # Optional. Default: des-ede3-cbc
58
+ }
59
+ end
60
+ ```
61
+
62
+ Authentication Hash
63
+ -------------------
64
+
65
+ 이메일 주소가 User identifier로 사용됩니다.
66
+
67
+ ```ruby
68
+ {
69
+ :provider => 'nate',
70
+ :uid => 'your-mail@nate.com',
71
+ :info => {
72
+ :name => 'your name',
73
+ :email => 'your-mail@nate.com'
74
+ }
75
+ }
76
+ ```
77
+
78
+ Contributing to omniauth-nate
79
+ -----------------------------
80
+
81
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
82
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
83
+ * Fork the project
84
+ * Start a feature/bugfix branch
85
+ * Commit and push until you are happy with your contribution
86
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
87
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
88
+
89
+ License
90
+ -------
91
+ Copyright (c) 2012 Junegunn Choi
92
+
93
+ Permission is hereby granted, free of charge, to any person obtaining
94
+ a copy of this software and associated documentation files (the
95
+ "Software"), to deal in the Software without restriction, including
96
+ without limitation the rights to use, copy, modify, merge, publish,
97
+ distribute, sublicense, and/or sell copies of the Software, and to
98
+ permit persons to whom the Software is furnished to do so, subject to
99
+ the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be
102
+ included in all copies or substantial portions of the Software.
103
+
104
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
105
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
106
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
107
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
108
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
109
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
110
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,110 @@
1
+ omniauth-nate
2
+ =============
3
+
4
+ Omniauth strategy for a Korean web portal nate.com which is a conglomerate of Nate, Cyworld and Empas.
5
+ This allows users to authenticate themselves with their Nate/Cyworld/Empas accounts.
6
+
7
+ http://www.nate.com
8
+
9
+ Nate Open Authentication API follows OAuth 1.0 protocol.
10
+
11
+ http://devsquare.nate.com/openApi/nateAuthAPIGuide
12
+
13
+ Installation
14
+ ------------
15
+
16
+ Add to your Gemfile
17
+
18
+ ```ruby
19
+ gem 'omniauth-nate'
20
+ ```
21
+
22
+ Then `bundle install`
23
+
24
+ How to use
25
+ ----------
26
+
27
+ Register your application in the following page to obtain consumer key and secret.
28
+
29
+ http://devsquare.nate.com/
30
+
31
+ In the confirmation mail, you will additionally receive encryption key and IV required
32
+ to decrypt the member information retrieved via their `GetNateMemberInfo` API.
33
+
34
+ ### Usage
35
+
36
+ Along with the usual consumer key and secret, encryption key must be specified.
37
+
38
+ ```ruby
39
+ Rails.application.config.middleware.use OmniAuth::Builder do
40
+ provider :nate, consumer_key, consumer_secret,
41
+ :encryption => {
42
+ :key => key, # Required.
43
+ :iv => 0.chr * 8, # Optional. Default: 0.chr * 8
44
+ :algorithm => 'des-ede3-cbc' # Optional. Default: des-ede3-cbc
45
+ }
46
+ end
47
+ ```
48
+
49
+ ### With Devise
50
+
51
+ ```ruby
52
+ Devise.setup do |config|
53
+ config.omniauth :nate, consumer_key, consumer_secret,
54
+ :encryption => {
55
+ :key => key, # Required.
56
+ :iv => 0.chr * 8, # Optional. Default: 0.chr * 8
57
+ :algorithm => 'des-ede3-cbc' # Optional. Default: des-ede3-cbc
58
+ }
59
+ end
60
+ ```
61
+
62
+ Authentication Hash
63
+ -------------------
64
+
65
+ Email address is used as the user identifier.
66
+
67
+ ```ruby
68
+ {
69
+ :provider => 'nate',
70
+ :uid => 'your-mail@nate.com',
71
+ :info => {
72
+ :name => 'your name',
73
+ :email => 'your-mail@nate.com'
74
+ }
75
+ }
76
+ ```
77
+
78
+ Contributing to omniauth-nate
79
+ -----------------------------
80
+
81
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
82
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
83
+ * Fork the project
84
+ * Start a feature/bugfix branch
85
+ * Commit and push until you are happy with your contribution
86
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
87
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
88
+
89
+ License
90
+ -------
91
+ Copyright (c) 2012 Junegunn Choi
92
+
93
+ Permission is hereby granted, free of charge, to any person obtaining
94
+ a copy of this software and associated documentation files (the
95
+ "Software"), to deal in the Software without restriction, including
96
+ without limitation the rights to use, copy, modify, merge, publish,
97
+ distribute, sublicense, and/or sell copies of the Software, and to
98
+ permit persons to whom the Software is furnished to do so, subject to
99
+ the following conditions:
100
+
101
+ The above copyright notice and this permission notice shall be
102
+ included in all copies or substantial portions of the Software.
103
+
104
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
105
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
106
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
107
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
108
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
109
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
110
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'lib'
6
+ t.pattern = 'test/**/test_*.rb'
7
+ t.verbose = true
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'omniauth-nate/version'
2
+ require 'omniauth/strategies/nate'
3
+
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Nate
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,73 @@
1
+ require 'omniauth-oauth'
2
+ require 'rexml/document'
3
+ require 'openssl'
4
+ require 'base64'
5
+ require 'insensitive_hash/minimal'
6
+
7
+ module OmniAuth
8
+ module Strategies
9
+ class Nate < OmniAuth::Strategies::OAuth
10
+ option :name, 'nate'
11
+ option :client_options, {
12
+ :site => 'https://oauth.nate.com',
13
+ :request_token_path => '/OAuth/GetRequestToken/V1a',
14
+ :authorize_path => '/OAuth/Authorize/V1a',
15
+ :access_token_path => '/OAuth/GetAccessToken/V1a',
16
+ }
17
+ option :member_info_path, '/OAuth/GetNateMemberInfo/V1a'
18
+ option :encryption, {
19
+ :key => nil,
20
+ :iv => 0.chr * 8,
21
+ :algorithm => 'des-ede3-cbc'
22
+ }
23
+
24
+ uid do
25
+ raw_info[:nid]
26
+ end
27
+
28
+ info do
29
+ {
30
+ :name => raw_info[:name],
31
+ :email => raw_info[:nid]
32
+ }
33
+ end
34
+
35
+ def initialize app, *args, &block
36
+ super
37
+ unless options[:encryption][:key]
38
+ raise ArgumentError.new("encryption key must be given")
39
+ end
40
+ end
41
+
42
+ def encryption
43
+ options[:encryption]
44
+ end
45
+
46
+ private
47
+ def raw_info
48
+ return @raw_info if @raw_info
49
+
50
+ @raw_info = InsensitiveHash.new
51
+ xml_data = access_token.get(options[:member_info_path]).body
52
+ doc = REXML::Document.new xml_data
53
+ %w[nid name].each do |elem|
54
+ doc.elements.each("response/minfo/#{elem}") do |nid|
55
+ @raw_info[elem] = decrypt nid.text
56
+ end
57
+ end
58
+ @raw_info
59
+ end
60
+
61
+ def decrypt val
62
+ c = OpenSSL::Cipher.new options[:encryption][:algorithm]
63
+ c.decrypt
64
+ c.key = options[:encryption][:key]
65
+ c.iv = options[:encryption][:iv]
66
+ text = c.update(Base64.decode64 val)
67
+ text << c.final
68
+ text.force_encoding("UTF-8")
69
+ end
70
+ end
71
+ end
72
+ end
73
+
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-nate/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-nate"
7
+ s.version = Omniauth::Nate::VERSION
8
+ s.authors = ["Junegunn Choi"]
9
+ s.email = ["junegunn.c@gmail.com"]
10
+ s.homepage = "https://github.com/junegunn/omniauth-nate"
11
+ s.summary = %q{OmniAuth strategy for nate.com}
12
+ s.description = %q{OmniAuth strategy for nate.com (Korean web portal site which is a conglomerate of Nate, Cyworld and Empas)}
13
+
14
+ s.rubyforge_project = "omniauth-nate"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ s.add_development_dependency "rack-test"
25
+ s.add_development_dependency "mocha"
26
+ s.add_development_dependency "webmock"
27
+ s.add_runtime_dependency "omniauth-oauth", "~> 1.0"
28
+ s.add_runtime_dependency "multi_json"
29
+ s.add_runtime_dependency "insensitive_hash", ">= 0.1.0"
30
+ end
@@ -0,0 +1,127 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require(:default, :development)
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'test/unit'
7
+ require 'mocha'
8
+ require 'omniauth-nate'
9
+ require 'rack/test'
10
+ require 'webmock'
11
+
12
+ class OmniauthNateTest < Test::Unit::TestCase
13
+ include Rack::Test::Methods
14
+ include WebMock::API
15
+
16
+ def setup
17
+ @consumer_key = 'consumer key'
18
+ @consumer_secret = 'consumer secret'
19
+
20
+ @iv = 0.chr * 8
21
+ @key = 'encryption key for triple des'
22
+ @algorithm = 'des-ede3-cbc'
23
+
24
+ @email = "you@and.me"
25
+ @name = "yam"
26
+ end
27
+
28
+ # Borrowed from omniauth-oauth spec
29
+ def app
30
+ Rack::Builder.new {
31
+ use OmniAuth::Test::PhonySession
32
+ use OmniAuth::Builder do
33
+ provider :nate, 'consumer key', 'consumer secret',
34
+ :encryption => { :key => 'encryption key for triple des' }
35
+ end
36
+ run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
37
+ }.to_app
38
+ end
39
+
40
+ def session
41
+ last_request.env['rack.session']
42
+ end
43
+
44
+ def encrypt str
45
+ c = OpenSSL::Cipher.new(@algorithm)
46
+ c.encrypt
47
+ c.key = @key
48
+ c.iv = @iv
49
+ text = c.update(str)
50
+ text << c.final
51
+ Base64.encode64 text
52
+ end
53
+
54
+ def decrypt str
55
+ c = OpenSSL::Cipher.new(@algorithm)
56
+ c.decrypt
57
+ c.key = @key
58
+ c.iv = @iv
59
+ text = c.update(Base64.decode64 str)
60
+ text << c.final
61
+ text
62
+ end
63
+
64
+ def test_encrypt_decrypt
65
+ str = "Meta-test: Testing encryption and decryption methods used in the test"
66
+ assert_equal str, decrypt(encrypt(str))
67
+ end
68
+
69
+ def test_encryption_key_is_required
70
+ assert_raise(ArgumentError) do
71
+ nate = OmniAuth::Strategies::Nate.new(nil, @consumer_key, @consumer_secret)
72
+ end
73
+ end
74
+
75
+ def test_encryption_parameters
76
+ nate = OmniAuth::Strategies::Nate.new(nil, @consumer_key, @consumer_secret,
77
+ :encryption => {
78
+ :key => @key,
79
+ :iv => @iv,
80
+ :algorithm => 'des3'
81
+ })
82
+ assert_equal @key, nate.encryption[:key]
83
+ assert_equal @iv, nate.encryption[:iv]
84
+ assert_equal 'des3', nate.encryption[:algorithm]
85
+ end
86
+
87
+ def test_name
88
+ nate = OmniAuth::Strategies::Nate.new(nil, @consumer_key, @consumer_secret,
89
+ :encryption => { :key => @key })
90
+ assert_equal 'nate', nate.name
91
+ end
92
+
93
+ def test_request
94
+ stub_request(:post, "https://oauth.nate.com/OAuth/GetRequestToken/V1a").
95
+ to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret&oauth_callback_confirmed=true")
96
+ get "/auth/nate"
97
+
98
+ assert last_response.redirect?
99
+ assert_equal 'https://oauth.nate.com/OAuth/Authorize/V1a?oauth_token=yourtoken',
100
+ last_response.headers['Location'].to_s
101
+ assert_equal 'yourtoken', session['oauth']['nate']['request_token']
102
+ assert_equal 'yoursecret', session['oauth']['nate']['request_secret']
103
+
104
+ assert_requested :post, 'https://oauth.nate.com/OAuth/GetRequestToken/V1a'
105
+
106
+ stub_request(:post, "https://oauth.nate.com/OAuth/GetAccessToken/V1a").
107
+ to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
108
+
109
+ stub_request(:get, "https://oauth.nate.com/OAuth/GetNateMemberInfo/V1a").
110
+ to_return(:body => "<response><rcode>RET0000</rcode><rmsg>SUCCESS</rmsg><class>1</class><minfo><nid>#{encrypt @email}</nid><name>#{encrypt @name}</name></minfo></response>")
111
+
112
+ get '/auth/nate/callback', { :oauth_verifier => 'verifier' }
113
+ assert_requested :post, 'https://oauth.nate.com/OAuth/GetAccessToken/V1a'
114
+ assert_requested :get, 'https://oauth.nate.com/OAuth/GetNateMemberInfo/V1a'
115
+
116
+ assert_equal 'true', last_response.body
117
+ assert_equal @email, last_request.env['omniauth.auth']['uid']
118
+ assert_equal @email, last_request.env['omniauth.auth']['info']['email']
119
+ assert_equal @name, last_request.env['omniauth.auth']['info']['name']
120
+ assert_equal Encoding::UTF_8, last_request.env['omniauth.auth']['info']['name'].encoding
121
+ end
122
+
123
+ def test_basic
124
+ nate = OmniAuth::Strategies::Nate.new(nil, @consumer_key, @consumer_secret, :encryption => { :key => @key })
125
+ end
126
+ end
127
+
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-nate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Junegunn Choi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack-test
16
+ requirement: &2153764780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2153764780
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ requirement: &2153764320 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2153764320
36
+ - !ruby/object:Gem::Dependency
37
+ name: webmock
38
+ requirement: &2153763900 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2153763900
47
+ - !ruby/object:Gem::Dependency
48
+ name: omniauth-oauth
49
+ requirement: &2153763380 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2153763380
58
+ - !ruby/object:Gem::Dependency
59
+ name: multi_json
60
+ requirement: &2153762960 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *2153762960
69
+ - !ruby/object:Gem::Dependency
70
+ name: insensitive_hash
71
+ requirement: &2153762420 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 0.1.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *2153762420
80
+ description: OmniAuth strategy for nate.com (Korean web portal site which is a conglomerate
81
+ of Nate, Cyworld and Empas)
82
+ email:
83
+ - junegunn.c@gmail.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - .gitignore
89
+ - Gemfile
90
+ - README.ko.md
91
+ - README.md
92
+ - Rakefile
93
+ - lib/omniauth-nate.rb
94
+ - lib/omniauth-nate/version.rb
95
+ - lib/omniauth/strategies/nate.rb
96
+ - omniauth-nate.gemspec
97
+ - test/test_omniauth-nate.rb
98
+ homepage: https://github.com/junegunn/omniauth-nate
99
+ licenses: []
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project: omniauth-nate
118
+ rubygems_version: 1.8.10
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: OmniAuth strategy for nate.com
122
+ test_files:
123
+ - test/test_omniauth-nate.rb
124
+ has_rdoc: