nov-omniauth-yahoojp 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b91f04e35715a3cc7068cd91f13fdb24361cf51a06f03596398e2cc87c96f99d
4
+ data.tar.gz: c9df9a1fd79972d67507b75c4565b73f390c3c4dc72ed141841a71518cb3783e
5
+ SHA512:
6
+ metadata.gz: e1def1da09813381b81e65fbc588681686dfd0f12c01b60b0fb29df72f29240e77344f2576dcab86922f12683a698c1ec23dc6a9db696d78b6cd248a6f1da613
7
+ data.tar.gz: a6bf7593a907840dc712fc43db46039efd534f4b210d8ca7ea6b5ef4eea4c507e0b99377a7f2d8cb1b1c2e0825ccc7e1c6ea484b14877b0d9cfb2ec7da1e8e71
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ /pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-yahoojp.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard 'bundler' do
8
+ watch('Gemfile')
9
+ watch('omniauth-yahoojp.gemspec')
10
+ end
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # OmniAuth YahooJp [![Gem Version](https://badge.fury.io/rb/omniauth-yahoojp.svg)](https://badge.fury.io/rb/omniauth-yahoojp)
2
+
3
+ **These notes are based on master, please see tags for README pertaining to specific releases.**
4
+
5
+ This is the official OmniAuth strategy for authenticating to Yahoo! JAPAN( [YConnect](http://developer.yahoo.co.jp/yconnect/v2/) ).
6
+ To use it, you'll need to sign up for a YConnect Client ID and Secret
7
+ on the [Yahoo! JAPAN Developer Network](https://e.developer.yahoo.co.jp/dashboard/).
8
+
9
+ Supports OAuth 2.0 Authorization Code flows. Read the Yahoo!JAPAN docs for more details: https://developer.yahoo.co.jp/yconnect/v2/
10
+
11
+ ## Installing
12
+
13
+ Add to your `Gemfile`:
14
+
15
+ ```ruby
16
+ gem 'omniauth-yahoojp'
17
+ ```
18
+
19
+ Then `bundle install`.
20
+
21
+ ## Basic Usage
22
+
23
+ `OmniAuth::Strategies::YahooJp` is simply a Rack middleware. Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth.
24
+
25
+ YConnect API v2 lets you set scopes to provide granular access to different types of data:
26
+
27
+ ```ruby
28
+ Rails.application.config.middleware.use OmniAuth::Builder do
29
+ provider :yahoojp, ENV['YAHOOJP_KEY'], ENV['YAHOOJP_SECRET'],
30
+ {
31
+ scope: "openid profile email address"
32
+ }
33
+ end
34
+ ```
35
+
36
+ ## Advanced Parameters
37
+
38
+ You can also set :display, :prompt, :scope, :bail parameter to specify behavior of sign-in and permission page.
39
+ More info on [YConnect](http://developer.yahoo.co.jp/yconnect/v2/).
40
+
41
+ For example, to request `openid`, `profile`, and `email` permissions and display the authentication page in a popup window:
42
+
43
+ ```ruby
44
+ Rails.application.config.middleware.use OmniAuth::Builder do
45
+ provider :yahoojp, ENV['YAHOOJP_KEY'], ENV['YAHOOJP_SECRET'],
46
+ {
47
+ scope: "openid profile email",
48
+ display: "popup"
49
+ }
50
+ end
51
+ ```
52
+
53
+ ### API Version
54
+
55
+ OmniAuth YahooJp uses versioned API endpoints by default (current v2). You can configure a different version via `client_options` hash passed to `provider`, specifically you should change the version in the `site` and `authorize_url` parameters. For example, to change to v1:
56
+
57
+ ```ruby
58
+ Rails.application.config.middleware.use OmniAuth::Builder do
59
+ provider :yahoojp, ENV['YAHOOJP_KEY'], ENV['YAHOOJP_SECRET'],
60
+ {
61
+ scope: "openid profile email address",
62
+ client_options: {
63
+ authorize_url: '/yconnect/v1/authorization',
64
+ token_url: '/yconnect/v1/token'
65
+ }
66
+ }
67
+ end
68
+ ```
69
+
70
+ ## License
71
+
72
+ Copyright (c) 2013 by mikanmarusan
73
+
74
+ 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:
75
+
76
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
77
+
78
+ 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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Run specs'
8
+ task :default => :spec
@@ -0,0 +1,101 @@
1
+ require 'omniauth-oauth2'
2
+ require 'httpauth'
3
+ require 'json/jwt'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class YahooJp < OmniAuth::Strategies::OAuth2
8
+
9
+ option :name, 'yahoojp'
10
+ option :client_options, {
11
+ :site => 'https://auth.login.yahoo.co.jp',
12
+ :authorize_url => '/yconnect/v2/authorization',
13
+ :token_url => '/yconnect/v2/token',
14
+ :auth_scheme => :basic_auth,
15
+ :userinfo_url => 'https://userinfo.yahooapis.jp/yconnect/v2/attribute'
16
+ }
17
+ option :authorize_options, [:display, :prompt, :scope, :bail]
18
+ option :userinfo_access, true
19
+
20
+ def request_phase
21
+ super
22
+ end
23
+
24
+ uid { raw_info['sub'] }
25
+
26
+ info do
27
+ prune!({
28
+ :sub => raw_info['sub'],
29
+ :name => raw_info['name'],
30
+ :given_name => raw_info['given_name'],
31
+ :given_name_ja_kana_jp => raw_info['given_name#ja-Kana-JP'],
32
+ :given_name_ja_hani_jp => raw_info['given_name#ja-Hani-JP'],
33
+ :family_name => raw_info['family_name'],
34
+ :family_name_ja_kana_jp => raw_info['family_name#ja-Kana-JP'],
35
+ :family_name_ja_hani_jp => raw_info['family_name#ja-Hani-JP'],
36
+ :gender => raw_info['gender'],
37
+ :zoneinfo => raw_info['zoneinfo'],
38
+ :locale => raw_info['locale'],
39
+ :birthdate => raw_info['birthdate'],
40
+ :nickname => raw_info['nickname'],
41
+ :picture => raw_info['picture'],
42
+ :email => raw_info['email'],
43
+ :email_verified => raw_info['email_verified'],
44
+ :address => raw_info['address'],
45
+ })
46
+ end
47
+
48
+ extra do
49
+ hash = {}
50
+ hash[:raw_info] = raw_info unless skip_info?
51
+ prune! hash
52
+ end
53
+
54
+ def raw_info
55
+ @raw_info ||= if options.userinfo_access
56
+ access_token.options[:mode] = :header
57
+ access_token.get(options.client_options.userinfo_url).parsed
58
+ elsif id_token
59
+ id_token_claims.slice(:sub).merge(
60
+ id_token: id_token,
61
+ id_token_claims: id_token_claims,
62
+ )
63
+ else
64
+ {}
65
+ end
66
+ end
67
+
68
+ def prune!(hash)
69
+ hash.delete_if do |_, value|
70
+ prune!(value) if value.is_a?(Hash)
71
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
72
+ end
73
+ end
74
+
75
+ def build_access_token
76
+ token_params = {
77
+ :code => request.params['code'],
78
+ :redirect_uri => callback_url,
79
+ :grant_type => 'authorization_code',
80
+ :headers => {'Authorization' => HTTPAuth::Basic.pack_authorization(client.id, client.secret)}
81
+ }
82
+
83
+ client.get_token(token_params);
84
+ end
85
+
86
+ def callback_url
87
+ full_host + script_name + callback_path
88
+ end
89
+
90
+ def id_token
91
+ access_token&.params&.dig('id_token')
92
+ end
93
+
94
+ def id_token_claims
95
+ JSON::JWT.decode(id_token, :skip_verification)
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ OmniAuth.config.add_camelization 'yahoojp', 'YahooJp'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module YahooJp
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-yahoojp/version"
2
+ require 'omniauth/strategies/yahoojp'
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-yahoojp/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["nov"]
6
+ gem.email = ["nov@matake.jp"]
7
+ gem.description = %q{Fork of Official OmniAuth strategy for Yahoo! JAPAN.}
8
+ gem.summary = %q{Fork of Official OmniAuth strategy for Yahoo! JAPAN.}
9
+ gem.homepage = "https://github.com/nov/omniauth-yahoojp"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "nov-omniauth-yahoojp"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::YahooJp::VERSION
17
+ gem.licenses = "MIT"
18
+
19
+ gem.add_dependency 'omniauth', '>= 1.0'
20
+ gem.add_dependency 'omniauth-oauth2', '>= 1.1'
21
+ gem.add_dependency 'httpauth'
22
+ gem.add_dependency 'json-jwt'
23
+ gem.add_development_dependency 'rspec', '~> 2.7'
24
+ gem.add_development_dependency 'rspec-its'
25
+ gem.add_development_dependency 'rack-test'
26
+ gem.add_development_dependency 'simplecov'
27
+ gem.add_development_dependency 'webmock'
28
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-yahoojp'
3
+
4
+ describe OmniAuth::Strategies::YahooJp do
5
+ let(:strategy) { described_class.new(app, options) }
6
+ let(:options) { {} }
7
+ let(:app) { nil }
8
+
9
+ describe "client options" do
10
+ subject { strategy.options.client_options }
11
+
12
+ its(:site) do
13
+ should eq "https://auth.login.yahoo.co.jp"
14
+ end
15
+
16
+ its(:authorize_url) do
17
+ should eq '/yconnect/v2/authorization'
18
+ end
19
+
20
+ its(:token_url) do
21
+ should eq '/yconnect/v2/token'
22
+ end
23
+
24
+ its(:userinfo_url) do
25
+ should eq 'https://userinfo.yahooapis.jp/yconnect/v2/attribute'
26
+ end
27
+ end
28
+
29
+ describe 'userinfo access' do
30
+ subject { strategy.options.userinfo_access }
31
+
32
+ context 'as default' do
33
+ it { should be_truthy }
34
+ end
35
+
36
+ context 'when disabled' do
37
+ let(:options) do
38
+ {userinfo_access: false}
39
+ end
40
+ it { should be_falsy }
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rspec/its'
7
+ require 'rack/test'
8
+ require 'webmock/rspec'
9
+ require 'omniauth'
10
+ require 'omniauth-yahoojp'
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
+ end
17
+
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nov-omniauth-yahoojp
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - nov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-10-19 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: httpauth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json-jwt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-its
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rack-test
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Fork of Official OmniAuth strategy for Yahoo! JAPAN.
140
+ email:
141
+ - nov@matake.jp
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - Gemfile
149
+ - Guardfile
150
+ - README.md
151
+ - Rakefile
152
+ - lib/omniauth-yahoojp.rb
153
+ - lib/omniauth-yahoojp/version.rb
154
+ - lib/omniauth/strategies/yahoojp.rb
155
+ - omniauth-yahoojp.gemspec
156
+ - spec/omniauth/strategies/yahoojp_spec.rb
157
+ - spec/spec_helper.rb
158
+ homepage: https://github.com/nov/omniauth-yahoojp
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubygems_version: 3.4.10
178
+ signing_key:
179
+ specification_version: 4
180
+ summary: Fork of Official OmniAuth strategy for Yahoo! JAPAN.
181
+ test_files:
182
+ - spec/omniauth/strategies/yahoojp_spec.rb
183
+ - spec/spec_helper.rb