omniauth-yahoojp-v2 0.0.0
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/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +189 -0
- data/Rakefile +11 -0
- data/lib/omniauth/strategies/yahoojp_v2.rb +217 -0
- data/lib/omniauth/yahoojp_v2/version.rb +7 -0
- data/lib/omniauth-yahoojp-v2.rb +4 -0
- metadata +97 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 960e2e247113e1b9ad3674056555041c980ba52e2caec7f27440ba72f233b040
|
|
4
|
+
data.tar.gz: 9125b715b45c246433f4345843dabcce6b25dffe962e60056372f1a9a5f47ced
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f43de86f89e07a6391ad681da98b2b28e95627ad71e6d24cc0eda7064336b2628a69982cd0d10044e018985a48d887b44bf34f05da89b5cb39bd4ccfcd2d6ed7
|
|
7
|
+
data.tar.gz: b0ad5955ef0c7d5adb0ff6dd9515cd41da0d490876577c92bb8eaefd3a54904a75661f1bba878b98ae42271b9190e45b57e5c8667f9bbece7c904f40189320cc
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Masahiro
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# OmniauthYahoojpV2
|
|
2
|
+
|
|
3
|
+
[](https://github.com/cadenza-tech/omniauth-yahoojp-v2/blob/main/LICENSE.txt) [](https://github.com/cadenza-tech/omniauth-yahoojp-v2/blob/main/CHANGELOG.md) [](https://github.com/cadenza-tech/omniauth-yahoojp-v2/actions?query=workflow%3Arelease) [](https://github.com/cadenza-tech/omniauth-yahoojp-v2/actions?query=workflow%3Atest) [](https://github.com/cadenza-tech/omniauth-yahoojp-v2/actions?query=workflow%3Alint)
|
|
4
|
+
|
|
5
|
+
Yahoo! JAPAN strategy for OmniAuth.
|
|
6
|
+
|
|
7
|
+
- [Installation](#installation)
|
|
8
|
+
- [Usage](#usage)
|
|
9
|
+
- [Rails Configuration with Devise](#rails-configuration-with-devise)
|
|
10
|
+
- [Configuration Options](#configuration-options)
|
|
11
|
+
- [Auth Hash](#auth-hash)
|
|
12
|
+
- [Changelog](#changelog)
|
|
13
|
+
- [Contributing](#contributing)
|
|
14
|
+
- [License](#license)
|
|
15
|
+
- [Code of Conduct](#code-of-conduct)
|
|
16
|
+
- [Sponsor](#sponsor)
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bundle add omniauth-yahoojp-v2
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
gem install omniauth-yahoojp-v2
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Rails Configuration with Devise
|
|
35
|
+
|
|
36
|
+
Add the following to `config/initializers/devise.rb`:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
# config/initializers/devise.rb
|
|
40
|
+
Devise.setup do |config|
|
|
41
|
+
config.omniauth :yahoojp_v2, ENV['YAHOOJP_CLIENT_ID'], ENV['YAHOOJP_CLIENT_SECRET']
|
|
42
|
+
end
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Add the OmniAuth callbacks routes to `config/routes.rb`:
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
# config/routes.rb
|
|
49
|
+
Rails.application.routes.draw do
|
|
50
|
+
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
|
|
51
|
+
end
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Add the OmniAuth configuration to your Devise model:
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
class User < ApplicationRecord
|
|
58
|
+
devise :database_authenticatable, :registerable,
|
|
59
|
+
:recoverable, :rememberable, :validatable,
|
|
60
|
+
:omniauthable, omniauth_providers: [:yahoojp_v2]
|
|
61
|
+
end
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Configuration Options
|
|
65
|
+
|
|
66
|
+
You can configure several options:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
# config/initializers/devise.rb
|
|
70
|
+
Devise.setup do |config|
|
|
71
|
+
config.omniauth :yahoojp_v2, ENV['YAHOOJP_CLIENT_ID'], ENV['YAHOOJP_CLIENT_SECRET'],
|
|
72
|
+
{
|
|
73
|
+
scope: 'openid profile email address', # Specify OAuth scopes
|
|
74
|
+
callback_path: '/custom/yahoojp_v2/callback', # Custom callback path
|
|
75
|
+
prompt: 'consent', # Optional: force consent screen
|
|
76
|
+
display: 'popup', # Optional: auth page display mode
|
|
77
|
+
max_age: 600, # Optional: max seconds since last auth
|
|
78
|
+
bail: true # Optional: redirect to app on consent denial instead of Yahoo! top
|
|
79
|
+
}
|
|
80
|
+
end
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Available scopes:
|
|
84
|
+
|
|
85
|
+
- `openid` - Required for ID token (includes user identifier)
|
|
86
|
+
- `profile` - Access to user's profile
|
|
87
|
+
- `email` - Access to user's email address
|
|
88
|
+
- `address` - Access to user's address
|
|
89
|
+
|
|
90
|
+
### Auth Hash
|
|
91
|
+
|
|
92
|
+
After successful authentication, the auth hash will be available in `request.env['omniauth.auth']`:
|
|
93
|
+
|
|
94
|
+
```ruby
|
|
95
|
+
{
|
|
96
|
+
provider: 'yahoojp_v2',
|
|
97
|
+
uid: 'FQBSQOIDGW5PV4NHAAUY7BWAMU',
|
|
98
|
+
info: {
|
|
99
|
+
name: '矢風太郎',
|
|
100
|
+
nickname: 'やふうたろう',
|
|
101
|
+
first_name: '太郎',
|
|
102
|
+
first_name_kana: 'タロウ',
|
|
103
|
+
first_name_hani: '太郎',
|
|
104
|
+
last_name: '矢風',
|
|
105
|
+
last_name_kana: 'ヤフウ',
|
|
106
|
+
last_name_hani: '矢風',
|
|
107
|
+
gender: 'male',
|
|
108
|
+
zoneinfo: 'Asia/Tokyo',
|
|
109
|
+
locale: 'ja-JP',
|
|
110
|
+
birth_year: 1986,
|
|
111
|
+
image: 'https://dummy.img.yahoo.co.jp/example.png',
|
|
112
|
+
email: 'yconnect@example.com',
|
|
113
|
+
email_verified: true,
|
|
114
|
+
address: {
|
|
115
|
+
country: 'JP',
|
|
116
|
+
postal_code: '1028282',
|
|
117
|
+
region: '東京都',
|
|
118
|
+
locality: '千代田区',
|
|
119
|
+
formatted: '東京都千代田区'
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
credentials: {
|
|
123
|
+
token: 'SlAV32hkKG',
|
|
124
|
+
expires: true,
|
|
125
|
+
expires_at: 1453618036,
|
|
126
|
+
refresh_token: '8xLOxBtZp8'
|
|
127
|
+
},
|
|
128
|
+
extra: {
|
|
129
|
+
raw_info: {
|
|
130
|
+
sub: 'FQBSQOIDGW5PV4NHAAUY7BWAMU',
|
|
131
|
+
name: '矢風太郎',
|
|
132
|
+
given_name: '太郎',
|
|
133
|
+
'given_name#ja-Kana-JP': 'タロウ',
|
|
134
|
+
'given_name#ja-Hani-JP': '太郎',
|
|
135
|
+
family_name: '矢風',
|
|
136
|
+
'family_name#ja-Kana-JP': 'ヤフウ',
|
|
137
|
+
'family_name#ja-Hani-JP': '矢風',
|
|
138
|
+
gender: 'male',
|
|
139
|
+
zoneinfo: 'Asia/Tokyo',
|
|
140
|
+
locale: 'ja-JP',
|
|
141
|
+
birthdate: '1986',
|
|
142
|
+
nickname: 'やふうたろう',
|
|
143
|
+
picture: 'https://dummy.img.yahoo.co.jp/example.png',
|
|
144
|
+
email: 'yconnect@example.com',
|
|
145
|
+
email_verified: 'true',
|
|
146
|
+
address: {
|
|
147
|
+
country: 'JP',
|
|
148
|
+
postal_code: '1028282',
|
|
149
|
+
region: '東京都',
|
|
150
|
+
locality: '千代田区',
|
|
151
|
+
formatted: '東京都千代田区'
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
id_token: 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjFlOWdkazcifQ.ewogImlzcyI6ICJodHRwOi8vc2VydmVyLmV4YW1wbGUuY29tIiwKICJzdWIiOiAiMjQ4Mjg5NzYxMDAxIiwKICJhdWQiOiAiczZCaGRSa3F0MyIsCiAibm9uY2UiOiAibi0wUzZfV3pBMk1qIiwKICJleHAiOiAxMzExMjgxOTcwLAogImlhdCI6IDEzMTEyODA5NzAKfQ.ggW8hZ1EuVLuxNuuIJKX_V8a_OMXzR0EHR9R6jgdqrOOF4daGU96Sr_P6qJp6IcmD3HP99Obi1PRs-cwh3LO-p146waJ8IhehcwL7F09JdijmBqkvPeB2T9CJNqeGpe-gccMg4vfKjkM8FcGvnzZUN4_KSP0aAp1tOJ1zZwgjxqGByKHiOtX7TpdQyHE5lcMiKPXfEIQILVq0pc_E2DzL7emopWoaoZTF_m0_N0YzFC6g6EJbOEoRoSK5hoDalrcvRYLSrQAZZKflyuVCyixEoV9GfNQC3_osjzw2PAithfubEEBLuVVk4XUVrWOLrLl0nx7RkKU8NXNHq-rvKMzqg',
|
|
155
|
+
id_info: {
|
|
156
|
+
iss: 'https://auth.login.yahoo.co.jp/yconnect/v2',
|
|
157
|
+
sub: 'KVNE5DZLWIY4Y57TRDLURJOOEU',
|
|
158
|
+
aud: ['dj0zaiZpPWxCUTczV01KazczNSZzPWNvbnN1bWVyc2VjcmV0Jng9NDc-'],
|
|
159
|
+
exp: 1453618036,
|
|
160
|
+
iat: 1453272436,
|
|
161
|
+
auth_time: 1453271436,
|
|
162
|
+
nonce: 'n-0S6_WzA2Mj',
|
|
163
|
+
amr: ['pwd'],
|
|
164
|
+
at_hash: 'SjjfaAWSdWEvSDfASCmonm',
|
|
165
|
+
c_hash: 'LDktKdoQak3Pk0cnXxCltA'
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Changelog
|
|
172
|
+
|
|
173
|
+
See [CHANGELOG.md](https://github.com/cadenza-tech/omniauth-yahoojp-v2/blob/main/CHANGELOG.md).
|
|
174
|
+
|
|
175
|
+
## Contributing
|
|
176
|
+
|
|
177
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cadenza-tech/omniauth-yahoojp-v2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/cadenza-tech/omniauth-yahoojp-v2/blob/main/CODE_OF_CONDUCT.md).
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
The gem is available as open source under the terms of the [MIT License](https://github.com/cadenza-tech/omniauth-yahoojp-v2/blob/main/LICENSE.txt).
|
|
182
|
+
|
|
183
|
+
## Code of Conduct
|
|
184
|
+
|
|
185
|
+
Everyone interacting in the OmniauthYahoojpV2 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cadenza-tech/omniauth-yahoojp-v2/blob/main/CODE_OF_CONDUCT.md).
|
|
186
|
+
|
|
187
|
+
## Sponsor
|
|
188
|
+
|
|
189
|
+
You can sponsor this project on [Patreon](https://patreon.com/CadenzaTech).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rspec/core/rake_task'
|
|
5
|
+
require 'rubocop/rake_task'
|
|
6
|
+
|
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
8
|
+
|
|
9
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
|
10
|
+
task.options = ['--format', ENV['RUBOCOP_FORMAT']] if ENV['RUBOCOP_FORMAT']
|
|
11
|
+
end
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'omniauth-oauth2'
|
|
4
|
+
require 'json/jwt'
|
|
5
|
+
require 'digest'
|
|
6
|
+
require 'base64'
|
|
7
|
+
|
|
8
|
+
module OmniAuth
|
|
9
|
+
module Strategies
|
|
10
|
+
class YahoojpV2 < OmniAuth::Strategies::OAuth2
|
|
11
|
+
DEFAULT_SCOPE = 'openid profile email'
|
|
12
|
+
DEFAULT_JWT_LEEWAY = 600
|
|
13
|
+
USER_INFO_URL = 'https://userinfo.yahooapis.jp/yconnect/v2/attribute'
|
|
14
|
+
JWKS_URL = 'https://auth.login.yahoo.co.jp/yconnect/v2/jwks'
|
|
15
|
+
ID_TOKEN_ISSUER = 'https://auth.login.yahoo.co.jp/yconnect/v2'
|
|
16
|
+
|
|
17
|
+
option :name, 'yahoojp_v2'
|
|
18
|
+
option :client_options, {
|
|
19
|
+
site: 'https://auth.login.yahoo.co.jp',
|
|
20
|
+
authorize_url: '/yconnect/v2/authorization',
|
|
21
|
+
token_url: '/yconnect/v2/token'
|
|
22
|
+
}
|
|
23
|
+
option :authorize_options, [:scope, :state, :nonce, :prompt, :display, :max_age, :bail]
|
|
24
|
+
option :pkce, true
|
|
25
|
+
option :scope, DEFAULT_SCOPE
|
|
26
|
+
option :jwt_leeway, DEFAULT_JWT_LEEWAY
|
|
27
|
+
option :skip_jwt, false
|
|
28
|
+
|
|
29
|
+
uid { raw_info['sub'] }
|
|
30
|
+
|
|
31
|
+
info do
|
|
32
|
+
prune!({
|
|
33
|
+
name: raw_info['name'],
|
|
34
|
+
nickname: raw_info['nickname'],
|
|
35
|
+
first_name: raw_info['given_name'],
|
|
36
|
+
first_name_kana: raw_info['given_name#ja-Kana-JP'],
|
|
37
|
+
first_name_hani: raw_info['given_name#ja-Hani-JP'],
|
|
38
|
+
last_name: raw_info['family_name'],
|
|
39
|
+
last_name_kana: raw_info['family_name#ja-Kana-JP'],
|
|
40
|
+
last_name_hani: raw_info['family_name#ja-Hani-JP'],
|
|
41
|
+
gender: raw_info['gender'],
|
|
42
|
+
zoneinfo: raw_info['zoneinfo'],
|
|
43
|
+
locale: raw_info['locale'],
|
|
44
|
+
birth_year: raw_info['birthdate']&.to_i,
|
|
45
|
+
image: raw_info['picture'],
|
|
46
|
+
email: raw_info['email'],
|
|
47
|
+
email_verified: raw_info['email_verified'] == 'true',
|
|
48
|
+
address: raw_info['address']&.transform_keys(&:to_sym)
|
|
49
|
+
})
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
extra do
|
|
53
|
+
hash = {}
|
|
54
|
+
hash[:raw_info] = raw_info unless skip_info?
|
|
55
|
+
hash[:id_token] = id_token_info[:raw] if id_token_info[:raw]
|
|
56
|
+
hash[:id_info] = id_token_info[:decoded] if id_token_info[:decoded]
|
|
57
|
+
prune!(hash)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
credentials do
|
|
61
|
+
hash = { token: access_token.token }
|
|
62
|
+
hash[:expires] = access_token.expires?
|
|
63
|
+
hash[:expires_at] = access_token.expires_at if access_token.expires?
|
|
64
|
+
hash[:refresh_token] = access_token.refresh_token if access_token.refresh_token
|
|
65
|
+
hash
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def raw_info
|
|
69
|
+
return @raw_info if defined?(@raw_info)
|
|
70
|
+
|
|
71
|
+
if skip_info?
|
|
72
|
+
decoded_id_token = decode_id_token(access_token.params['id_token'])
|
|
73
|
+
@raw_info = { 'sub' => decoded_id_token[:sub] }
|
|
74
|
+
else
|
|
75
|
+
@raw_info = access_token.get(USER_INFO_URL, headers: { 'Authorization' => "Bearer #{access_token.token}" }).parsed
|
|
76
|
+
end
|
|
77
|
+
@raw_info
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def callback_url
|
|
81
|
+
options[:redirect_uri] || (full_host + callback_path)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def authorize_params # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
|
85
|
+
super.tap do |params|
|
|
86
|
+
options[:authorize_options].each do |key|
|
|
87
|
+
params[key] = request.params[key.to_s] unless empty?(request.params[key.to_s])
|
|
88
|
+
end
|
|
89
|
+
params[:scope] ||= DEFAULT_SCOPE
|
|
90
|
+
params[:nonce] ||= SecureRandom.hex(24)
|
|
91
|
+
params[:response_type] = 'code'
|
|
92
|
+
session['omniauth.state'] = params[:state] unless empty?(params[:state])
|
|
93
|
+
session['omniauth.nonce'] = params[:nonce] unless empty?(params[:nonce])
|
|
94
|
+
session['omniauth.max_age'] = params[:max_age] unless empty?(params[:max_age])
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
private
|
|
99
|
+
|
|
100
|
+
def prune!(hash)
|
|
101
|
+
hash.delete_if do |_, value|
|
|
102
|
+
prune!(value) if value.is_a?(Hash)
|
|
103
|
+
empty?(value)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def empty?(value)
|
|
108
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def decode_id_token(id_token)
|
|
112
|
+
JSON::JWT.decode(id_token, :skip_verification)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def id_token_info
|
|
116
|
+
return @id_token_info if defined?(@id_token_info)
|
|
117
|
+
|
|
118
|
+
@id_token_info = { raw: nil, decoded: nil }
|
|
119
|
+
return @id_token_info unless access_token.params['id_token']
|
|
120
|
+
|
|
121
|
+
@id_token_info[:raw] = access_token.params['id_token']
|
|
122
|
+
return @id_token_info if skip_info?
|
|
123
|
+
|
|
124
|
+
decoded_id_token = decode_id_token(access_token.params['id_token'])
|
|
125
|
+
verify_id_token(decoded_id_token) unless options.skip_jwt
|
|
126
|
+
@id_token_info[:decoded] = decoded_id_token
|
|
127
|
+
@id_token_info
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def verify_id_token(id_token)
|
|
131
|
+
jwk = fetch_jwk(id_token.kid)
|
|
132
|
+
verify_signature(id_token, jwk)
|
|
133
|
+
verify_claims(id_token)
|
|
134
|
+
rescue StandardError => e
|
|
135
|
+
fail!(:id_token_verification_failed, e)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def fetch_jwk(kid)
|
|
139
|
+
JSON::JWK::Set::Fetcher.fetch(JWKS_URL, kid: kid)
|
|
140
|
+
rescue StandardError => e
|
|
141
|
+
fail!(:jwk_fetch_failed, e)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def verify_signature(id_token, jwk)
|
|
145
|
+
id_token.verify!(jwk)
|
|
146
|
+
rescue StandardError => e
|
|
147
|
+
fail!(:id_token_signature_invalid, e)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def verify_claims(id_token)
|
|
151
|
+
verify_iss(id_token)
|
|
152
|
+
verify_aud(id_token)
|
|
153
|
+
verify_nonce(id_token)
|
|
154
|
+
verify_at_hash(id_token)
|
|
155
|
+
verify_c_hash(id_token)
|
|
156
|
+
verify_exp(id_token)
|
|
157
|
+
verify_iat(id_token)
|
|
158
|
+
verify_auth_time(id_token)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def verify_iss(id_token)
|
|
162
|
+
fail!(:id_token_issuer_invalid) if id_token[:iss] != ID_TOKEN_ISSUER
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def verify_aud(id_token)
|
|
166
|
+
fail!(:id_token_audience_invalid) if id_token[:aud] != options.client_id
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def verify_nonce(id_token)
|
|
170
|
+
expected_nonce = session.delete('omniauth.nonce')
|
|
171
|
+
return unless expected_nonce
|
|
172
|
+
|
|
173
|
+
fail!(:nonce_mismatch) if id_token[:nonce] != expected_nonce
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def verify_at_hash(id_token)
|
|
177
|
+
return unless id_token[:at_hash]
|
|
178
|
+
|
|
179
|
+
expected_hash = generate_hash(access_token.token)
|
|
180
|
+
fail!(:at_hash_mismatch) if id_token[:at_hash] != expected_hash
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def verify_c_hash(id_token)
|
|
184
|
+
return unless id_token[:c_hash]
|
|
185
|
+
|
|
186
|
+
auth_code = request.params['code']
|
|
187
|
+
return unless auth_code
|
|
188
|
+
|
|
189
|
+
expected_hash = generate_hash(auth_code)
|
|
190
|
+
fail!(:c_hash_mismatch) if id_token[:c_hash] != expected_hash
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def generate_hash(value)
|
|
194
|
+
hash = Digest::SHA256.digest(value)
|
|
195
|
+
half_of_hash = hash[0, hash.length / 2]
|
|
196
|
+
Base64.urlsafe_encode64(half_of_hash, padding: false)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def verify_exp(id_token)
|
|
200
|
+
fail!(:id_token_expired) if id_token[:exp] < Time.now.to_i
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def verify_iat(id_token)
|
|
204
|
+
fail!(:id_token_issued_at_too_old) if id_token[:iat] < (Time.now.to_i - options.jwt_leeway)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
def verify_auth_time(id_token)
|
|
208
|
+
return unless id_token[:auth_time]
|
|
209
|
+
|
|
210
|
+
max_age = session.delete('omniauth.max_age')
|
|
211
|
+
return unless max_age
|
|
212
|
+
|
|
213
|
+
fail!(:auth_time_too_old) if (id_token[:auth_time] + max_age.to_i) < Time.now.to_i
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: omniauth-yahoojp-v2
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Masahiro
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: json-jwt
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: omniauth
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '2.0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '2.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: omniauth-oauth2
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.8'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - "~>"
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '1.8'
|
|
54
|
+
description: Yahoo! JAPAN strategy for OmniAuth
|
|
55
|
+
email:
|
|
56
|
+
- watanabe@cadenza-tech.com
|
|
57
|
+
executables: []
|
|
58
|
+
extensions: []
|
|
59
|
+
extra_rdoc_files: []
|
|
60
|
+
files:
|
|
61
|
+
- ".rspec"
|
|
62
|
+
- CHANGELOG.md
|
|
63
|
+
- LICENSE.txt
|
|
64
|
+
- README.md
|
|
65
|
+
- Rakefile
|
|
66
|
+
- lib/omniauth-yahoojp-v2.rb
|
|
67
|
+
- lib/omniauth/strategies/yahoojp_v2.rb
|
|
68
|
+
- lib/omniauth/yahoojp_v2/version.rb
|
|
69
|
+
homepage: https://github.com/cadenza-tech/omniauth-yahoojp-v2/tree/v0.0.0
|
|
70
|
+
licenses:
|
|
71
|
+
- MIT
|
|
72
|
+
metadata:
|
|
73
|
+
homepage_uri: https://github.com/cadenza-tech/omniauth-yahoojp-v2/tree/v0.0.0
|
|
74
|
+
source_code_uri: https://github.com/cadenza-tech/omniauth-yahoojp-v2/tree/v0.0.0
|
|
75
|
+
changelog_uri: https://github.com/cadenza-tech/omniauth-yahoojp-v2/blob/v0.0.0/CHANGELOG.md
|
|
76
|
+
bug_tracker_uri: https://github.com/cadenza-tech/omniauth-yahoojp-v2/issues
|
|
77
|
+
documentation_uri: https://rubydoc.info/gems/omniauth-yahoojp-v2/0.0.0
|
|
78
|
+
funding_uri: https://patreon.com/CadenzaTech
|
|
79
|
+
rubygems_mfa_required: 'true'
|
|
80
|
+
rdoc_options: []
|
|
81
|
+
require_paths:
|
|
82
|
+
- lib
|
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: 2.5.0
|
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ">="
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
requirements: []
|
|
94
|
+
rubygems_version: 3.6.9
|
|
95
|
+
specification_version: 4
|
|
96
|
+
summary: Yahoo! JAPAN strategy for OmniAuth
|
|
97
|
+
test_files: []
|