omniauth-yconnect 0.0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/omniauth-yconnect.rb +2 -0
- data/lib/omniauth-yconnect/version.rb +5 -0
- data/lib/omniauth/strategies/yconnect.rb +112 -0
- data/omniauth-yconnect.gemspec +27 -0
- data/spec/omniauth/strategies/yconnect_spec.rb +21 -0
- data/spec/spec_helper.rb +19 -0
- metadata +156 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 jun
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Omniauth::Yconnect
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'omniauth-yconnect'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install omniauth-yconnect
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
|
7
|
+
# An omniauth 1.0 strategy for yahoo authentication
|
8
|
+
class Yconnect < OmniAuth::Strategies::OAuth2
|
9
|
+
|
10
|
+
option :name, 'yconnect'
|
11
|
+
|
12
|
+
option :client_options, {
|
13
|
+
:access_token_url => '/yconnect/v1/token',
|
14
|
+
:authorize_url => '/yconnect/v1/authorization',
|
15
|
+
:token_url => '/yconnect/v1/token',
|
16
|
+
:user_info_url => 'https://userinfo.yahooapis.jp/yconnect/v1/attribute',
|
17
|
+
:site => 'https://auth.login.yahoo.co.jp' ,
|
18
|
+
}
|
19
|
+
|
20
|
+
uid {
|
21
|
+
#access_token.params['xoauth_yahoo_guid']
|
22
|
+
raw_info['user_id']
|
23
|
+
|
24
|
+
}
|
25
|
+
|
26
|
+
info do
|
27
|
+
{
|
28
|
+
:user_id => user_info["user_id"] ,
|
29
|
+
:name => user_info['name'] ,
|
30
|
+
:given_name => user_info['given_name'] ,
|
31
|
+
:given_name_ja_kana_jP => user_info['given_name#ja-Kana-JP'] ,
|
32
|
+
:given_name_ja_hani_jP => user_info['given_name#ja-Hani-JP'] ,
|
33
|
+
:family_name => user_info['family_name'] ,
|
34
|
+
:family_name_ja_kana_jP => user_info['family_name#ja-Kana-JP'] ,
|
35
|
+
:family_name_ja_hani_jP => user_info['family_name#ja-Hani-JP'] ,
|
36
|
+
:locale => user_info['locale'] ,
|
37
|
+
:email => user_info['email'] ,
|
38
|
+
:email_verified => user_info['email_verified'] ,
|
39
|
+
:address => {
|
40
|
+
"country" => user_info["address"] ? user_info["address"]["country"] : nil ,
|
41
|
+
"postal_code" => user_info["address"] ? user_info["address"]["postal_code"] : nil ,
|
42
|
+
"region" => user_info["address"] ? user_info["address"]["region"] : nil ,
|
43
|
+
"locality" => user_info["address"] ? user_info["address"]["locality"] : nil
|
44
|
+
} ,
|
45
|
+
:birthday => user_info['birthday'] ,
|
46
|
+
:gender => user_info['gender']
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
extra do
|
51
|
+
hash = {}
|
52
|
+
hash[:raw_info] = raw_info unless skip_info?
|
53
|
+
hash
|
54
|
+
end
|
55
|
+
|
56
|
+
def build_access_token
|
57
|
+
options.token_params = {} if options.token_params.nil?
|
58
|
+
options.auth_token_params = {} if options.auth_token_params.nil?
|
59
|
+
params = {}
|
60
|
+
params[:body] = {:redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true))
|
61
|
+
params[:body].merge!({'grant_type' => 'authorization_code', 'code' => request.params['code']})
|
62
|
+
params[:headers] = {'Expect'=> '' ,
|
63
|
+
'Authorization' => 'Basic ' + Base64::strict_encode64("#{options.client_id}:#{options.client_secret}").strip}
|
64
|
+
params.delete "client_id"
|
65
|
+
params.delete "client_secret"
|
66
|
+
params.merge(token_params.to_hash(:symbolize_keys => true))
|
67
|
+
get_token( params , deep_symbolize(options.auth_token_params))
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_token(params, access_token_opts={})
|
71
|
+
opts = {:raise_errors => options[:raise_errors], :parse => params.delete(:parse)}
|
72
|
+
response = client.request(:post , client.token_url, params.merge(opts))
|
73
|
+
raise Error.new(response) if client.options[:raise_errors] && !(response.parsed.is_a?(Hash) && response.parsed['access_token'])
|
74
|
+
::OAuth2::AccessToken.from_hash(client , response.parsed.merge(access_token_opts))
|
75
|
+
end
|
76
|
+
|
77
|
+
# Refreshes the current Access Token
|
78
|
+
#
|
79
|
+
# @return [AccessToken] a new AccessToken
|
80
|
+
# @note options should be carried over to the new AccessToken
|
81
|
+
def refresh!(params={})
|
82
|
+
raise "A refresh_token is not available" unless refresh_token
|
83
|
+
params.merge!(
|
84
|
+
:grant_type => 'refresh_token',
|
85
|
+
:refresh_token => refresh_token)
|
86
|
+
params[:headers] = {'Expect'=> '' ,
|
87
|
+
'Authorization' => 'Basic ' + Base64::strict_encode64("#{options.client_id}:#{options.client_secret}").strip}
|
88
|
+
new_token = get_token(params)
|
89
|
+
new_token.options = client.options
|
90
|
+
new_token
|
91
|
+
end
|
92
|
+
|
93
|
+
# Return info gathered from the v1/user/:id/profile API call
|
94
|
+
|
95
|
+
def raw_info
|
96
|
+
# This is a public API and does not need signing or authentication
|
97
|
+
url = "https://userinfo.yahooapis.jp/yconnect/v1/attribute"
|
98
|
+
opts = {:headers => {'Authorization' => access_token.params["token_type"].camelize + ' ' + access_token.token}}
|
99
|
+
opts[:params] = {:schema => 'openid'}
|
100
|
+
@raw_info ||= MultiJson.decode(client.request(:get , url , opts).body)
|
101
|
+
rescue ::Errno::ETIMEDOUT
|
102
|
+
raise ::Timeout::Error
|
103
|
+
end
|
104
|
+
|
105
|
+
# Provide the "Profile" portion of the raw_info
|
106
|
+
|
107
|
+
def user_info
|
108
|
+
@user_info ||= raw_info.nil? ? {} : raw_info
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'omniauth-yconnect/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "omniauth-yconnect"
|
8
|
+
gem.version = Omniauth::Yconnect::VERSION
|
9
|
+
gem.authors = ["yamitake"]
|
10
|
+
gem.email = ["take.yapr@gmail.com"]
|
11
|
+
gem.description = %q{OmniAuth strategy for YConnect}
|
12
|
+
gem.summary = %q{OmniAuth strategy for YConnect}
|
13
|
+
gem.homepage = "https://github.com/yamitake/omniauth-yconnect"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency 'multi_json', '~> 1.3'
|
22
|
+
gem.add_runtime_dependency 'omniauth-oauth2'
|
23
|
+
gem.add_development_dependency 'rspec', '~> 2.7'
|
24
|
+
gem.add_development_dependency 'rack-test'
|
25
|
+
gem.add_development_dependency 'simplecov'
|
26
|
+
gem.add_development_dependency 'webmock'
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::Yconnect do
|
4
|
+
subject do
|
5
|
+
OmniAuth::Strategies::Yconnect.new({})
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'client options' do
|
9
|
+
it 'should have correct name' do
|
10
|
+
expect(subject.options.name).to eq('yconnect')
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should have correct authorize url' do
|
14
|
+
expect(subject.options.client_options.authorize_url).to eq('/yconnect/v1/authorization')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'shoud have client' do
|
18
|
+
p subject.client
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
require 'rspec'
|
6
|
+
require 'rack/test'
|
7
|
+
require 'webmock/rspec'
|
8
|
+
require 'omniauth'
|
9
|
+
require 'omniauth-oauth2'
|
10
|
+
require 'omniauth-yconnect'
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.include WebMock::API
|
14
|
+
config.include Rack::Test::Methods
|
15
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
16
|
+
config.expect_with :rspec do |c|
|
17
|
+
c.syntax = :expect
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-yconnect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- yamitake
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: multi_json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: omniauth-oauth2
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.7'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.7'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rack-test
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: webmock
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: OmniAuth strategy for YConnect
|
111
|
+
email:
|
112
|
+
- take.yapr@gmail.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- Gemfile
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- lib/omniauth-yconnect.rb
|
123
|
+
- lib/omniauth-yconnect/version.rb
|
124
|
+
- lib/omniauth/strategies/yconnect.rb
|
125
|
+
- omniauth-yconnect.gemspec
|
126
|
+
- spec/omniauth/strategies/yconnect_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
homepage: https://github.com/yamitake/omniauth-yconnect
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ! '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
none: false
|
143
|
+
requirements:
|
144
|
+
- - ! '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 1.8.23
|
150
|
+
signing_key:
|
151
|
+
specification_version: 3
|
152
|
+
summary: OmniAuth strategy for YConnect
|
153
|
+
test_files:
|
154
|
+
- spec/omniauth/strategies/yconnect_spec.rb
|
155
|
+
- spec/spec_helper.rb
|
156
|
+
has_rdoc:
|